diff --git a/gulliver/bin/gulliver.php b/gulliver/bin/gulliver.php index b251c4555..6f06dadc2 100644 --- a/gulliver/bin/gulliver.php +++ b/gulliver/bin/gulliver.php @@ -1,6 +1,12 @@ make(Kernel::class)->bootstrap(); + +error_reporting(error_reporting() & ~E_DEPRECATED & ~E_STRICT); if (!PATH_THIRDPARTY) { die("You must launch gulliver command line with the gulliver script\n"); diff --git a/gulliver/bin/tasks/pakeGulliver.php b/gulliver/bin/tasks/pakeGulliver.php index 520998883..7afff1153 100644 --- a/gulliver/bin/tasks/pakeGulliver.php +++ b/gulliver/bin/tasks/pakeGulliver.php @@ -2223,23 +2223,23 @@ function run_check_standard_code ( $task, $options) { function run_update_plugin_attributes($task, $args) { try { - //Verify data if (!isset($args[0])) { throw new Exception("Error: You must specify the name of a plugin"); } - //Set variables $pluginName = $args[0]; - - //Update plugin attributes - $pmPluginRegistry = PluginRegistry::loadSingleton(); - - $pmPluginRegistry->updatePluginAttributesInAllWorkspaces($pluginName); + define('SYS_SYS', uniqid()); + foreach (PmSystem::listWorkspaces() as $value) { + \ProcessMaker\Util\Cnn::connect($value->name); + //Update plugin attributes + $pmPluginRegistry = PluginRegistry::newInstance(); + $pmPluginRegistry->updatePluginAttributesInAllWorkspaces($value->name, $pluginName); + } echo "Done!\n"; } catch (Exception $e) { - error_log( $e->getMessage() . "\n" ); + error_log($e->getMessage() . "\n"); } } @@ -2247,7 +2247,7 @@ function run_check_plugin_disabled_code($task, $args) { try { //Set variables - $option = (isset($args[0]))? trim($args[0]) : ""; + $option = (isset($args[0])) ? trim($args[0]) : ""; $option2 = strtoupper($option); switch ($option2) { @@ -2273,10 +2273,10 @@ function run_check_plugin_disabled_code($task, $args) if (is_file(PATH_PLUGINS . $pluginName . ".php") && is_dir(PATH_PLUGINS . $pluginName)) { if (preg_match( - '/^.*class\s+' . $pluginName . 'Plugin\s+extends\s+(\w*)\s*\{.*$/i', - str_replace(["\n", "\r", "\t"], ' ', file_get_contents(PATH_PLUGINS . $pluginName . '.php')), - $arrayMatch - ) + '/^.*class\s+' . $pluginName . 'Plugin\s+extends\s+(\w*)\s*\{.*$/i', + str_replace(["\n", "\r", "\t"], ' ', file_get_contents(PATH_PLUGINS . $pluginName . '.php')), + $arrayMatch + ) ) { $pluginParentClassName = $arrayMatch[1]; @@ -2325,13 +2325,13 @@ function run_check_plugin_disabled_code($task, $args) $arrayFoundDisabledCode = array_merge($cs->checkDisabledCode("FILE", PATH_PLUGINS . $pluginName . ".php"), $cs->checkDisabledCode("PATH", PATH_PLUGINS . $pluginName)); if (!empty($arrayFoundDisabledCode)) { - $strFoundDisabledCode .= (($strFoundDisabledCode != "")? "\n\n" : "") . "> " . $pluginName; + $strFoundDisabledCode .= (($strFoundDisabledCode != "") ? "\n\n" : "") . "> " . $pluginName; foreach ($arrayFoundDisabledCode as $key2 => $value2) { $strCodeAndLine = ""; foreach ($value2 as $key3 => $value3) { - $strCodeAndLine .= (($strCodeAndLine != "")? ", " : "") . $key3 . " (Lines " . implode(", ", $value3) . ")"; + $strCodeAndLine .= (($strCodeAndLine != "") ? ", " : "") . $key3 . " (Lines " . implode(", ", $value3) . ")"; } $strFoundDisabledCode .= "\n- " . str_replace(PATH_PLUGINS, "", $key2) . ": " . $strCodeAndLine; @@ -2350,7 +2350,7 @@ function run_check_plugin_disabled_code($task, $args) echo "Done!\n"; } catch (Exception $e) { - error_log( $e->getMessage() . "\n" ); + error_log($e->getMessage() . "\n"); } } diff --git a/workflow/engine/src/ProcessMaker/Plugins/PluginRegistry.php b/workflow/engine/src/ProcessMaker/Plugins/PluginRegistry.php index 756e38ee4..934e6914b 100644 --- a/workflow/engine/src/ProcessMaker/Plugins/PluginRegistry.php +++ b/workflow/engine/src/ProcessMaker/Plugins/PluginRegistry.php @@ -122,6 +122,21 @@ class PluginRegistry $this->_aPluginDetails[$Namespace] = $detail; } + /** + * Unregister the plugin in the class + * @param string $Namespace Name Plugin + * @return PluginDetail + */ + public function unregisterPlugin($Namespace) + { + $detail = null; + if (isset($this->_aPluginDetails[$Namespace])) { + $detail = $this->_aPluginDetails[$Namespace]; + unset($this->_aPluginDetails[$Namespace]); + } + return $detail; + } + /** * Get setup Plugins * @return int @@ -1363,14 +1378,13 @@ class PluginRegistry /** * Update the plugin attributes in all workspaces + * @param string $Workspace Name workspace * @param string $Namespace Name of Plugin * @throws Exception */ - public function updatePluginAttributesInAllWorkspaces($Namespace) + public function updatePluginAttributesInAllWorkspaces($Workspace, $Namespace) { try { - G::LoadClass("wsTools"); - //Set variables $pluginFileName = $Namespace . ".php"; @@ -1379,69 +1393,17 @@ class PluginRegistry throw new Exception("Error: The plugin not exists"); } - //Update plugin attributes + //remove old data plugin + $pmPluginRegistry = PluginRegistry::loadSingleton(); + $pluginDetails = $pmPluginRegistry->unregisterPlugin($Namespace); + + //Load plugin attributes require_once(PATH_PLUGINS . $pluginFileName); - $pmPluginRegistry = PluginRegistry::loadSingleton(); - - $pluginDetails = $pmPluginRegistry->getPluginDetails($pluginFileName); - - if (is_array($pluginDetails->getWorkspaces()) && - count($pluginDetails->getWorkspaces()) > 0 - ) { - $arrayWorkspace = array(); - - foreach (System::listWorkspaces() as $value) { - $workspaceTools = $value; - - $arrayWorkspace[] = $workspaceTools->name; - } - //Workspaces to update - $arrayWorkspaceAux = array_diff($arrayWorkspace, $pluginDetails->getWorkspaces()); - $strWorkspaceNoWritable = ""; - - $arrayWorkspace = array(); - - foreach ($arrayWorkspaceAux as $value) { - $workspace = $value; - - $workspacePathDataSite = PATH_DATA . "sites" . PATH_SEP . $workspace . PATH_SEP; - - if (file_exists($workspacePathDataSite . "plugin.singleton")) { - $pmPluginRegistry = PluginRegistry::loadSingleton(); - - if (isset($pmPluginRegistry->_aPluginDetails[$Namespace])) { - if (!is_writable($workspacePathDataSite . "plugin.singleton")) { - $strWorkspaceNoWritable .= (($strWorkspaceNoWritable != "") ? ", " : "") . $workspace; - } - - $arrayWorkspace[] = $workspace; - } - } - } - - //Verify data - if ($strWorkspaceNoWritable != "") { - throw new Exception( - 'Error: The workspaces ' . - $strWorkspaceNoWritable . - ' has problems of permissions of write in file "plugin.singleton", solve this problem' - ); - } - - //Update plugin attributes - foreach ($arrayWorkspace as $value) { - $workspace = $value; - - $workspacePathDataSite = PATH_DATA . "sites" . PATH_SEP . $workspace . PATH_SEP; - - $pmPluginRegistry = PluginRegistry::loadSingleton(); - - $pmPluginRegistry->disablePlugin($Namespace); - - $pmPluginRegistry->savePlugin($Namespace); - } + if (is_array($pluginDetails->getWorkspaces()) && !in_array($Workspace, $pluginDetails->getWorkspaces())) { + $pmPluginRegistry->disablePlugin($Namespace); } + $pmPluginRegistry->savePlugin($Namespace); } catch (Exception $e) { throw $e; } diff --git a/workflow/engine/src/ProcessMaker/Util/Cnn.php b/workflow/engine/src/ProcessMaker/Util/Cnn.php new file mode 100644 index 000000000..bf13cd3f5 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Util/Cnn.php @@ -0,0 +1,122 @@ +Workspace = $Workspace; + Propel::initConfiguration($cnn->buildParams()); + } + + /** + * Loads the parameters required to connect to each workspace database + * @return array + */ + public function buildParams() + { + if ($this->readFileDBWorkspace()) { + return $this->prepareDataSources(); + } + return []; + } + + /** + * Reads the workspace db.php file + * @return bool + */ + private function readFileDBWorkspace() + { + if (file_exists(PATH_DB . $this->Workspace . PATH_SEP . 'db.php')) { + $this->DBFile = file_get_contents(PATH_DB . $this->Workspace . PATH_SEP . 'db.php'); + return true; + } + return false; + } + + /** + * Prepares data resources + * @return array + */ + private function prepareDataSources() + { + $phpCode = preg_replace( + '/define\s*\(\s*[\x22\x27](.*)[\x22\x27]\s*,\s*(\x22.*\x22|\x27.*\x27)\s*\)\s*;/i', + '$$1 = $2;', + $this->DBFile + ); + $phpCode = str_replace([''], '', $phpCode); + + eval($phpCode); + + $dataSources = []; + $dataSources['datasources'] = array( + 'workflow' => array( + 'connection' => $this->buildDsnString( + $DB_ADAPTER, + $DB_HOST, + $DB_NAME, + $DB_USER, + urlencode($DB_PASS) + ), + 'adapter' => "mysql" + ), + 'rbac' => array( + 'connection' => $this->buildDsnString( + $DB_ADAPTER, + $DB_RBAC_HOST, + $DB_RBAC_NAME, + $DB_RBAC_USER, + urlencode($DB_RBAC_PASS) + ), + 'adapter' => "mysql" + ), + 'report' => array( + 'connection' => $this->buildDsnString( + $DB_ADAPTER, + $DB_REPORT_HOST, + $DB_REPORT_NAME, + $DB_REPORT_USER, + urlencode($DB_REPORT_PASS) + ), + 'adapter' => "mysql" + ) + ); + return $dataSources; + } + + /** + * Builds the DSN string to be used by PROPEL + * @param string $Adapter + * @param string $Host + * @param string $Name + * @param string $User + * @param string $Pass + * @return string + */ + private function buildDsnString($Adapter, $Host, $Name, $User, $Pass) + { + $Dsn = $Adapter . "://" . $User . ":" . $Pass . "@" . $Host . "/" . $Name; + switch ($Adapter) { + case 'mysql': + $Dsn .= '?encoding=utf8'; + break; + } + return $Dsn; + } +}