From 4f08fca630e858dea7d7f92a86df32a70e001a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20Cesar=20Laura=20Avenda=C3=B1o?= Date: Wed, 30 Jun 2021 15:39:54 +0000 Subject: [PATCH] PMCORE-3063 --- framework/src/Maveriks/WebApplication.php | 27 ++++---- workflow/engine/bin/cli.php | 76 +++++++++++++++-------- 2 files changed, 66 insertions(+), 37 deletions(-) diff --git a/framework/src/Maveriks/WebApplication.php b/framework/src/Maveriks/WebApplication.php index 46c788a23..8af8a82ad 100644 --- a/framework/src/Maveriks/WebApplication.php +++ b/framework/src/Maveriks/WebApplication.php @@ -433,7 +433,8 @@ class WebApplication * The value of $executeSetupPlugin must always be true for a web environment. * * @param string $workspace - * @param boolean $executeSetupPlugin + * @param bool $executeSetupPlugin + * @param bool $setTimeZone * @return bool * @throws Exception * @@ -441,7 +442,7 @@ class WebApplication * @see workflow/engine/bin/cli.php * @see \App\Console\Commands\AddParametersTrait */ - public function loadEnvironment($workspace = "", $executeSetupPlugin = true) + public function loadEnvironment($workspace = "", $executeSetupPlugin = true, $setTimeZone = true) { define("PATH_SEP", DIRECTORY_SEPARATOR); @@ -511,8 +512,10 @@ class WebApplication $arraySystemConfiguration = System::getSystemConfiguration('', '', $workspace); - //In community version the default value is 0 - $_SESSION['__SYSTEM_UTC_TIME_ZONE__'] = (int)($arraySystemConfiguration['system_utc_time_zone']) == 1; + if ($setTimeZone) { + //In community version the default value is 0 + $_SESSION['__SYSTEM_UTC_TIME_ZONE__'] = (int)($arraySystemConfiguration['system_utc_time_zone']) == 1; + } define('DEBUG_SQL_LOG', $arraySystemConfiguration['debug_sql']); define('DEBUG_TIME_LOG', $arraySystemConfiguration['debug_time']); @@ -521,8 +524,10 @@ class WebApplication define('MEMCACHED_SERVER', $arraySystemConfiguration['memcached_server']); define('SYS_SKIN', $arraySystemConfiguration['default_skin']); define('DISABLE_DOWNLOAD_DOCUMENTS_SESSION_VALIDATION', $arraySystemConfiguration['disable_download_documents_session_validation']); - define('TIME_ZONE', - (isset($_SESSION['__SYSTEM_UTC_TIME_ZONE__']) && $_SESSION['__SYSTEM_UTC_TIME_ZONE__']) ? 'UTC' : $arraySystemConfiguration['time_zone']); + if ($setTimeZone) { + define('TIME_ZONE', + (isset($_SESSION['__SYSTEM_UTC_TIME_ZONE__']) && $_SESSION['__SYSTEM_UTC_TIME_ZONE__']) ? 'UTC' : $arraySystemConfiguration['time_zone']); + } // Change storage path app()->useStoragePath(realpath(PATH_DATA)); @@ -537,11 +542,11 @@ class WebApplication ini_set('short_open_tag', 'On'); //?? ini_set('default_charset', 'UTF-8'); //?? ini_set('soap.wsdl_cache_enabled', $arraySystemConfiguration['wsdl_cache']); - ini_set('date.timezone', TIME_ZONE); //Set Time Zone - - date_default_timezone_set(TIME_ZONE); - - config(['app.timezone' => TIME_ZONE]); + if ($setTimeZone) { + ini_set('date.timezone', TIME_ZONE); //Set Time Zone + date_default_timezone_set(TIME_ZONE); + config(['app.timezone' => TIME_ZONE]); + } // Define the language Bootstrap::setLanguage(); diff --git a/workflow/engine/bin/cli.php b/workflow/engine/bin/cli.php index 7c8879a6e..62078a872 100644 --- a/workflow/engine/bin/cli.php +++ b/workflow/engine/bin/cli.php @@ -1,36 +1,60 @@ setRootDir(PROCESSMAKER_PATH); -$app->loadEnvironment(); +$app->loadEnvironment('', true, false); - // trap -V before pake - if (in_array('-v', $argv) || in_array('-V', $argv) || in_array('--version', $argv)) { - printf("ProcessMaker version %s\n", pakeColor::colorize(trim(file_get_contents(PATH_GULLIVER . 'VERSION')), 'INFO')); - exit(0); - } +// Trap -V before pake +if (in_array('-v', $argv) || in_array('-V', $argv) || in_array('--version', $argv)) { + printf("ProcessMaker version %s\n", + pakeColor::colorize(trim(file_get_contents(PATH_GULLIVER . 'VERSION')), 'INFO')); + exit(0); +} - // register tasks - //TODO: include plugins - $directories = array(PATH_HOME . 'engine/bin/tasks'); - $pluginsDirectories = glob(PATH_PLUGINS . "*"); - foreach ($pluginsDirectories as $dir) { - if (!is_dir($dir)) { - continue; - } - if (is_dir("$dir/bin/tasks")) { - $directories[] = "$dir/bin/tasks"; - } - } +// Register tasks +$directories = [PATH_HOME . 'engine/bin/tasks']; +$pluginsDirectories = glob(PATH_PLUGINS . "*"); +foreach ($pluginsDirectories as $dir) { + if (!is_dir($dir)) { + continue; + } + if (is_dir("$dir/bin/tasks")) { + $directories[] = "$dir/bin/tasks"; + } +} +foreach ($directories as $dir) { + foreach (glob("$dir/*.php") as $filename) { + include_once $filename; + } +} - foreach ($directories as $dir) { - foreach (glob("$dir/*.php") as $filename) { - include_once($filename); - } - } +// Set time zone, if not defined +if (!defined('TIME_ZONE')) { + // Get workspace + $args = $argv; + $cliName = array_shift($args); + $taskName = array_shift($args); + $workspace = array_shift($args); + while ($workspace[0] == '-') { + $workspace = array_shift($args); + } - CLI::run(); + // Get time zone (global or by workspace) + $arraySystemConfiguration = System::getSystemConfiguration('', '', $workspace); - exit(0); + // Set time zone + $_SESSION['__SYSTEM_UTC_TIME_ZONE__'] = (int)($arraySystemConfiguration['system_utc_time_zone']) == 1; + define('TIME_ZONE', + (isset($_SESSION['__SYSTEM_UTC_TIME_ZONE__']) && $_SESSION['__SYSTEM_UTC_TIME_ZONE__']) ? 'UTC' : $arraySystemConfiguration['time_zone']); + ini_set('date.timezone', TIME_ZONE); + date_default_timezone_set(TIME_ZONE); + config(['app.timezone' => TIME_ZONE]); +} + +// Run command +CLI::run(); +exit(0);