From 519e9e477f62c574ae98c9b9d1745d89011c3293 Mon Sep 17 00:00:00 2001 From: dev-ronald Date: Fri, 21 Jul 2017 16:56:44 -0400 Subject: [PATCH] HOR-3502 HOR-2043 --- gulliver/system/class.headPublisher.php | 4 +- workflow/engine/bin/tasks/cliAddons.php | 5 - workflow/engine/bin/tasks/cliWorkspaces.php | 34 + .../engine/classes/class.pluginRegistry.php | 31 +- workflow/engine/classes/class.wsTools.php | 32 + .../engine/classes/model/AddonsManager.php | 4 +- .../engine/classes/model/PluginsRegistry.php | 138 ++ .../classes/model/PluginsRegistryPeer.php | 23 + .../model/map/PluginsRegistryMapBuilder.php | 112 ++ .../classes/model/om/BasePluginsRegistry.php | 1658 ++++++++++++++++ .../model/om/BasePluginsRegistryPeer.php | 667 +++++++ workflow/engine/config/schema.xml | 28 + workflow/engine/data/mysql/schema.sql | 33 + .../engine/methods/enterprise/enterprise.php | 4 +- .../engine/methods/login/licenseUpdate.php | 30 - .../engine/methods/setup/pluginsChange.php | 35 +- .../methods/setup/pluginsImportFile.php | 5 +- .../engine/methods/setup/pluginsRemove.php | 8 +- .../Plugins/Adapters/PluginAdapter.php | 249 +++ .../Interfaces/CaseSchedulerPlugin.php | 32 + .../Plugins/Interfaces/CronFile.php | 20 + .../Plugins/Interfaces/CssFile.php | 20 + .../Plugins/Interfaces/DashboardPage.php | 26 + .../Plugins/Interfaces/FolderDetail.php | 23 + .../Plugins/Interfaces/ImportCallBack.php | 20 + .../Plugins/Interfaces/MenuDetail.php | 23 + .../Interfaces/OpenReassignCallback.php | 17 + .../Plugins/Interfaces/PluginDetail.php | 55 + .../Plugins/Interfaces/Plugins.php | 83 + .../Plugins/Interfaces/RedirectDetail.php | 23 + .../Plugins/Interfaces/StepDetail.php | 35 + .../Interfaces/TaskExtendedProperty.php | 26 + .../Plugins/Interfaces/ToolbarDetail.php | 23 + .../Plugins/Interfaces/TriggerDetail.php | 23 + .../ProcessMaker/Plugins/PluginsRegistry.php | 1764 +++++++++++++++++ workflow/public_html/sysGeneric.php | 26 +- 36 files changed, 5242 insertions(+), 97 deletions(-) create mode 100644 workflow/engine/classes/model/PluginsRegistry.php create mode 100644 workflow/engine/classes/model/PluginsRegistryPeer.php create mode 100644 workflow/engine/classes/model/map/PluginsRegistryMapBuilder.php create mode 100644 workflow/engine/classes/model/om/BasePluginsRegistry.php create mode 100644 workflow/engine/classes/model/om/BasePluginsRegistryPeer.php create mode 100644 workflow/engine/src/ProcessMaker/Plugins/Adapters/PluginAdapter.php create mode 100644 workflow/engine/src/ProcessMaker/Plugins/Interfaces/CaseSchedulerPlugin.php create mode 100644 workflow/engine/src/ProcessMaker/Plugins/Interfaces/CronFile.php create mode 100644 workflow/engine/src/ProcessMaker/Plugins/Interfaces/CssFile.php create mode 100644 workflow/engine/src/ProcessMaker/Plugins/Interfaces/DashboardPage.php create mode 100644 workflow/engine/src/ProcessMaker/Plugins/Interfaces/FolderDetail.php create mode 100644 workflow/engine/src/ProcessMaker/Plugins/Interfaces/ImportCallBack.php create mode 100644 workflow/engine/src/ProcessMaker/Plugins/Interfaces/MenuDetail.php create mode 100644 workflow/engine/src/ProcessMaker/Plugins/Interfaces/OpenReassignCallback.php create mode 100644 workflow/engine/src/ProcessMaker/Plugins/Interfaces/PluginDetail.php create mode 100644 workflow/engine/src/ProcessMaker/Plugins/Interfaces/Plugins.php create mode 100644 workflow/engine/src/ProcessMaker/Plugins/Interfaces/RedirectDetail.php create mode 100644 workflow/engine/src/ProcessMaker/Plugins/Interfaces/StepDetail.php create mode 100644 workflow/engine/src/ProcessMaker/Plugins/Interfaces/TaskExtendedProperty.php create mode 100644 workflow/engine/src/ProcessMaker/Plugins/Interfaces/ToolbarDetail.php create mode 100644 workflow/engine/src/ProcessMaker/Plugins/Interfaces/TriggerDetail.php create mode 100644 workflow/engine/src/ProcessMaker/Plugins/PluginsRegistry.php diff --git a/gulliver/system/class.headPublisher.php b/gulliver/system/class.headPublisher.php index 84f2be7fb..96a097069 100644 --- a/gulliver/system/class.headPublisher.php +++ b/gulliver/system/class.headPublisher.php @@ -386,7 +386,7 @@ class headPublisher */ // Load external/plugin css // NOTE is necesary to move this to decorator server - if (class_exists('PMPluginRegistry')) { + if (class_exists('PMPluginRegistry') && PATH_DATA != PATH_C) { $oPluginRegistry = & PMPluginRegistry::getSingleton(); $registeredCss = $oPluginRegistry->getRegisteredCss(); foreach ($registeredCss as $cssFile) { @@ -550,7 +550,7 @@ class headPublisher $this->extJsScript[] = '/extjs/' . $cacheName; //hook for registered javascripts from plugins - if (class_exists('PMPluginRegistry')) { + if (class_exists('PMPluginRegistry') && PATH_DATA != PATH_C) { $oPluginRegistry = & PMPluginRegistry::getSingleton(); $pluginJavascripts = $oPluginRegistry->getRegisteredJavascriptBy($filename); } else { diff --git a/workflow/engine/bin/tasks/cliAddons.php b/workflow/engine/bin/tasks/cliAddons.php index 332a4deb8..779600e11 100644 --- a/workflow/engine/bin/tasks/cliAddons.php +++ b/workflow/engine/bin/tasks/cliAddons.php @@ -56,11 +56,6 @@ function run_addon_core_install($args) define("DB_ADAPTER", $args[3]); } - $sSerializedFile = PATH_DATA_SITE . "plugin.singleton"; - $oPluginRegistry = &PMPluginRegistry::getSingleton(); - if (file_exists($sSerializedFile)) { - $oPluginRegistry->unSerializeInstance(file_get_contents($sSerializedFile)); - } /////// //echo "** Installation starting... (workspace: $workspace, store: $storeId, id: $addonName)\n"; $ws = new workspaceTools($workspace); diff --git a/workflow/engine/bin/tasks/cliWorkspaces.php b/workflow/engine/bin/tasks/cliWorkspaces.php index 05b53ecd9..a450e9960 100644 --- a/workflow/engine/bin/tasks/cliWorkspaces.php +++ b/workflow/engine/bin/tasks/cliWorkspaces.php @@ -303,6 +303,19 @@ CLI::taskArg('workspace', true, true); CLI::taskOpt("lang", "Specify the language to migrate the content data. If not specified, then 'en' (English) will be used by default.\n Ex: -lfr (French) Ex: --lang=zh-CN (Mainland Chinese)", "l:","lang="); CLI::taskRun("run_migrate_content"); +CLI::taskName('migrate-plugin-information'); +CLI::taskDescription(<< Migrating and populating indexing for avoiding the use of table APP_CACHE_VIEW process took " . ($stop - $start) . " seconds.\n"); } + +function run_migrate_plugin($args, $opts) { + G::LoadSystem('inputfilter'); + $filter = new InputFilter(); + $args = $filter->xssFilterHard($args); + $workspaces = get_workspaces_from_args($args); + $lang = array_key_exists("lang", $opts) ? $opts['lang'] : SYS_LANG; + $start = microtime(true); + CLI::logging("> Migrating and populating data...\n"); + /** @var workspaceTools $workspace */ + foreach ($workspaces as $workspace) { + if (!defined('SYS_SYS')) { + define('SYS_SYS', $workspace->name); + } + print_r('Regenerating Singleton in: ' . pakeColor::colorize($workspace->name, 'INFO') . "\n"); + CLI::logging("-> Regenerating Singleton \n"); + $workspace->migrateSingleton($workspace->name, $lang); + } + $stop = microtime(true); + CLI::logging("<*> Migrating and populating data Singleton took " . ($stop - $start) . " seconds.\n"); +} diff --git a/workflow/engine/classes/class.pluginRegistry.php b/workflow/engine/classes/class.pluginRegistry.php index 79026e308..bc67e72d4 100644 --- a/workflow/engine/classes/class.pluginRegistry.php +++ b/workflow/engine/classes/class.pluginRegistry.php @@ -140,30 +140,21 @@ class PMPluginRegistry * * @return object */ - public static function getSingleton () + public static function getSingleton() { - if (self::$instance == null) { - self::$instance = new PMPluginRegistry(); - } - return self::$instance; + return \ProcessMaker\Plugins\PluginsRegistry::loadSingleton(); } /** * Load the singleton instance from a serialized stored file * * @param $file - * @return PMPluginRegistry + * @return object * @throws Exception */ public static function loadSingleton($file) { - self::$instance = unserialize(file_get_contents($file)); - - if (! is_object(self::$instance) || get_class(self::$instance) != "PMPluginRegistry") { - throw new Exception("Can't load main PMPluginRegistry object."); - } - - return self::$instance; + return \ProcessMaker\Plugins\PluginsRegistry::loadSingleton(); } /** @@ -1939,7 +1930,7 @@ class PMPluginRegistry } /** - * Saves the state of instance, in the private property 'stateSaved'. + * Saves the state of instance, in the private property 'stateSaved'. * Use the 'restoreState()' method to put the instance in the saved state. */ public static function saveState() @@ -1949,8 +1940,8 @@ class PMPluginRegistry } /** - * Restores the state of the instance that is in the private variable 'stateSaved'. - * You must save the state of the instacia with the method 'saveState()' + * Restores the state of the instance that is in the private variable 'stateSaved'. + * You must save the state of the instacia with the method 'saveState()' * before being called. */ public static function restoreState() @@ -1962,4 +1953,12 @@ class PMPluginRegistry } } + function iterateVisible() + { + $response = array(); + foreach ($this as $key => $value) { + $response[$key] = $value; + } + return $response; + } } diff --git a/workflow/engine/classes/class.wsTools.php b/workflow/engine/classes/class.wsTools.php index d64660ac8..04167427e 100644 --- a/workflow/engine/classes/class.wsTools.php +++ b/workflow/engine/classes/class.wsTools.php @@ -201,6 +201,12 @@ class workspaceTools $this->updatingWebEntryClassicModel($workSpace); $stop = microtime(true); CLI::logging("<*> Updating rows in Web Entry table for classic processes took " . ($stop - $start) . " seconds.\n"); + + $start = microtime(true); + CLI::logging("> Migrating and populating data...\n"); + $this->migrateSingleton($workSpace, $lang); + $stop = microtime(true); + CLI::logging("<*> Migrating and populating data Singleton took " . ($stop - $start) . " seconds.\n"); } /** @@ -3867,4 +3873,30 @@ class workspaceTools $this->initPropel(true); $this->upgradeTriggersOfTables($flagRecreate, $lang); } + + /** + * @param $workspace + * @param mixed|string $lang + */ + public function migrateSingleton($workspace, $lang = SYS_LANG) + { + if ((!class_exists('Memcache') || !class_exists('Memcached')) && !defined('MEMCACHED_ENABLED')) { + define('MEMCACHED_ENABLED', false); + } + $this->initPropel(true); + $conf = new Configuration(); + if(!$bExist = $conf->exists('MIGRATED_PLUGIN', 'singleton')){ + $pathSingleton = PATH_DATA . 'sites' . PATH_SEP . $workspace . PATH_SEP . 'plugin.singleton'; + $oPluginRegistry = unserialize(file_get_contents($pathSingleton)); + $pluginAdapter = new \ProcessMaker\Plugins\Adapters\PluginAdapter(); + $pluginAdapter->save($oPluginRegistry); + $data["CFG_UID"] = 'MIGRATED_PLUGIN'; + $data["OBJ_UID"] = 'singleton'; + $data["CFG_VALUE"] = 'true'; + $data["PRO_UID"] = ''; + $data["USR_UID"] = ''; + $data["APP_UID"] = ''; + $conf->create($data); + } + } } diff --git a/workflow/engine/classes/model/AddonsManager.php b/workflow/engine/classes/model/AddonsManager.php index 4762cda5e..abed7e2e4 100644 --- a/workflow/engine/classes/model/AddonsManager.php +++ b/workflow/engine/classes/model/AddonsManager.php @@ -149,9 +149,7 @@ class AddonsManager extends BaseAddonsManager //$oPluginRegistry->disablePlugin($oDetails->sNamespace); $oPluginRegistry->disablePlugin($this->getAddonName()); } - - //$oPluginRegistry->setupPlugins(); - file_put_contents(PATH_DATA_SITE . "plugin.singleton", $oPluginRegistry->serializeInstance()); + $oPluginRegistry->pluginAdapter->savePlugin($this->getAddonName(), $oPluginRegistry); return true; } diff --git a/workflow/engine/classes/model/PluginsRegistry.php b/workflow/engine/classes/model/PluginsRegistry.php new file mode 100644 index 000000000..6db797ac1 --- /dev/null +++ b/workflow/engine/classes/model/PluginsRegistry.php @@ -0,0 +1,138 @@ +setFetchmode(ResultSet::FETCHMODE_ASSOC); + $rows = array(); + while ($oDataset->next()) { + $rows[] = $oDataset->getRow(); + } + return $rows; + } + + /** + * @param $PR_UID + * @return array + * @throws Exception + */ + public static function load($PR_UID) + { + $oPluginsRegistry = PluginsRegistryPeer::retrieveByPK($PR_UID); + if ($oPluginsRegistry) { + /** @var array $aFields */ + $aFields = $oPluginsRegistry->toArray(BasePeer::TYPE_FIELDNAME); + return $aFields; + } else { + throw new Exception("User with $PR_UID does not exist!"); + } + } + + /** + * @param $PR_UID + * @return mixed|bool + */ + public static function exists($PR_UID) + { + $oPluginsRegistry = PluginsRegistryPeer::retrieveByPk($PR_UID); + if ($oPluginsRegistry) { + return true; + } else { + return false; + } + } + + /** + * @param $PR_UID + * @param array $pluginData + * @return mixed|array|bool + */ + public static function loadOrCreateIfNotExists($PR_UID, $pluginData = array()) + { + if (!self::exists($PR_UID)) { + $pluginData['PR_UID'] = $PR_UID; + self::create($pluginData); + } else { + $fields = self::load($PR_UID); + $pluginData = array_merge($fields, $pluginData); + } + return $pluginData; + } + + public static function create($aData) + { + $oConnection = Propel::getConnection(PluginsRegistryPeer::DATABASE_NAME); + try { + $oPluginsRegistry = new PluginsRegistry(); + $oPluginsRegistry->fromArray($aData, BasePeer::TYPE_FIELDNAME); + if ($oPluginsRegistry->validate()) { + $oConnection->begin(); + $oPluginsRegistry->save(); + $oConnection->commit(); + return true; + } else { + $sMessage = ''; + $aValidationFailures = $oPluginsRegistry->getValidationFailures(); + /** @var ValidationFailed $oValidationFailure */ + foreach ($aValidationFailures as $oValidationFailure) { + $sMessage .= $oValidationFailure->getMessage() . '
'; + } + throw (new Exception('The registry cannot be created!
' . $sMessage)); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } + + public static function update($aData) + { + $oConnection = Propel::getConnection(UsersPropertiesPeer::DATABASE_NAME); + try { + $oPluginsRegistry = PluginsRegistryPeer::retrieveByPK($aData['PR_UID']); + if ($oPluginsRegistry) { + $oPluginsRegistry->fromArray($aData, BasePeer::TYPE_FIELDNAME); + if ($oPluginsRegistry->validate()) { + $oConnection->begin(); + $iResult = $oPluginsRegistry->save(); + $oConnection->commit(); + return $iResult; + } else { + $sMessage = ''; + $aValidationFailures = $oPluginsRegistry->getValidationFailures(); + /** @var ValidationFailed $oValidationFailure */ + foreach ($aValidationFailures as $oValidationFailure) { + $sMessage .= $oValidationFailure->getMessage() . '
'; + } + throw (new Exception('The registry cannot be updated!
' . $sMessage)); + } + } else { + throw (new Exception('This row doesn\'t exist!')); + } + } catch (Exception $oError) { + $oConnection->rollback(); + throw ($oError); + } + } +} diff --git a/workflow/engine/classes/model/PluginsRegistryPeer.php b/workflow/engine/classes/model/PluginsRegistryPeer.php new file mode 100644 index 000000000..e3e8cb762 --- /dev/null +++ b/workflow/engine/classes/model/PluginsRegistryPeer.php @@ -0,0 +1,23 @@ +dbMap !== null); + } + + /** + * Gets the databasemap this map builder built. + * + * @return the databasemap + */ + public function getDatabaseMap() + { + return $this->dbMap; + } + + /** + * The doBuild() method builds the DatabaseMap + * + * @return void + * @throws PropelException + */ + public function doBuild() + { + $this->dbMap = Propel::getDatabaseMap('workflow'); + + $tMap = $this->dbMap->addTable('PLUGINS_REGISTRY'); + $tMap->setPhpName('PluginsRegistry'); + + $tMap->setUseIdGenerator(true); + + $tMap->addColumn('ID', 'Id', 'int', CreoleTypes::INTEGER, true, null); + + $tMap->addPrimaryKey('PR_UID', 'PrUid', 'string', CreoleTypes::VARCHAR, true, 32); + + $tMap->addColumn('PLUGIN_NAMESPACE', 'PluginNamespace', 'string', CreoleTypes::VARCHAR, true, 100); + + $tMap->addColumn('PLUGIN_DESCRIPTION', 'PluginDescription', 'string', CreoleTypes::VARCHAR, false, 200); + + $tMap->addColumn('CLASS_NAME', 'ClassName', 'string', CreoleTypes::VARCHAR, true, 100); + + $tMap->addColumn('FRIENDLY_NAME', 'FriendlyName', 'string', CreoleTypes::VARCHAR, false, 150); + + $tMap->addColumn('FILE_NAME', 'FileName', 'string', CreoleTypes::VARCHAR, true, 250); + + $tMap->addColumn('PLUGIN_FOLDER', 'PluginFolder', 'string', CreoleTypes::VARCHAR, true, 100); + + $tMap->addColumn('PLUGIN_VERSION', 'PluginVersion', 'string', CreoleTypes::VARCHAR, false, 50); + + $tMap->addColumn('PLUGIN_ENABLE', 'PluginEnable', 'boolean', CreoleTypes::BOOLEAN, false, null); + + $tMap->addColumn('PLUGIN_PRIVATE', 'PluginPrivate', 'boolean', CreoleTypes::BOOLEAN, false, null); + + $tMap->addColumn('PLUGIN_MENUS', 'PluginMenus', 'string', CreoleTypes::LONGVARCHAR, false, null); + + $tMap->addColumn('PLUGIN_FOLDERS', 'PluginFolders', 'string', CreoleTypes::LONGVARCHAR, false, null); + + $tMap->addColumn('PLUGIN_TRIGGERS', 'PluginTriggers', 'string', CreoleTypes::LONGVARCHAR, false, null); + + $tMap->addColumn('PLUGIN_PM_FUNCTIONS', 'PluginPmFunctions', 'string', CreoleTypes::LONGVARCHAR, false, null); + + $tMap->addColumn('PLUGIN_REDIRECT_LOGIN', 'PluginRedirectLogin', 'string', CreoleTypes::LONGVARCHAR, false, null); + + $tMap->addColumn('PLUGIN_STEPS', 'PluginSteps', 'string', CreoleTypes::LONGVARCHAR, false, null); + + $tMap->addColumn('PLUGIN_CSS', 'PluginCss', 'string', CreoleTypes::LONGVARCHAR, false, null); + + $tMap->addColumn('PLUGIN_JS', 'PluginJs', 'string', CreoleTypes::LONGVARCHAR, false, null); + + $tMap->addColumn('PLUGIN_REST_SERVICE', 'PluginRestService', 'string', CreoleTypes::LONGVARCHAR, false, null); + + $tMap->addColumn('PLUGIN_ATTRIBUTES', 'PluginAttributes', 'string', CreoleTypes::LONGVARCHAR, false, null); + + } // doBuild() + +} // PluginsRegistryMapBuilder diff --git a/workflow/engine/classes/model/om/BasePluginsRegistry.php b/workflow/engine/classes/model/om/BasePluginsRegistry.php new file mode 100644 index 000000000..263294137 --- /dev/null +++ b/workflow/engine/classes/model/om/BasePluginsRegistry.php @@ -0,0 +1,1658 @@ +id; + } + + /** + * Get the [pr_uid] column value. + * + * @return string + */ + public function getPrUid() + { + + return $this->pr_uid; + } + + /** + * Get the [plugin_namespace] column value. + * + * @return string + */ + public function getPluginNamespace() + { + + return $this->plugin_namespace; + } + + /** + * Get the [plugin_description] column value. + * + * @return string + */ + public function getPluginDescription() + { + + return $this->plugin_description; + } + + /** + * Get the [class_name] column value. + * + * @return string + */ + public function getClassName() + { + + return $this->class_name; + } + + /** + * Get the [friendly_name] column value. + * + * @return string + */ + public function getFriendlyName() + { + + return $this->friendly_name; + } + + /** + * Get the [file_name] column value. + * + * @return string + */ + public function getFileName() + { + + return $this->file_name; + } + + /** + * Get the [plugin_folder] column value. + * + * @return string + */ + public function getPluginFolder() + { + + return $this->plugin_folder; + } + + /** + * Get the [plugin_version] column value. + * + * @return string + */ + public function getPluginVersion() + { + + return $this->plugin_version; + } + + /** + * Get the [plugin_enable] column value. + * + * @return boolean + */ + public function getPluginEnable() + { + + return $this->plugin_enable; + } + + /** + * Get the [plugin_private] column value. + * + * @return boolean + */ + public function getPluginPrivate() + { + + return $this->plugin_private; + } + + /** + * Get the [plugin_menus] column value. + * + * @return string + */ + public function getPluginMenus() + { + + return $this->plugin_menus; + } + + /** + * Get the [plugin_folders] column value. + * + * @return string + */ + public function getPluginFolders() + { + + return $this->plugin_folders; + } + + /** + * Get the [plugin_triggers] column value. + * + * @return string + */ + public function getPluginTriggers() + { + + return $this->plugin_triggers; + } + + /** + * Get the [plugin_pm_functions] column value. + * + * @return string + */ + public function getPluginPmFunctions() + { + + return $this->plugin_pm_functions; + } + + /** + * Get the [plugin_redirect_login] column value. + * + * @return string + */ + public function getPluginRedirectLogin() + { + + return $this->plugin_redirect_login; + } + + /** + * Get the [plugin_steps] column value. + * + * @return string + */ + public function getPluginSteps() + { + + return $this->plugin_steps; + } + + /** + * Get the [plugin_css] column value. + * + * @return string + */ + public function getPluginCss() + { + + return $this->plugin_css; + } + + /** + * Get the [plugin_js] column value. + * + * @return string + */ + public function getPluginJs() + { + + return $this->plugin_js; + } + + /** + * Get the [plugin_rest_service] column value. + * + * @return string + */ + public function getPluginRestService() + { + + return $this->plugin_rest_service; + } + + /** + * Get the [plugin_attributes] column value. + * + * @return string + */ + public function getPluginAttributes() + { + + return $this->plugin_attributes; + } + + /** + * Set the value of [id] column. + * + * @param int $v new value + * @return void + */ + public function setId($v) + { + + // Since the native PHP type for this column is integer, + // we will cast the input value to an int (if it is not). + if ($v !== null && !is_int($v) && is_numeric($v)) { + $v = (int) $v; + } + + if ($this->id !== $v) { + $this->id = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::ID; + } + + } // setId() + + /** + * Set the value of [pr_uid] column. + * + * @param string $v new value + * @return void + */ + public function setPrUid($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->pr_uid !== $v || $v === '') { + $this->pr_uid = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::PR_UID; + } + + } // setPrUid() + + /** + * Set the value of [plugin_namespace] column. + * + * @param string $v new value + * @return void + */ + public function setPluginNamespace($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->plugin_namespace !== $v) { + $this->plugin_namespace = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::PLUGIN_NAMESPACE; + } + + } // setPluginNamespace() + + /** + * Set the value of [plugin_description] column. + * + * @param string $v new value + * @return void + */ + public function setPluginDescription($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->plugin_description !== $v || $v === '') { + $this->plugin_description = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::PLUGIN_DESCRIPTION; + } + + } // setPluginDescription() + + /** + * Set the value of [class_name] column. + * + * @param string $v new value + * @return void + */ + public function setClassName($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->class_name !== $v) { + $this->class_name = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::CLASS_NAME; + } + + } // setClassName() + + /** + * Set the value of [friendly_name] column. + * + * @param string $v new value + * @return void + */ + public function setFriendlyName($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->friendly_name !== $v || $v === '') { + $this->friendly_name = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::FRIENDLY_NAME; + } + + } // setFriendlyName() + + /** + * Set the value of [file_name] column. + * + * @param string $v new value + * @return void + */ + public function setFileName($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->file_name !== $v || $v === '') { + $this->file_name = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::FILE_NAME; + } + + } // setFileName() + + /** + * Set the value of [plugin_folder] column. + * + * @param string $v new value + * @return void + */ + public function setPluginFolder($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->plugin_folder !== $v || $v === '') { + $this->plugin_folder = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::PLUGIN_FOLDER; + } + + } // setPluginFolder() + + /** + * Set the value of [plugin_version] column. + * + * @param string $v new value + * @return void + */ + public function setPluginVersion($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->plugin_version !== $v || $v === '') { + $this->plugin_version = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::PLUGIN_VERSION; + } + + } // setPluginVersion() + + /** + * Set the value of [plugin_enable] column. + * + * @param boolean $v new value + * @return void + */ + public function setPluginEnable($v) + { + + if ($this->plugin_enable !== $v || $v === true) { + $this->plugin_enable = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::PLUGIN_ENABLE; + } + + } // setPluginEnable() + + /** + * Set the value of [plugin_private] column. + * + * @param boolean $v new value + * @return void + */ + public function setPluginPrivate($v) + { + + if ($this->plugin_private !== $v || $v === true) { + $this->plugin_private = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::PLUGIN_PRIVATE; + } + + } // setPluginPrivate() + + /** + * Set the value of [plugin_menus] column. + * + * @param string $v new value + * @return void + */ + public function setPluginMenus($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->plugin_menus !== $v) { + $this->plugin_menus = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::PLUGIN_MENUS; + } + + } // setPluginMenus() + + /** + * Set the value of [plugin_folders] column. + * + * @param string $v new value + * @return void + */ + public function setPluginFolders($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->plugin_folders !== $v) { + $this->plugin_folders = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::PLUGIN_FOLDERS; + } + + } // setPluginFolders() + + /** + * Set the value of [plugin_triggers] column. + * + * @param string $v new value + * @return void + */ + public function setPluginTriggers($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->plugin_triggers !== $v) { + $this->plugin_triggers = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::PLUGIN_TRIGGERS; + } + + } // setPluginTriggers() + + /** + * Set the value of [plugin_pm_functions] column. + * + * @param string $v new value + * @return void + */ + public function setPluginPmFunctions($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->plugin_pm_functions !== $v) { + $this->plugin_pm_functions = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::PLUGIN_PM_FUNCTIONS; + } + + } // setPluginPmFunctions() + + /** + * Set the value of [plugin_redirect_login] column. + * + * @param string $v new value + * @return void + */ + public function setPluginRedirectLogin($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->plugin_redirect_login !== $v) { + $this->plugin_redirect_login = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::PLUGIN_REDIRECT_LOGIN; + } + + } // setPluginRedirectLogin() + + /** + * Set the value of [plugin_steps] column. + * + * @param string $v new value + * @return void + */ + public function setPluginSteps($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->plugin_steps !== $v) { + $this->plugin_steps = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::PLUGIN_STEPS; + } + + } // setPluginSteps() + + /** + * Set the value of [plugin_css] column. + * + * @param string $v new value + * @return void + */ + public function setPluginCss($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->plugin_css !== $v) { + $this->plugin_css = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::PLUGIN_CSS; + } + + } // setPluginCss() + + /** + * Set the value of [plugin_js] column. + * + * @param string $v new value + * @return void + */ + public function setPluginJs($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->plugin_js !== $v) { + $this->plugin_js = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::PLUGIN_JS; + } + + } // setPluginJs() + + /** + * Set the value of [plugin_rest_service] column. + * + * @param string $v new value + * @return void + */ + public function setPluginRestService($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->plugin_rest_service !== $v) { + $this->plugin_rest_service = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::PLUGIN_REST_SERVICE; + } + + } // setPluginRestService() + + /** + * Set the value of [plugin_attributes] column. + * + * @param string $v new value + * @return void + */ + public function setPluginAttributes($v) + { + + // Since the native PHP type for this column is string, + // we will cast the input to a string (if it is not). + if ($v !== null && !is_string($v)) { + $v = (string) $v; + } + + if ($this->plugin_attributes !== $v) { + $this->plugin_attributes = $v; + $this->modifiedColumns[] = PluginsRegistryPeer::PLUGIN_ATTRIBUTES; + } + + } // setPluginAttributes() + + /** + * Hydrates (populates) the object variables with values from the database resultset. + * + * An offset (1-based "start column") is specified so that objects can be hydrated + * with a subset of the columns in the resultset rows. This is needed, for example, + * for results of JOIN queries where the resultset row includes columns from two or + * more tables. + * + * @param ResultSet $rs The ResultSet class with cursor advanced to desired record pos. + * @param int $startcol 1-based offset column which indicates which restultset column to start with. + * @return int next starting column + * @throws PropelException - Any caught Exception will be rewrapped as a PropelException. + */ + public function hydrate(ResultSet $rs, $startcol = 1) + { + try { + + $this->id = $rs->getInt($startcol + 0); + + $this->pr_uid = $rs->getString($startcol + 1); + + $this->plugin_namespace = $rs->getString($startcol + 2); + + $this->plugin_description = $rs->getString($startcol + 3); + + $this->class_name = $rs->getString($startcol + 4); + + $this->friendly_name = $rs->getString($startcol + 5); + + $this->file_name = $rs->getString($startcol + 6); + + $this->plugin_folder = $rs->getString($startcol + 7); + + $this->plugin_version = $rs->getString($startcol + 8); + + $this->plugin_enable = $rs->getBoolean($startcol + 9); + + $this->plugin_private = $rs->getBoolean($startcol + 10); + + $this->plugin_menus = $rs->getString($startcol + 11); + + $this->plugin_folders = $rs->getString($startcol + 12); + + $this->plugin_triggers = $rs->getString($startcol + 13); + + $this->plugin_pm_functions = $rs->getString($startcol + 14); + + $this->plugin_redirect_login = $rs->getString($startcol + 15); + + $this->plugin_steps = $rs->getString($startcol + 16); + + $this->plugin_css = $rs->getString($startcol + 17); + + $this->plugin_js = $rs->getString($startcol + 18); + + $this->plugin_rest_service = $rs->getString($startcol + 19); + + $this->plugin_attributes = $rs->getString($startcol + 20); + + $this->resetModified(); + + $this->setNew(false); + + // FIXME - using NUM_COLUMNS may be clearer. + return $startcol + 21; // 21 = PluginsRegistryPeer::NUM_COLUMNS - PluginsRegistryPeer::NUM_LAZY_LOAD_COLUMNS). + + } catch (Exception $e) { + throw new PropelException("Error populating PluginsRegistry object", $e); + } + } + + /** + * Removes this object from datastore and sets delete attribute. + * + * @param Connection $con + * @return void + * @throws PropelException + * @see BaseObject::setDeleted() + * @see BaseObject::isDeleted() + */ + public function delete($con = null) + { + if ($this->isDeleted()) { + throw new PropelException("This object has already been deleted."); + } + + if ($con === null) { + $con = Propel::getConnection(PluginsRegistryPeer::DATABASE_NAME); + } + + try { + $con->begin(); + PluginsRegistryPeer::doDelete($this, $con); + $this->setDeleted(true); + $con->commit(); + } catch (PropelException $e) { + $con->rollback(); + throw $e; + } + } + + /** + * Stores the object in the database. If the object is new, + * it inserts it; otherwise an update is performed. This method + * wraps the doSave() worker method in a transaction. + * + * @param Connection $con + * @return int The number of rows affected by this insert/update + * @throws PropelException + * @see doSave() + */ + public function save($con = null) + { + if ($this->isDeleted()) { + throw new PropelException("You cannot save an object that has been deleted."); + } + + if ($con === null) { + $con = Propel::getConnection(PluginsRegistryPeer::DATABASE_NAME); + } + + try { + $con->begin(); + $affectedRows = $this->doSave($con); + $con->commit(); + return $affectedRows; + } catch (PropelException $e) { + $con->rollback(); + throw $e; + } + } + + /** + * Stores the object in the database. + * + * If the object is new, it inserts it; otherwise an update is performed. + * All related objects are also updated in this method. + * + * @param Connection $con + * @return int The number of rows affected by this insert/update and any referring + * @throws PropelException + * @see save() + */ + protected function doSave($con) + { + $affectedRows = 0; // initialize var to track total num of affected rows + if (!$this->alreadyInSave) { + $this->alreadyInSave = true; + + + // If this object has been modified, then save it to the database. + if ($this->isModified()) { + if ($this->isNew()) { + $pk = PluginsRegistryPeer::doInsert($this, $con); + $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which + // should always be true here (even though technically + // BasePeer::doInsert() can insert multiple rows). + + $this->setNew(false); + } else { + $affectedRows += PluginsRegistryPeer::doUpdate($this, $con); + } + $this->resetModified(); // [HL] After being saved an object is no longer 'modified' + } + + $this->alreadyInSave = false; + } + return $affectedRows; + } // doSave() + + /** + * Array of ValidationFailed objects. + * @var array ValidationFailed[] + */ + protected $validationFailures = array(); + + /** + * Gets any ValidationFailed objects that resulted from last call to validate(). + * + * + * @return array ValidationFailed[] + * @see validate() + */ + public function getValidationFailures() + { + return $this->validationFailures; + } + + /** + * Validates the objects modified field values and all objects related to this table. + * + * If $columns is either a column name or an array of column names + * only those columns are validated. + * + * @param mixed $columns Column name or an array of column names. + * @return boolean Whether all columns pass validation. + * @see doValidate() + * @see getValidationFailures() + */ + public function validate($columns = null) + { + $res = $this->doValidate($columns); + if ($res === true) { + $this->validationFailures = array(); + return true; + } else { + $this->validationFailures = $res; + return false; + } + } + + /** + * This function performs the validation work for complex object models. + * + * In addition to checking the current object, all related objects will + * also be validated. If all pass then true is returned; otherwise + * an aggreagated array of ValidationFailed objects will be returned. + * + * @param array $columns Array of column names to validate. + * @return mixed true if all validations pass; + array of ValidationFailed objects otherwise. + */ + protected function doValidate($columns = null) + { + if (!$this->alreadyInValidation) { + $this->alreadyInValidation = true; + $retval = null; + + $failureMap = array(); + + + if (($retval = PluginsRegistryPeer::doValidate($this, $columns)) !== true) { + $failureMap = array_merge($failureMap, $retval); + } + + + + $this->alreadyInValidation = false; + } + + return (!empty($failureMap) ? $failureMap : true); + } + + /** + * Retrieves a field from the object by name passed in as a string. + * + * @param string $name name + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TYPE_PHPNAME, + * TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM + * @return mixed Value of field. + */ + public function getByName($name, $type = BasePeer::TYPE_PHPNAME) + { + $pos = PluginsRegistryPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM); + return $this->getByPosition($pos); + } + + /** + * Retrieves a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @return mixed Value of field at $pos + */ + public function getByPosition($pos) + { + switch($pos) { + case 0: + return $this->getId(); + break; + case 1: + return $this->getPrUid(); + break; + case 2: + return $this->getPluginNamespace(); + break; + case 3: + return $this->getPluginDescription(); + break; + case 4: + return $this->getClassName(); + break; + case 5: + return $this->getFriendlyName(); + break; + case 6: + return $this->getFileName(); + break; + case 7: + return $this->getPluginFolder(); + break; + case 8: + return $this->getPluginVersion(); + break; + case 9: + return $this->getPluginEnable(); + break; + case 10: + return $this->getPluginPrivate(); + break; + case 11: + return $this->getPluginMenus(); + break; + case 12: + return $this->getPluginFolders(); + break; + case 13: + return $this->getPluginTriggers(); + break; + case 14: + return $this->getPluginPmFunctions(); + break; + case 15: + return $this->getPluginRedirectLogin(); + break; + case 16: + return $this->getPluginSteps(); + break; + case 17: + return $this->getPluginCss(); + break; + case 18: + return $this->getPluginJs(); + break; + case 19: + return $this->getPluginRestService(); + break; + case 20: + return $this->getPluginAttributes(); + break; + default: + return null; + break; + } // switch() + } + + /** + * Exports the object as an array. + * + * You can specify the key type of the array by passing one of the class + * type constants. + * + * @param string $keyType One of the class type constants TYPE_PHPNAME, + * TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM + * @return an associative array containing the field names (as keys) and field values + */ + public function toArray($keyType = BasePeer::TYPE_PHPNAME) + { + $keys = PluginsRegistryPeer::getFieldNames($keyType); + $result = array( + $keys[0] => $this->getId(), + $keys[1] => $this->getPrUid(), + $keys[2] => $this->getPluginNamespace(), + $keys[3] => $this->getPluginDescription(), + $keys[4] => $this->getClassName(), + $keys[5] => $this->getFriendlyName(), + $keys[6] => $this->getFileName(), + $keys[7] => $this->getPluginFolder(), + $keys[8] => $this->getPluginVersion(), + $keys[9] => $this->getPluginEnable(), + $keys[10] => $this->getPluginPrivate(), + $keys[11] => $this->getPluginMenus(), + $keys[12] => $this->getPluginFolders(), + $keys[13] => $this->getPluginTriggers(), + $keys[14] => $this->getPluginPmFunctions(), + $keys[15] => $this->getPluginRedirectLogin(), + $keys[16] => $this->getPluginSteps(), + $keys[17] => $this->getPluginCss(), + $keys[18] => $this->getPluginJs(), + $keys[19] => $this->getPluginRestService(), + $keys[20] => $this->getPluginAttributes(), + ); + return $result; + } + + /** + * Sets a field from the object by name passed in as a string. + * + * @param string $name peer name + * @param mixed $value field value + * @param string $type The type of fieldname the $name is of: + * one of the class type constants TYPE_PHPNAME, + * TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM + * @return void + */ + public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME) + { + $pos = PluginsRegistryPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM); + return $this->setByPosition($pos, $value); + } + + /** + * Sets a field from the object by Position as specified in the xml schema. + * Zero-based. + * + * @param int $pos position in xml schema + * @param mixed $value field value + * @return void + */ + public function setByPosition($pos, $value) + { + switch($pos) { + case 0: + $this->setId($value); + break; + case 1: + $this->setPrUid($value); + break; + case 2: + $this->setPluginNamespace($value); + break; + case 3: + $this->setPluginDescription($value); + break; + case 4: + $this->setClassName($value); + break; + case 5: + $this->setFriendlyName($value); + break; + case 6: + $this->setFileName($value); + break; + case 7: + $this->setPluginFolder($value); + break; + case 8: + $this->setPluginVersion($value); + break; + case 9: + $this->setPluginEnable($value); + break; + case 10: + $this->setPluginPrivate($value); + break; + case 11: + $this->setPluginMenus($value); + break; + case 12: + $this->setPluginFolders($value); + break; + case 13: + $this->setPluginTriggers($value); + break; + case 14: + $this->setPluginPmFunctions($value); + break; + case 15: + $this->setPluginRedirectLogin($value); + break; + case 16: + $this->setPluginSteps($value); + break; + case 17: + $this->setPluginCss($value); + break; + case 18: + $this->setPluginJs($value); + break; + case 19: + $this->setPluginRestService($value); + break; + case 20: + $this->setPluginAttributes($value); + break; + } // switch() + } + + /** + * Populates the object using an array. + * + * This is particularly useful when populating an object from one of the + * request arrays (e.g. $_POST). This method goes through the column + * names, checking to see whether a matching key exists in populated + * array. If so the setByName() method is called for that column. + * + * You can specify the key type of the array by additionally passing one + * of the class type constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, + * TYPE_NUM. The default key type is the column's phpname (e.g. 'authorId') + * + * @param array $arr An array to populate the object from. + * @param string $keyType The type of keys the array uses. + * @return void + */ + public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) + { + $keys = PluginsRegistryPeer::getFieldNames($keyType); + + if (array_key_exists($keys[0], $arr)) { + $this->setId($arr[$keys[0]]); + } + + if (array_key_exists($keys[1], $arr)) { + $this->setPrUid($arr[$keys[1]]); + } + + if (array_key_exists($keys[2], $arr)) { + $this->setPluginNamespace($arr[$keys[2]]); + } + + if (array_key_exists($keys[3], $arr)) { + $this->setPluginDescription($arr[$keys[3]]); + } + + if (array_key_exists($keys[4], $arr)) { + $this->setClassName($arr[$keys[4]]); + } + + if (array_key_exists($keys[5], $arr)) { + $this->setFriendlyName($arr[$keys[5]]); + } + + if (array_key_exists($keys[6], $arr)) { + $this->setFileName($arr[$keys[6]]); + } + + if (array_key_exists($keys[7], $arr)) { + $this->setPluginFolder($arr[$keys[7]]); + } + + if (array_key_exists($keys[8], $arr)) { + $this->setPluginVersion($arr[$keys[8]]); + } + + if (array_key_exists($keys[9], $arr)) { + $this->setPluginEnable($arr[$keys[9]]); + } + + if (array_key_exists($keys[10], $arr)) { + $this->setPluginPrivate($arr[$keys[10]]); + } + + if (array_key_exists($keys[11], $arr)) { + $this->setPluginMenus($arr[$keys[11]]); + } + + if (array_key_exists($keys[12], $arr)) { + $this->setPluginFolders($arr[$keys[12]]); + } + + if (array_key_exists($keys[13], $arr)) { + $this->setPluginTriggers($arr[$keys[13]]); + } + + if (array_key_exists($keys[14], $arr)) { + $this->setPluginPmFunctions($arr[$keys[14]]); + } + + if (array_key_exists($keys[15], $arr)) { + $this->setPluginRedirectLogin($arr[$keys[15]]); + } + + if (array_key_exists($keys[16], $arr)) { + $this->setPluginSteps($arr[$keys[16]]); + } + + if (array_key_exists($keys[17], $arr)) { + $this->setPluginCss($arr[$keys[17]]); + } + + if (array_key_exists($keys[18], $arr)) { + $this->setPluginJs($arr[$keys[18]]); + } + + if (array_key_exists($keys[19], $arr)) { + $this->setPluginRestService($arr[$keys[19]]); + } + + if (array_key_exists($keys[20], $arr)) { + $this->setPluginAttributes($arr[$keys[20]]); + } + + } + + /** + * Build a Criteria object containing the values of all modified columns in this object. + * + * @return Criteria The Criteria object containing all modified values. + */ + public function buildCriteria() + { + $criteria = new Criteria(PluginsRegistryPeer::DATABASE_NAME); + + if ($this->isColumnModified(PluginsRegistryPeer::ID)) { + $criteria->add(PluginsRegistryPeer::ID, $this->id); + } + + if ($this->isColumnModified(PluginsRegistryPeer::PR_UID)) { + $criteria->add(PluginsRegistryPeer::PR_UID, $this->pr_uid); + } + + if ($this->isColumnModified(PluginsRegistryPeer::PLUGIN_NAMESPACE)) { + $criteria->add(PluginsRegistryPeer::PLUGIN_NAMESPACE, $this->plugin_namespace); + } + + if ($this->isColumnModified(PluginsRegistryPeer::PLUGIN_DESCRIPTION)) { + $criteria->add(PluginsRegistryPeer::PLUGIN_DESCRIPTION, $this->plugin_description); + } + + if ($this->isColumnModified(PluginsRegistryPeer::CLASS_NAME)) { + $criteria->add(PluginsRegistryPeer::CLASS_NAME, $this->class_name); + } + + if ($this->isColumnModified(PluginsRegistryPeer::FRIENDLY_NAME)) { + $criteria->add(PluginsRegistryPeer::FRIENDLY_NAME, $this->friendly_name); + } + + if ($this->isColumnModified(PluginsRegistryPeer::FILE_NAME)) { + $criteria->add(PluginsRegistryPeer::FILE_NAME, $this->file_name); + } + + if ($this->isColumnModified(PluginsRegistryPeer::PLUGIN_FOLDER)) { + $criteria->add(PluginsRegistryPeer::PLUGIN_FOLDER, $this->plugin_folder); + } + + if ($this->isColumnModified(PluginsRegistryPeer::PLUGIN_VERSION)) { + $criteria->add(PluginsRegistryPeer::PLUGIN_VERSION, $this->plugin_version); + } + + if ($this->isColumnModified(PluginsRegistryPeer::PLUGIN_ENABLE)) { + $criteria->add(PluginsRegistryPeer::PLUGIN_ENABLE, $this->plugin_enable); + } + + if ($this->isColumnModified(PluginsRegistryPeer::PLUGIN_PRIVATE)) { + $criteria->add(PluginsRegistryPeer::PLUGIN_PRIVATE, $this->plugin_private); + } + + if ($this->isColumnModified(PluginsRegistryPeer::PLUGIN_MENUS)) { + $criteria->add(PluginsRegistryPeer::PLUGIN_MENUS, $this->plugin_menus); + } + + if ($this->isColumnModified(PluginsRegistryPeer::PLUGIN_FOLDERS)) { + $criteria->add(PluginsRegistryPeer::PLUGIN_FOLDERS, $this->plugin_folders); + } + + if ($this->isColumnModified(PluginsRegistryPeer::PLUGIN_TRIGGERS)) { + $criteria->add(PluginsRegistryPeer::PLUGIN_TRIGGERS, $this->plugin_triggers); + } + + if ($this->isColumnModified(PluginsRegistryPeer::PLUGIN_PM_FUNCTIONS)) { + $criteria->add(PluginsRegistryPeer::PLUGIN_PM_FUNCTIONS, $this->plugin_pm_functions); + } + + if ($this->isColumnModified(PluginsRegistryPeer::PLUGIN_REDIRECT_LOGIN)) { + $criteria->add(PluginsRegistryPeer::PLUGIN_REDIRECT_LOGIN, $this->plugin_redirect_login); + } + + if ($this->isColumnModified(PluginsRegistryPeer::PLUGIN_STEPS)) { + $criteria->add(PluginsRegistryPeer::PLUGIN_STEPS, $this->plugin_steps); + } + + if ($this->isColumnModified(PluginsRegistryPeer::PLUGIN_CSS)) { + $criteria->add(PluginsRegistryPeer::PLUGIN_CSS, $this->plugin_css); + } + + if ($this->isColumnModified(PluginsRegistryPeer::PLUGIN_JS)) { + $criteria->add(PluginsRegistryPeer::PLUGIN_JS, $this->plugin_js); + } + + if ($this->isColumnModified(PluginsRegistryPeer::PLUGIN_REST_SERVICE)) { + $criteria->add(PluginsRegistryPeer::PLUGIN_REST_SERVICE, $this->plugin_rest_service); + } + + if ($this->isColumnModified(PluginsRegistryPeer::PLUGIN_ATTRIBUTES)) { + $criteria->add(PluginsRegistryPeer::PLUGIN_ATTRIBUTES, $this->plugin_attributes); + } + + + return $criteria; + } + + /** + * Builds a Criteria object containing the primary key for this object. + * + * Unlike buildCriteria() this method includes the primary key values regardless + * of whether or not they have been modified. + * + * @return Criteria The Criteria object containing value(s) for primary key(s). + */ + public function buildPkeyCriteria() + { + $criteria = new Criteria(PluginsRegistryPeer::DATABASE_NAME); + + $criteria->add(PluginsRegistryPeer::PR_UID, $this->pr_uid); + + return $criteria; + } + + /** + * Returns the primary key for this object (row). + * @return string + */ + public function getPrimaryKey() + { + return $this->getPrUid(); + } + + /** + * Generic method to set the primary key (pr_uid column). + * + * @param string $key Primary key. + * @return void + */ + public function setPrimaryKey($key) + { + $this->setPrUid($key); + } + + /** + * Sets contents of passed object to values from current object. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param object $copyObj An object of PluginsRegistry (or compatible) type. + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @throws PropelException + */ + public function copyInto($copyObj, $deepCopy = false) + { + + $copyObj->setId($this->id); + + $copyObj->setPluginNamespace($this->plugin_namespace); + + $copyObj->setPluginDescription($this->plugin_description); + + $copyObj->setClassName($this->class_name); + + $copyObj->setFriendlyName($this->friendly_name); + + $copyObj->setFileName($this->file_name); + + $copyObj->setPluginFolder($this->plugin_folder); + + $copyObj->setPluginVersion($this->plugin_version); + + $copyObj->setPluginEnable($this->plugin_enable); + + $copyObj->setPluginPrivate($this->plugin_private); + + $copyObj->setPluginMenus($this->plugin_menus); + + $copyObj->setPluginFolders($this->plugin_folders); + + $copyObj->setPluginTriggers($this->plugin_triggers); + + $copyObj->setPluginPmFunctions($this->plugin_pm_functions); + + $copyObj->setPluginRedirectLogin($this->plugin_redirect_login); + + $copyObj->setPluginSteps($this->plugin_steps); + + $copyObj->setPluginCss($this->plugin_css); + + $copyObj->setPluginJs($this->plugin_js); + + $copyObj->setPluginRestService($this->plugin_rest_service); + + $copyObj->setPluginAttributes($this->plugin_attributes); + + + $copyObj->setNew(true); + + $copyObj->setPrUid(''); // this is a pkey column, so set to default value + + } + + /** + * Makes a copy of this object that will be inserted as a new row in table when saved. + * It creates a new object filling in the simple attributes, but skipping any primary + * keys that are defined for the table. + * + * If desired, this method can also make copies of all associated (fkey referrers) + * objects. + * + * @param boolean $deepCopy Whether to also copy all rows that refer (by fkey) to the current row. + * @return PluginsRegistry Clone of current object. + * @throws PropelException + */ + public function copy($deepCopy = false) + { + // we use get_class(), because this might be a subclass + $clazz = get_class($this); + $copyObj = new $clazz(); + $this->copyInto($copyObj, $deepCopy); + return $copyObj; + } + + /** + * Returns a peer instance associated with this om. + * + * Since Peer classes are not to have any instance attributes, this method returns the + * same instance for all member of this class. The method could therefore + * be static, but this would prevent one from overriding the behavior. + * + * @return PluginsRegistryPeer + */ + public function getPeer() + { + if (self::$peer === null) { + self::$peer = new PluginsRegistryPeer(); + } + return self::$peer; + } +} + diff --git a/workflow/engine/classes/model/om/BasePluginsRegistryPeer.php b/workflow/engine/classes/model/om/BasePluginsRegistryPeer.php new file mode 100644 index 000000000..ce93113f0 --- /dev/null +++ b/workflow/engine/classes/model/om/BasePluginsRegistryPeer.php @@ -0,0 +1,667 @@ + array ('Id', 'PrUid', 'PluginNamespace', 'PluginDescription', 'ClassName', 'FriendlyName', 'FileName', 'PluginFolder', 'PluginVersion', 'PluginEnable', 'PluginPrivate', 'PluginMenus', 'PluginFolders', 'PluginTriggers', 'PluginPmFunctions', 'PluginRedirectLogin', 'PluginSteps', 'PluginCss', 'PluginJs', 'PluginRestService', 'PluginAttributes', ), + BasePeer::TYPE_COLNAME => array (PluginsRegistryPeer::ID, PluginsRegistryPeer::PR_UID, PluginsRegistryPeer::PLUGIN_NAMESPACE, PluginsRegistryPeer::PLUGIN_DESCRIPTION, PluginsRegistryPeer::CLASS_NAME, PluginsRegistryPeer::FRIENDLY_NAME, PluginsRegistryPeer::FILE_NAME, PluginsRegistryPeer::PLUGIN_FOLDER, PluginsRegistryPeer::PLUGIN_VERSION, PluginsRegistryPeer::PLUGIN_ENABLE, PluginsRegistryPeer::PLUGIN_PRIVATE, PluginsRegistryPeer::PLUGIN_MENUS, PluginsRegistryPeer::PLUGIN_FOLDERS, PluginsRegistryPeer::PLUGIN_TRIGGERS, PluginsRegistryPeer::PLUGIN_PM_FUNCTIONS, PluginsRegistryPeer::PLUGIN_REDIRECT_LOGIN, PluginsRegistryPeer::PLUGIN_STEPS, PluginsRegistryPeer::PLUGIN_CSS, PluginsRegistryPeer::PLUGIN_JS, PluginsRegistryPeer::PLUGIN_REST_SERVICE, PluginsRegistryPeer::PLUGIN_ATTRIBUTES, ), + BasePeer::TYPE_FIELDNAME => array ('ID', 'PR_UID', 'PLUGIN_NAMESPACE', 'PLUGIN_DESCRIPTION', 'CLASS_NAME', 'FRIENDLY_NAME', 'FILE_NAME', 'PLUGIN_FOLDER', 'PLUGIN_VERSION', 'PLUGIN_ENABLE', 'PLUGIN_PRIVATE', 'PLUGIN_MENUS', 'PLUGIN_FOLDERS', 'PLUGIN_TRIGGERS', 'PLUGIN_PM_FUNCTIONS', 'PLUGIN_REDIRECT_LOGIN', 'PLUGIN_STEPS', 'PLUGIN_CSS', 'PLUGIN_JS', 'PLUGIN_REST_SERVICE', 'PLUGIN_ATTRIBUTES', ), + BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ) + ); + + /** + * holds an array of keys for quick access to the fieldnames array + * + * first dimension keys are the type constants + * e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0 + */ + private static $fieldKeys = array ( + BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'PrUid' => 1, 'PluginNamespace' => 2, 'PluginDescription' => 3, 'ClassName' => 4, 'FriendlyName' => 5, 'FileName' => 6, 'PluginFolder' => 7, 'PluginVersion' => 8, 'PluginEnable' => 9, 'PluginPrivate' => 10, 'PluginMenus' => 11, 'PluginFolders' => 12, 'PluginTriggers' => 13, 'PluginPmFunctions' => 14, 'PluginRedirectLogin' => 15, 'PluginSteps' => 16, 'PluginCss' => 17, 'PluginJs' => 18, 'PluginRestService' => 19, 'PluginAttributes' => 20, ), + BasePeer::TYPE_COLNAME => array (PluginsRegistryPeer::ID => 0, PluginsRegistryPeer::PR_UID => 1, PluginsRegistryPeer::PLUGIN_NAMESPACE => 2, PluginsRegistryPeer::PLUGIN_DESCRIPTION => 3, PluginsRegistryPeer::CLASS_NAME => 4, PluginsRegistryPeer::FRIENDLY_NAME => 5, PluginsRegistryPeer::FILE_NAME => 6, PluginsRegistryPeer::PLUGIN_FOLDER => 7, PluginsRegistryPeer::PLUGIN_VERSION => 8, PluginsRegistryPeer::PLUGIN_ENABLE => 9, PluginsRegistryPeer::PLUGIN_PRIVATE => 10, PluginsRegistryPeer::PLUGIN_MENUS => 11, PluginsRegistryPeer::PLUGIN_FOLDERS => 12, PluginsRegistryPeer::PLUGIN_TRIGGERS => 13, PluginsRegistryPeer::PLUGIN_PM_FUNCTIONS => 14, PluginsRegistryPeer::PLUGIN_REDIRECT_LOGIN => 15, PluginsRegistryPeer::PLUGIN_STEPS => 16, PluginsRegistryPeer::PLUGIN_CSS => 17, PluginsRegistryPeer::PLUGIN_JS => 18, PluginsRegistryPeer::PLUGIN_REST_SERVICE => 19, PluginsRegistryPeer::PLUGIN_ATTRIBUTES => 20, ), + BasePeer::TYPE_FIELDNAME => array ('ID' => 0, 'PR_UID' => 1, 'PLUGIN_NAMESPACE' => 2, 'PLUGIN_DESCRIPTION' => 3, 'CLASS_NAME' => 4, 'FRIENDLY_NAME' => 5, 'FILE_NAME' => 6, 'PLUGIN_FOLDER' => 7, 'PLUGIN_VERSION' => 8, 'PLUGIN_ENABLE' => 9, 'PLUGIN_PRIVATE' => 10, 'PLUGIN_MENUS' => 11, 'PLUGIN_FOLDERS' => 12, 'PLUGIN_TRIGGERS' => 13, 'PLUGIN_PM_FUNCTIONS' => 14, 'PLUGIN_REDIRECT_LOGIN' => 15, 'PLUGIN_STEPS' => 16, 'PLUGIN_CSS' => 17, 'PLUGIN_JS' => 18, 'PLUGIN_REST_SERVICE' => 19, 'PLUGIN_ATTRIBUTES' => 20, ), + BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ) + ); + + /** + * @return MapBuilder the map builder for this peer + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getMapBuilder() + { + include_once 'classes/model/map/PluginsRegistryMapBuilder.php'; + return BasePeer::getMapBuilder('classes.model.map.PluginsRegistryMapBuilder'); + } + /** + * Gets a map (hash) of PHP names to DB column names. + * + * @return array The PHP to DB name map for this peer + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @deprecated Use the getFieldNames() and translateFieldName() methods instead of this. + */ + public static function getPhpNameMap() + { + if (self::$phpNameMap === null) { + $map = PluginsRegistryPeer::getTableMap(); + $columns = $map->getColumns(); + $nameMap = array(); + foreach ($columns as $column) { + $nameMap[$column->getPhpName()] = $column->getColumnName(); + } + self::$phpNameMap = $nameMap; + } + return self::$phpNameMap; + } + /** + * Translates a fieldname to another type + * + * @param string $name field name + * @param string $fromType One of the class type constants TYPE_PHPNAME, + * TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM + * @param string $toType One of the class type constants + * @return string translated name of the field. + */ + static public function translateFieldName($name, $fromType, $toType) + { + $toNames = self::getFieldNames($toType); + $key = isset(self::$fieldKeys[$fromType][$name]) ? self::$fieldKeys[$fromType][$name] : null; + if ($key === null) { + throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(self::$fieldKeys[$fromType], true)); + } + return $toNames[$key]; + } + + /** + * Returns an array of of field names. + * + * @param string $type The type of fieldnames to return: + * One of the class type constants TYPE_PHPNAME, + * TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM + * @return array A list of field names + */ + + static public function getFieldNames($type = BasePeer::TYPE_PHPNAME) + { + if (!array_key_exists($type, self::$fieldNames)) { + throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, TYPE_NUM. ' . $type . ' was given.'); + } + return self::$fieldNames[$type]; + } + + /** + * Convenience method which changes table.column to alias.column. + * + * Using this method you can maintain SQL abstraction while using column aliases. + * + * $c->addAlias("alias1", TablePeer::TABLE_NAME); + * $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN); + * + * @param string $alias The alias for the current table. + * @param string $column The column name for current table. (i.e. PluginsRegistryPeer::COLUMN_NAME). + * @return string + */ + public static function alias($alias, $column) + { + return str_replace(PluginsRegistryPeer::TABLE_NAME.'.', $alias.'.', $column); + } + + /** + * Add all the columns needed to create a new object. + * + * Note: any columns that were marked with lazyLoad="true" in the + * XML schema will not be added to the select list and only loaded + * on demand. + * + * @param criteria object containing the columns to add. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function addSelectColumns(Criteria $criteria) + { + + $criteria->addSelectColumn(PluginsRegistryPeer::ID); + + $criteria->addSelectColumn(PluginsRegistryPeer::PR_UID); + + $criteria->addSelectColumn(PluginsRegistryPeer::PLUGIN_NAMESPACE); + + $criteria->addSelectColumn(PluginsRegistryPeer::PLUGIN_DESCRIPTION); + + $criteria->addSelectColumn(PluginsRegistryPeer::CLASS_NAME); + + $criteria->addSelectColumn(PluginsRegistryPeer::FRIENDLY_NAME); + + $criteria->addSelectColumn(PluginsRegistryPeer::FILE_NAME); + + $criteria->addSelectColumn(PluginsRegistryPeer::PLUGIN_FOLDER); + + $criteria->addSelectColumn(PluginsRegistryPeer::PLUGIN_VERSION); + + $criteria->addSelectColumn(PluginsRegistryPeer::PLUGIN_ENABLE); + + $criteria->addSelectColumn(PluginsRegistryPeer::PLUGIN_PRIVATE); + + $criteria->addSelectColumn(PluginsRegistryPeer::PLUGIN_MENUS); + + $criteria->addSelectColumn(PluginsRegistryPeer::PLUGIN_FOLDERS); + + $criteria->addSelectColumn(PluginsRegistryPeer::PLUGIN_TRIGGERS); + + $criteria->addSelectColumn(PluginsRegistryPeer::PLUGIN_PM_FUNCTIONS); + + $criteria->addSelectColumn(PluginsRegistryPeer::PLUGIN_REDIRECT_LOGIN); + + $criteria->addSelectColumn(PluginsRegistryPeer::PLUGIN_STEPS); + + $criteria->addSelectColumn(PluginsRegistryPeer::PLUGIN_CSS); + + $criteria->addSelectColumn(PluginsRegistryPeer::PLUGIN_JS); + + $criteria->addSelectColumn(PluginsRegistryPeer::PLUGIN_REST_SERVICE); + + $criteria->addSelectColumn(PluginsRegistryPeer::PLUGIN_ATTRIBUTES); + + } + + const COUNT = 'COUNT(PLUGINS_REGISTRY.PR_UID)'; + const COUNT_DISTINCT = 'COUNT(DISTINCT PLUGINS_REGISTRY.PR_UID)'; + + /** + * Returns the number of rows matching criteria. + * + * @param Criteria $criteria + * @param boolean $distinct Whether to select only distinct columns (You can also set DISTINCT modifier in Criteria). + * @param Connection $con + * @return int Number of matching rows. + */ + public static function doCount(Criteria $criteria, $distinct = false, $con = null) + { + // we're going to modify criteria, so copy it first + $criteria = clone $criteria; + + // clear out anything that might confuse the ORDER BY clause + $criteria->clearSelectColumns()->clearOrderByColumns(); + if ($distinct || in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) { + $criteria->addSelectColumn(PluginsRegistryPeer::COUNT_DISTINCT); + } else { + $criteria->addSelectColumn(PluginsRegistryPeer::COUNT); + } + + // just in case we're grouping: add those columns to the select statement + foreach ($criteria->getGroupByColumns() as $column) { + $criteria->addSelectColumn($column); + } + + $rs = PluginsRegistryPeer::doSelectRS($criteria, $con); + if ($rs->next()) { + return $rs->getInt(1); + } else { + // no rows returned; we infer that means 0 matches. + return 0; + } + } + /** + * Method to select one object from the DB. + * + * @param Criteria $criteria object used to create the SELECT statement. + * @param Connection $con + * @return PluginsRegistry + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doSelectOne(Criteria $criteria, $con = null) + { + $critcopy = clone $criteria; + $critcopy->setLimit(1); + $objects = PluginsRegistryPeer::doSelect($critcopy, $con); + if ($objects) { + return $objects[0]; + } + return null; + } + /** + * Method to do selects. + * + * @param Criteria $criteria The Criteria object used to build the SELECT statement. + * @param Connection $con + * @return array Array of selected Objects + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doSelect(Criteria $criteria, $con = null) + { + return PluginsRegistryPeer::populateObjects(PluginsRegistryPeer::doSelectRS($criteria, $con)); + } + /** + * Prepares the Criteria object and uses the parent doSelect() + * method to get a ResultSet. + * + * Use this method directly if you want to just get the resultset + * (instead of an array of objects). + * + * @param Criteria $criteria The Criteria object used to build the SELECT statement. + * @param Connection $con the connection to use + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + * @return ResultSet The resultset object with numerically-indexed fields. + * @see BasePeer::doSelect() + */ + public static function doSelectRS(Criteria $criteria, $con = null) + { + if ($con === null) { + $con = Propel::getConnection(self::DATABASE_NAME); + } + + if (!$criteria->getSelectColumns()) { + $criteria = clone $criteria; + PluginsRegistryPeer::addSelectColumns($criteria); + } + + // Set the correct dbName + $criteria->setDbName(self::DATABASE_NAME); + + // BasePeer returns a Creole ResultSet, set to return + // rows indexed numerically. + return BasePeer::doSelect($criteria, $con); + } + /** + * The returned array will contain objects of the default type or + * objects that inherit from the default. + * + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function populateObjects(ResultSet $rs) + { + $results = array(); + + // set the class once to avoid overhead in the loop + $cls = PluginsRegistryPeer::getOMClass(); + $cls = Propel::import($cls); + // populate the object(s) + while ($rs->next()) { + + $obj = new $cls(); + $obj->hydrate($rs); + $results[] = $obj; + + } + return $results; + } + /** + * Returns the TableMap related to this peer. + * This method is not needed for general use but a specific application could have a need. + * @return TableMap + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function getTableMap() + { + return Propel::getDatabaseMap(self::DATABASE_NAME)->getTable(self::TABLE_NAME); + } + + /** + * The class that the Peer will make instances of. + * + * This uses a dot-path notation which is tranalted into a path + * relative to a location on the PHP include_path. + * (e.g. path.to.MyClass -> 'path/to/MyClass.php') + * + * @return string path.to.ClassName + */ + public static function getOMClass() + { + return PluginsRegistryPeer::CLASS_DEFAULT; + } + + /** + * Method perform an INSERT on the database, given a PluginsRegistry or Criteria object. + * + * @param mixed $values Criteria or PluginsRegistry object containing data that is used to create the INSERT statement. + * @param Connection $con the connection to use + * @return mixed The new primary key. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doInsert($values, $con = null) + { + if ($con === null) { + $con = Propel::getConnection(self::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + $criteria = clone $values; // rename for clarity + } else { + $criteria = $values->buildCriteria(); // build Criteria from PluginsRegistry object + } + + + // Set the correct dbName + $criteria->setDbName(self::DATABASE_NAME); + + try { + // use transaction because $criteria could contain info + // for more than one table (I guess, conceivably) + $con->begin(); + $pk = BasePeer::doInsert($criteria, $con); + $con->commit(); + } catch (PropelException $e) { + $con->rollback(); + throw $e; + } + + return $pk; + } + + /** + * Method perform an UPDATE on the database, given a PluginsRegistry or Criteria object. + * + * @param mixed $values Criteria or PluginsRegistry object containing data create the UPDATE statement. + * @param Connection $con The connection to use (specify Connection exert more control over transactions). + * @return int The number of affected rows (if supported by underlying database driver). + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doUpdate($values, $con = null) + { + if ($con === null) { + $con = Propel::getConnection(self::DATABASE_NAME); + } + + $selectCriteria = new Criteria(self::DATABASE_NAME); + + if ($values instanceof Criteria) { + $criteria = clone $values; // rename for clarity + + $comparison = $criteria->getComparison(PluginsRegistryPeer::PR_UID); + $selectCriteria->add(PluginsRegistryPeer::PR_UID, $criteria->remove(PluginsRegistryPeer::PR_UID), $comparison); + + } else { + $criteria = $values->buildCriteria(); // gets full criteria + $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s) + } + + // set the correct dbName + $criteria->setDbName(self::DATABASE_NAME); + + return BasePeer::doUpdate($selectCriteria, $criteria, $con); + } + + /** + * Method to DELETE all rows from the PLUGINS_REGISTRY table. + * + * @return int The number of affected rows (if supported by underlying database driver). + */ + public static function doDeleteAll($con = null) + { + if ($con === null) { + $con = Propel::getConnection(self::DATABASE_NAME); + } + $affectedRows = 0; // initialize var to track total num of affected rows + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->begin(); + $affectedRows += BasePeer::doDeleteAll(PluginsRegistryPeer::TABLE_NAME, $con); + $con->commit(); + return $affectedRows; + } catch (PropelException $e) { + $con->rollback(); + throw $e; + } + } + + /** + * Method perform a DELETE on the database, given a PluginsRegistry or Criteria object OR a primary key value. + * + * @param mixed $values Criteria or PluginsRegistry object or primary key or array of primary keys + * which is used to create the DELETE statement + * @param Connection $con the connection to use + * @return int The number of affected rows (if supported by underlying database driver). + * This includes CASCADE-related rows + * if supported by native driver or if emulated using Propel. + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function doDelete($values, $con = null) + { + if ($con === null) { + $con = Propel::getConnection(PluginsRegistryPeer::DATABASE_NAME); + } + + if ($values instanceof Criteria) { + $criteria = clone $values; // rename for clarity + } elseif ($values instanceof PluginsRegistry) { + + $criteria = $values->buildPkeyCriteria(); + } else { + // it must be the primary key + $criteria = new Criteria(self::DATABASE_NAME); + $criteria->add(PluginsRegistryPeer::PR_UID, (array) $values, Criteria::IN); + } + + // Set the correct dbName + $criteria->setDbName(self::DATABASE_NAME); + + $affectedRows = 0; // initialize var to track total num of affected rows + + try { + // use transaction because $criteria could contain info + // for more than one table or we could emulating ON DELETE CASCADE, etc. + $con->begin(); + + $affectedRows += BasePeer::doDelete($criteria, $con); + $con->commit(); + return $affectedRows; + } catch (PropelException $e) { + $con->rollback(); + throw $e; + } + } + + /** + * Validates all modified columns of given PluginsRegistry object. + * If parameter $columns is either a single column name or an array of column names + * than only those columns are validated. + * + * NOTICE: This does not apply to primary or foreign keys for now. + * + * @param PluginsRegistry $obj The object to validate. + * @param mixed $cols Column name or array of column names. + * + * @return mixed TRUE if all columns are valid or the error message of the first invalid column. + */ + public static function doValidate(PluginsRegistry $obj, $cols = null) + { + $columns = array(); + + if ($cols) { + $dbMap = Propel::getDatabaseMap(PluginsRegistryPeer::DATABASE_NAME); + $tableMap = $dbMap->getTable(PluginsRegistryPeer::TABLE_NAME); + + if (! is_array($cols)) { + $cols = array($cols); + } + + foreach ($cols as $colName) { + if ($tableMap->containsColumn($colName)) { + $get = 'get' . $tableMap->getColumn($colName)->getPhpName(); + $columns[$colName] = $obj->$get(); + } + } + } else { + + } + + return BasePeer::doValidate(PluginsRegistryPeer::DATABASE_NAME, PluginsRegistryPeer::TABLE_NAME, $columns); + } + + /** + * Retrieve a single object by pkey. + * + * @param mixed $pk the primary key. + * @param Connection $con the connection to use + * @return PluginsRegistry + */ + public static function retrieveByPK($pk, $con = null) + { + if ($con === null) { + $con = Propel::getConnection(self::DATABASE_NAME); + } + + $criteria = new Criteria(PluginsRegistryPeer::DATABASE_NAME); + + $criteria->add(PluginsRegistryPeer::PR_UID, $pk); + + + $v = PluginsRegistryPeer::doSelect($criteria, $con); + + return !empty($v) > 0 ? $v[0] : null; + } + + /** + * Retrieve multiple objects by pkey. + * + * @param array $pks List of primary keys + * @param Connection $con the connection to use + * @throws PropelException Any exceptions caught during processing will be + * rethrown wrapped into a PropelException. + */ + public static function retrieveByPKs($pks, $con = null) + { + if ($con === null) { + $con = Propel::getConnection(self::DATABASE_NAME); + } + + $objs = null; + if (empty($pks)) { + $objs = array(); + } else { + $criteria = new Criteria(); + $criteria->add(PluginsRegistryPeer::PR_UID, $pks, Criteria::IN); + $objs = PluginsRegistryPeer::doSelect($criteria, $con); + } + return $objs; + } +} + + +// static code to register the map builder for this Peer with the main Propel class +if (Propel::isInit()) { + // the MapBuilder classes register themselves with Propel during initialization + // so we need to load them here. + try { + BasePluginsRegistryPeer::getMapBuilder(); + } catch (Exception $e) { + Propel::log('Could not initialize Peer: ' . $e->getMessage(), Propel::LOG_ERR); + } +} else { + // even if Propel is not yet initialized, the map builder class can be registered + // now and then it will be loaded when Propel initializes. + require_once 'classes/model/map/PluginsRegistryMapBuilder.php'; + Propel::registerMapBuilder('classes.model.map.PluginsRegistryMapBuilder'); +} + diff --git a/workflow/engine/config/schema.xml b/workflow/engine/config/schema.xml index 8fde24211..758b21bb1 100644 --- a/workflow/engine/config/schema.xml +++ b/workflow/engine/config/schema.xml @@ -5615,4 +5615,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/workflow/engine/data/mysql/schema.sql b/workflow/engine/data/mysql/schema.sql index 0c0898e37..adb0a9d44 100644 --- a/workflow/engine/data/mysql/schema.sql +++ b/workflow/engine/data/mysql/schema.sql @@ -3133,5 +3133,38 @@ CREATE TABLE `NOTIFICATION_QUEUE` PRIMARY KEY (`NOT_UID`), KEY `indexNotStatus`(`NOT_STATUS`) )ENGINE=InnoDB ; +#----------------------------------------------------------------------------- +#-- PLUGINS_REGISTRY +#----------------------------------------------------------------------------- + +DROP TABLE IF EXISTS `PLUGINS_REGISTRY`; + + +CREATE TABLE `PLUGINS_REGISTRY` +( + `ID` INTEGER NOT NULL AUTO_INCREMENT, + `PR_UID` VARCHAR(32) default '' NOT NULL, + `PLUGIN_NAMESPACE` VARCHAR(100) NOT NULL, + `PLUGIN_DESCRIPTION` VARCHAR(200) default '', + `CLASS_NAME` VARCHAR(100) NOT NULL, + `FRIENDLY_NAME` VARCHAR(150) default '', + `FILE_NAME` VARCHAR(250) default '' NOT NULL, + `PLUGIN_FOLDER` VARCHAR(100) default '' NOT NULL, + `PLUGIN_VERSION` VARCHAR(50) default '', + `PLUGIN_ENABLE` INTEGER default 0, + `PLUGIN_PRIVATE` INTEGER default 0, + `PLUGIN_MENUS` MEDIUMTEXT, + `PLUGIN_FOLDERS` MEDIUMTEXT, + `PLUGIN_TRIGGERS` MEDIUMTEXT, + `PLUGIN_PM_FUNCTIONS` MEDIUMTEXT, + `PLUGIN_REDIRECT_LOGIN` MEDIUMTEXT, + `PLUGIN_STEPS` MEDIUMTEXT, + `PLUGIN_CSS` MEDIUMTEXT, + `PLUGIN_JS` MEDIUMTEXT, + `PLUGIN_REST_SERVICE` MEDIUMTEXT, + `PLUGIN_ATTRIBUTES` MEDIUMTEXT, + PRIMARY KEY (`PR_UID`), + UNIQUE KEY `INDEX_PLUGINS_REGISTRY_ID` (`ID`) +)ENGINE=InnoDB ; # This restores the fkey checks, after having unset them earlier SET FOREIGN_KEY_CHECKS = 1; diff --git a/workflow/engine/methods/enterprise/enterprise.php b/workflow/engine/methods/enterprise/enterprise.php index e859b3a9f..e44441d77 100644 --- a/workflow/engine/methods/enterprise/enterprise.php +++ b/workflow/engine/methods/enterprise/enterprise.php @@ -117,11 +117,11 @@ class enterprisePlugin extends PMPlugin public function setup() { - if (!file_exists(PATH_DATA_SITE . "plugin.singleton")) { + if (!PluginsRegistryPeer::retrieveByPK(md5('enterprise'))) { $pluginRegistry = &PMPluginRegistry::getSingleton(); $pluginDetail = $pluginRegistry->getPluginDetails("enterprise.php"); $pluginRegistry->enablePlugin($pluginDetail->sNamespace); - file_put_contents(PATH_DATA_SITE . "plugin.singleton", $pluginRegistry->serializeInstance()); + $pluginRegistry->pluginAdapter->savePlugin($pluginDetail->sNamespace, $pluginRegistry); } } diff --git a/workflow/engine/methods/login/licenseUpdate.php b/workflow/engine/methods/login/licenseUpdate.php index 68007ef7e..7d0027dd9 100644 --- a/workflow/engine/methods/login/licenseUpdate.php +++ b/workflow/engine/methods/login/licenseUpdate.php @@ -36,36 +36,6 @@ if ($aux['extension'] != 'dat') { BasePeer::doUpdate($oCriteriaSelect, $oCriteriaUpdate, $cnn); - //plugin.singleton //are all the plugins that are enabled in the SYS_SYS - $pluginRegistry = &PMPluginRegistry::getSingleton(); - - $arrayAddon = array(); - - //ee //all plugins enterprise installed in /processmaker/workflow/engine/plugins (no matter if they are enabled/disabled) - if (file_exists(PATH_DATA_SITE . "ee")) { - $arrayAddon = unserialize(trim(file_get_contents(PATH_DATA_SITE . "ee"))); - } - - foreach ($arrayAddon as $addon) { - $sFileName = substr($addon["sFilename"], 0, strpos($addon["sFilename"], "-")); - - if (file_exists(PATH_PLUGINS . $sFileName . ".php")) { - $addonDetails = $pluginRegistry->getPluginDetails($sFileName . ".php"); - $enabled = 0; - - if ($addonDetails) { - $enabled = ($addonDetails->enabled)? 1 : 0; - } - - if ($enabled == 1 && !in_array($sFileName, $licenseManager->features)) { - require_once (PATH_PLUGINS . $sFileName . ".php"); - - $pluginRegistry->disablePlugin($sFileName); - } - } - } - - file_put_contents(PATH_DATA_SITE . "plugin.singleton", $pluginRegistry->serializeInstance()); G::SendTemporalMessage('ID_NLIC', 'info'); } else { G::SendTemporalMessage('ID_WARNING_ENTERPRISE_LICENSE_MSG', 'warning'); diff --git a/workflow/engine/methods/setup/pluginsChange.php b/workflow/engine/methods/setup/pluginsChange.php index 281a3b13c..9f7059969 100644 --- a/workflow/engine/methods/setup/pluginsChange.php +++ b/workflow/engine/methods/setup/pluginsChange.php @@ -32,18 +32,17 @@ $filter = new InputFilter(); $path = PATH_PLUGINS . $pluginFile; $path = $filter->validateInput($path, 'path'); -$oPluginRegistry = & PMPluginRegistry::getSingleton(); - -if ($handle = opendir( PATH_PLUGINS )) { - while (false !== ($file = readdir( $handle ))) { - if (strpos( $file, '.php', 1 ) && $file == $pluginFile) { +$oPluginRegistry =& ProcessMaker\Plugins\PluginsRegistry::loadSingleton(); +if ($handle = opendir(PATH_PLUGINS)) { + while (false !== ($file = readdir($handle))) { + if (strpos($file, '.php', 1) && $file == $pluginFile) { if ($pluginStatus == '1') { //print "change to disable"; - $details = $oPluginRegistry->getPluginDetails( $pluginFile ); - $oPluginRegistry->disablePlugin( $details->sNamespace ); - $size = file_put_contents( PATH_DATA_SITE . 'plugin.singleton', $oPluginRegistry->serializeInstance() ); - G::auditLog("DisablePlugin", "Plugin Name: ".$details->sNamespace); + $details = $oPluginRegistry->getPluginDetails($pluginFile); + $oPluginRegistry->disablePlugin($details->sNamespace); + $oPluginRegistry->pluginAdapter->savePlugin($details->sNamespace, $oPluginRegistry); + G::auditLog("DisablePlugin", "Plugin Name: " . $details->sNamespace); //print "size saved : $size
"; } else { $pluginName = str_replace(".php", "", $pluginFile); @@ -51,17 +50,21 @@ if ($handle = opendir( PATH_PLUGINS )) { if (is_file(PATH_PLUGINS . $pluginName . ".php") && is_dir(PATH_PLUGINS . $pluginName)) { /*----------------------------------********---------------------------------*/ if (!$oPluginRegistry->isEnterprisePlugin($pluginName) && - PMLicensedFeatures::getSingleton()->verifyfeature('B0oWlBLY3hHdWY0YUNpZEtFQm5CeTJhQlIwN3IxMEkwaG4=') + PMLicensedFeatures::getSingleton() + ->verifyfeature('B0oWlBLY3hHdWY0YUNpZEtFQm5CeTJhQlIwN3IxMEkwaG4=') ) { //Check disabled code $cs = new CodeScanner(SYS_SYS); - $arrayFoundDisabledCode = array_merge($cs->checkDisabledCode("FILE", PATH_PLUGINS . $pluginName . ".php"), $cs->checkDisabledCode("PATH", PATH_PLUGINS . $pluginName)); + $arrayFoundDisabledCode = array_merge( + $cs->checkDisabledCode("FILE", PATH_PLUGINS . $pluginName . ".php"), + $cs->checkDisabledCode("PATH", PATH_PLUGINS . $pluginName) + ); if (!empty($arrayFoundDisabledCode)) { $response = array(); - $response["status"] = "DISABLED-CODE"; + $response["status"] = "DISABLED-CODE"; $response["message"] = G::LoadTranslation("ID_DISABLED_CODE_PLUGIN"); echo G::json_encode($response); @@ -75,16 +78,16 @@ if ($handle = opendir( PATH_PLUGINS )) { $details = $oPluginRegistry->getPluginDetails($pluginFile); $oPluginRegistry->enablePlugin($details->sNamespace); $oPluginRegistry->setupPlugins(); //get and setup enabled plugins - $size = file_put_contents(PATH_DATA_SITE . "plugin.singleton", $oPluginRegistry->serializeInstance()); + $oPluginRegistry->pluginAdapter->savePlugin($details->sNamespace, $oPluginRegistry); G::auditLog("EnablePlugin", "Plugin Name: " . $details->sNamespace); //print "size saved : $size
"; } } } } - closedir( $handle ); + closedir($handle); } - //$oPluginRegistry->showArrays(); - //G::Header('location: pluginsList'); +//$oPluginRegistry->showArrays(); +//G::Header('location: pluginsList'); diff --git a/workflow/engine/methods/setup/pluginsImportFile.php b/workflow/engine/methods/setup/pluginsImportFile.php index 9822338dc..70ee4ea9a 100644 --- a/workflow/engine/methods/setup/pluginsImportFile.php +++ b/workflow/engine/methods/setup/pluginsImportFile.php @@ -222,7 +222,7 @@ try { file_put_contents($pathFileFlag, 'New Enterprise'); } - $oPluginRegistry = & PMPluginRegistry::getSingleton(); + $oPluginRegistry =& ProcessMaker\Plugins\PluginsRegistry::loadSingleton(); $pluginFile = $sClassName . '.php'; if ($bMainFile && $bClassFile) { @@ -323,14 +323,13 @@ try { require_once (PATH_PLUGINS . $pluginFile); $oPluginRegistry->registerPlugin( $sClassName, PATH_PLUGINS . $sClassName . ".php" ); - $size = file_put_contents( PATH_DATA_SITE . "plugin.singleton", $oPluginRegistry->serializeInstance() ); $details = $oPluginRegistry->getPluginDetails( $pluginFile ); $oPluginRegistry->installPlugin( $details->sNamespace ); $oPluginRegistry->setupPlugins(); //get and setup enabled plugins - $size = file_put_contents( PATH_DATA_SITE . "plugin.singleton", $oPluginRegistry->serializeInstance() ); + $oPluginRegistry->pluginAdapter->savePlugin($details->sNamespace , $oPluginRegistry); $response = $oPluginRegistry->verifyTranslation( $details->sNamespace); G::auditLog("InstallPlugin", "Plugin Name: ".$details->sNamespace ); diff --git a/workflow/engine/methods/setup/pluginsRemove.php b/workflow/engine/methods/setup/pluginsRemove.php index 3f049586a..7e6722857 100644 --- a/workflow/engine/methods/setup/pluginsRemove.php +++ b/workflow/engine/methods/setup/pluginsRemove.php @@ -42,13 +42,9 @@ $filter = new InputFilter(); $pluginName = $_REQUEST['pluginUid']; $pluginName = $filter->xssFilterHard($pluginName); -if (file_exists( PATH_PLUGINS . $pluginName . '.php' )) { - $pluginRegistry = &PMPluginRegistry::getSingleton(); +$pluginRegistry =& ProcessMaker\Plugins\PluginsRegistry::loadSingleton(); +$pluginRegistry->uninstallPlugin($pluginName); - $pluginRegistry->uninstallPlugin( $pluginName ); - $path = $filter->validateInput(PATH_DATA_SITE . 'plugin.singleton', 'path'); - $pluginRegistry->unSerializeInstance( file_get_contents( $path ) ); -} G::auditLog('RemovePlugin','Plugin Name: '.$pluginName); echo $pluginName . ' ' . nl2br( $filter->xssFilterHard(G::LoadTranslation( 'ID_MSG_REMOVE_PLUGIN_SUCCESS' )) ); diff --git a/workflow/engine/src/ProcessMaker/Plugins/Adapters/PluginAdapter.php b/workflow/engine/src/ProcessMaker/Plugins/Adapters/PluginAdapter.php new file mode 100644 index 000000000..250cc313f --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Plugins/Adapters/PluginAdapter.php @@ -0,0 +1,249 @@ + 'PLUGIN_NAMESPACE', + 'sDescription' => 'PLUGIN_DESCRIPTION', + 'sClassName' => 'CLASS_NAME', + 'sFriendlyName' => 'FRIENDLY_NAME', + 'sFilename' => 'FILE_NAME', + 'sPluginFolder' => 'PLUGIN_FOLDER', + 'iVersion' => 'PLUGIN_VERSION', + 'enabled' => 'PLUGIN_ENABLE', + 'bPrivate' => 'PLUGIN_PRIVATE', + '_aMenus' => 'PLUGIN_MENUS', + '_aFolders' => 'PLUGIN_FOLDERS', + '_aTriggers' => 'PLUGIN_TRIGGERS', + '_aPmFunctions' => 'PLUGIN_PM_FUNCTIONS', + '_aRedirectLogin' => 'PLUGIN_REDIRECT_LOGIN', + '_aSteps' => 'PLUGIN_STEPS', + '_aCSSStyleSheets' => 'PLUGIN_CSS', + '_aJavascripts' => 'PLUGIN_JS', + '_restServices' => 'PLUGIN_REST_SERVICE', + ]; + + /** + * @param PMPluginRegistry|PluginsRegistry $pluginsSingleton + */ + public function save($pluginsSingleton) + { + $this->pluginRegistry = \G::json_decode(\G::json_encode($pluginsSingleton->iterateVisible())); + foreach ($this->pluginRegistry->_aPluginDetails as $nameSpace => $value) { + $this->savePluginOld($nameSpace, $this->pluginRegistry); + } + } + + public function savePluginOld($sNamespace, $pluginRegistry) + { + $structurePlugin = $this->getOldPluginStructure($sNamespace, $pluginRegistry); + $plugin = $this->diffFieldTable($structurePlugin); + if ($plugin['PLUGIN_NAMESPACE']) { + $fieldPlugin = \PluginsRegistry::loadOrCreateIfNotExists(md5($plugin['PLUGIN_NAMESPACE']), $plugin); + \PluginsRegistry::update($fieldPlugin); + } + } + + public function savePlugin($sNamespace, $pluginRegistry) + { + $structurePlugin = $this->getPluginStructure($sNamespace, $pluginRegistry); + $plugin = $this->diffFieldTable($structurePlugin); + if ($plugin['PLUGIN_NAMESPACE']) { + $fieldPlugin = \PluginsRegistry::loadOrCreateIfNotExists(md5($plugin['PLUGIN_NAMESPACE']), $plugin); + \PluginsRegistry::update($fieldPlugin); + } + } + + /** + * @param string $nameSpace + * @param object $pluginsRegistry + * @return array + */ + public function getOldPluginStructure($nameSpace, $pluginsRegistry) + { + $pluginRegistry = clone $pluginsRegistry; + $structurePlugins = $pluginRegistry->_aPluginDetails->{$nameSpace}; + unset($pluginRegistry->_aPluginDetails); + $aPlugins = isset($pluginRegistry->_aPlugins->{$nameSpace}) ? $pluginRegistry->_aPlugins->{$nameSpace} : []; + $structurePlugins = array_merge((array)$structurePlugins, (array)$aPlugins); + unset($pluginRegistry->_aPlugins); + foreach ($pluginRegistry as $propertyName => $propertyValue) { + foreach ($propertyValue as $key => $plugin) { + if (is_object($plugin) && + ( + (property_exists($plugin, 'sNamespace') && $plugin->sNamespace == $nameSpace) || + (!is_int($key) && $key == $nameSpace) + ) + ) { + $structurePlugins[$propertyName][] = $plugin; + } elseif (is_object($plugin) && + property_exists($plugin, 'pluginName') && + $plugin->pluginName == $nameSpace + ) { + $structurePlugins[$propertyName][] = $plugin; + } elseif (is_string($plugin) && $plugin == $nameSpace) { + $structurePlugins[$propertyName][] = $plugin; + } + } + } + return $structurePlugins; + } + + /** + * @param string $nameSpace + * @param object $pluginsRegistry + * @return array + */ + public function getPluginStructure($nameSpace, $pluginsRegistry) + { + $pluginRegistry = clone $pluginsRegistry; + $structurePlugins = $pluginRegistry->_aPluginDetails[$nameSpace]; + unset($pluginRegistry->_aPluginDetails); + $aPlugins = isset($pluginRegistry->_aPlugins[$nameSpace]) ? $pluginRegistry->_aPlugins[$nameSpace] : []; + $structurePlugins = array_merge((array)$structurePlugins, get_object_vars($aPlugins)); + unset($pluginRegistry->_aPlugins); + foreach ($pluginRegistry as $propertyName => $propertyValue) { + foreach ($propertyValue as $key => $plugin) { + if (is_object($plugin) && + ( + (property_exists($plugin, 'sNamespace') && $plugin->sNamespace == $nameSpace) || + (!is_int($key) && $key == $nameSpace) + ) + ) { + $structurePlugins[$propertyName][] = $plugin; + } elseif (is_object($plugin) && + property_exists($plugin, 'pluginName') && + $plugin->pluginName == $nameSpace + ) { + $structurePlugins[$propertyName][] = $plugin; + } elseif (is_string($plugin) && $plugin == $nameSpace) { + $structurePlugins[$propertyName][] = $plugin; + } + } + } + return $structurePlugins; + } + + /** + * @param $plugin + * @return array + */ + public function diffFieldTable($plugin) + { + $fields = []; + $map = \PluginsRegistryPeer::getTableMap(); + $columns = $map->getColumns(); + $attributes = array_diff_key((array)$plugin, $this->aliasNameAttributes); + $fieldsTMP = array_intersect_key((array)$plugin, $this->aliasNameAttributes); + foreach ($this->aliasNameAttributes as $name => $nameTable) { + if (array_key_exists($name, $fieldsTMP)) { + switch (gettype($fieldsTMP[$name])) { + case 'string': + $valueField = array_key_exists($name, $fieldsTMP) ? $fieldsTMP[$name] : ''; + break; + case 'array': + $valueField = array_key_exists($name, $fieldsTMP) ? $fieldsTMP[$name] : []; + $valueField = \G::json_encode($valueField); + break; + case 'integer': + $valueField = array_key_exists($name, $fieldsTMP) ? $fieldsTMP[$name] : 0; + break; + case 'boolean': + $valueField = array_key_exists($name, $fieldsTMP) ? ($fieldsTMP[$name] ? true : false ): false; + break; + case 'NULL': + default: + $valueField = array_key_exists($name, $fieldsTMP) ? + $fieldsTMP[$name] : + $this->getDefaultValueType($columns[$nameTable]->getType()); + break; + } + } else { + $valueField = $this->getDefaultValueType($columns[$nameTable]->getType()); + } + $fields[$nameTable] = $valueField; + } + $fields['PLUGIN_ATTRIBUTES'] = \G::json_encode($attributes); + return $fields; + } + + public function getDefaultValueType($var) + { + switch ($var) { + case 'string': + $response = ''; + break; + case 'int': + $response = 0; + break; + case 'boolean': + $response = false; + break; + default: + $response = ''; + break; + } + return $response; + } + + /** + * @param PluginsRegistry $oPlugins + * @return mixed + */ + public function getPluginsDefinition($oPlugins) + { + $oldStructure = $this->convertArrayStructure(); + $oPlugins->setPlugins($oldStructure); + $oPlugins = $this->populateAttributes($oPlugins, $oldStructure); + return $oPlugins; + } + + public function convertArrayStructure() + { + $invertAlias = array_flip($this->aliasNameAttributes); + $plugins = \PluginsRegistry::loadPlugins(); + $pluginsRegistry = []; + foreach ($plugins as $index => $plugin) { + $namePlugin = $plugin['PLUGIN_NAMESPACE']; + $pluginsRegistry[$namePlugin] = new \stdClass(); + array_walk($plugin, function ($value, $key) use ($invertAlias, &$pluginsRegistry, $namePlugin) { + if (array_key_exists($key, $invertAlias)) { + $pluginsRegistry[$namePlugin]->{$invertAlias[$key]} = !is_null($data = \G::json_decode($value)) ? + $data : + (!empty($value) ? $value : []); + } + }); + $moreAttributes = \G::json_decode($plugin['PLUGIN_ATTRIBUTES']); + $pluginsRegistry[$namePlugin] = Plugins::setter(array_merge( + (array)$pluginsRegistry[$namePlugin], + $moreAttributes ? (array)$moreAttributes : [] + )); + } + return $pluginsRegistry; + } + + public function populateAttributes($oPlugins, $structures) + { + foreach ($structures as $namePlugin => $plugin) { + foreach ($plugin as $nameAttribute => $detail) { + if ($detail && + property_exists($oPlugins, $nameAttribute) && + $plugin->_aPluginDetails[$namePlugin]->enabled + ) { + $oPlugins->{$nameAttribute} = array_merge($oPlugins->{$nameAttribute}, $detail); + } + } + } + return $oPlugins; + } +} diff --git a/workflow/engine/src/ProcessMaker/Plugins/Interfaces/CaseSchedulerPlugin.php b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/CaseSchedulerPlugin.php new file mode 100644 index 000000000..3e7538cf4 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/CaseSchedulerPlugin.php @@ -0,0 +1,32 @@ +sNamespace = $sNamespace; + $this->sActionId = $sActionId; + $this->sActionForm = $sActionForm; + $this->sActionSave = $sActionSave; + $this->sActionExecute = $sActionExecute; + $this->sActionGetFields = $sActionGetFields; + } +} diff --git a/workflow/engine/src/ProcessMaker/Plugins/Interfaces/CronFile.php b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/CronFile.php new file mode 100644 index 000000000..24088e963 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/CronFile.php @@ -0,0 +1,20 @@ +namespace = $namespace; + $this->cronFile = $cronFile; + } +} diff --git a/workflow/engine/src/ProcessMaker/Plugins/Interfaces/CssFile.php b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/CssFile.php new file mode 100644 index 000000000..5ce4b9414 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/CssFile.php @@ -0,0 +1,20 @@ +sNamespace = $sNamespace; + $this->sCssFile = $sCssFile; + } +} diff --git a/workflow/engine/src/ProcessMaker/Plugins/Interfaces/DashboardPage.php b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/DashboardPage.php new file mode 100644 index 000000000..26d771f3b --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/DashboardPage.php @@ -0,0 +1,26 @@ +sNamespace = $sNamespace; + $this->sPage = $sPage; + $this->sName = $sName; + $this->sIcon = $sIcon; + } +} diff --git a/workflow/engine/src/ProcessMaker/Plugins/Interfaces/FolderDetail.php b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/FolderDetail.php new file mode 100644 index 000000000..bb5777ea0 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/FolderDetail.php @@ -0,0 +1,23 @@ +sNamespace = $sNamespace; + $this->sFolderId = $sFolderId; + $this->sFolderName = $sFolderName; + } +} diff --git a/workflow/engine/src/ProcessMaker/Plugins/Interfaces/ImportCallBack.php b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/ImportCallBack.php new file mode 100644 index 000000000..5fd8df939 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/ImportCallBack.php @@ -0,0 +1,20 @@ +namespace = $namespace; + $this->callBackFile = $callBackFile; + } +} diff --git a/workflow/engine/src/ProcessMaker/Plugins/Interfaces/MenuDetail.php b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/MenuDetail.php new file mode 100644 index 000000000..44408807f --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/MenuDetail.php @@ -0,0 +1,23 @@ +sNamespace = $sNamespace; + $this->sMenuId = $sMenuId; + $this->sFilename = $sFilename; + } +} diff --git a/workflow/engine/src/ProcessMaker/Plugins/Interfaces/OpenReassignCallback.php b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/OpenReassignCallback.php new file mode 100644 index 000000000..4cd69af67 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/OpenReassignCallback.php @@ -0,0 +1,17 @@ +callBackFile = $callBackFile; + } +} diff --git a/workflow/engine/src/ProcessMaker/Plugins/Interfaces/PluginDetail.php b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/PluginDetail.php new file mode 100644 index 000000000..5e6b59fc6 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/PluginDetail.php @@ -0,0 +1,55 @@ +sNamespace = $sNamespace; + $this->sClassName = $sClassName; + $this->sFriendlyName = $sFriendlyName; + $this->sDescription = $sDescription; + $this->sSetupPage = $sSetupPage; + $this->iVersion = $iVersion; + $this->sFilename = $sFilename; + if ($sPluginFolder == '') { + $this->sPluginFolder = $sNamespace; + } else { + $this->sPluginFolder = $sPluginFolder; + } + } +} diff --git a/workflow/engine/src/ProcessMaker/Plugins/Interfaces/Plugins.php b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/Plugins.php new file mode 100644 index 000000000..5b80f56c2 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/Plugins.php @@ -0,0 +1,83 @@ + $oldValue) { + if (isset($vars[$name])) { + $newObject->{$name} = $vars[$name]; + unset($vars[$name]); + } else { + $newObject->{$name} = $oldValue; + } + } + if ($vars) { + $sClassName = $vars['sClassName']; + $sNamespace = $vars['sNamespace']; + $sFilename = $vars['sFilename']; + $newObjectDetails = new PluginDetail( + $sNamespace, + $sClassName, + $sFilename + ); + if (class_exists($sClassName)) { + $oPlugin = new $sClassName($sNamespace, $sFilename); + } else { + $oPlugin = $newObjectDetails; + } + $newObject->_aPlugins[$sNamespace] = $oPlugin; + $hasDetails = get_object_vars($newObjectDetails); + foreach ($hasDetails as $name => $oldValue) { + if (isset($vars[$name])) { + $newObjectDetails->{$name} = $vars[$name]; + unset($vars[$name]); + } else { + $newObjectDetails->{$name} = $oldValue; + } + } + $newObject->_aPluginDetails[$sNamespace] = $newObjectDetails; + } + return $newObject; + } +} diff --git a/workflow/engine/src/ProcessMaker/Plugins/Interfaces/RedirectDetail.php b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/RedirectDetail.php new file mode 100644 index 000000000..6f802c67d --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/RedirectDetail.php @@ -0,0 +1,23 @@ +sNamespace = $sNamespace; + $this->sRoleCode = $sRoleCode; + $this->sPathMethod = $sPathMethod; + } +} diff --git a/workflow/engine/src/ProcessMaker/Plugins/Interfaces/StepDetail.php b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/StepDetail.php new file mode 100644 index 000000000..bbb138cb9 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/StepDetail.php @@ -0,0 +1,35 @@ +sNamespace = $sNamespace; + $this->sStepId = $sStepId; + $this->sStepName = $sStepName; + $this->sStepTitle = $sStepTitle; + $this->sSetupStepPage = $sSetupStepPage; + } +} diff --git a/workflow/engine/src/ProcessMaker/Plugins/Interfaces/TaskExtendedProperty.php b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/TaskExtendedProperty.php new file mode 100644 index 000000000..b4b86e124 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/TaskExtendedProperty.php @@ -0,0 +1,26 @@ +sNamespace = $sNamespace; + $this->sPage = $sPage; + $this->sName = $sName; + $this->sIcon = $sIcon; + } +} diff --git a/workflow/engine/src/ProcessMaker/Plugins/Interfaces/ToolbarDetail.php b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/ToolbarDetail.php new file mode 100644 index 000000000..e2a267e7d --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/ToolbarDetail.php @@ -0,0 +1,23 @@ +sNamespace = $sNamespace; + $this->sToolbarId = $sToolbarId; + $this->sFilename = $sFilename; + } +} diff --git a/workflow/engine/src/ProcessMaker/Plugins/Interfaces/TriggerDetail.php b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/TriggerDetail.php new file mode 100644 index 000000000..7b06bafda --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Plugins/Interfaces/TriggerDetail.php @@ -0,0 +1,23 @@ +sNamespace = $sNamespace; + $this->sTriggerId = $sTriggerId; + $this->sTriggerName = $sTriggerName; + } +} diff --git a/workflow/engine/src/ProcessMaker/Plugins/PluginsRegistry.php b/workflow/engine/src/ProcessMaker/Plugins/PluginsRegistry.php new file mode 100644 index 000000000..185fe6cac --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Plugins/PluginsRegistry.php @@ -0,0 +1,1764 @@ +Plugins; + } + + /** + * @param array $Plugins + */ + public function setPlugins($Plugins) + { + $this->Plugins = $Plugins; + } + + /** + * PluginRegistry constructor. + */ + public function __construct() + { + $this->pluginAdapter = new PluginAdapter(); + $oPlugins = $this->pluginAdapter->getPluginsDefinition($this); + } + + /** + * Load the singleton instance from a serialized stored file + * + * @return PluginsRegistry|static + * @throws \Exception + */ + public static function loadSingleton() + { + if (self::$instance == null) { + self::$instance = new PluginsRegistry(); + if (!is_object(self::$instance) || get_class(self::$instance) != "ProcessMaker\Plugins\PluginsRegistry") { + throw new \Exception("Can't load main PluginRegistry object."); + } + } + return self::$instance; + } + + /** + * This function is instancing to this class + * param + * + * @return object + * @deprecated + */ + public static function getSingleton() + { + if (self::$instance == null) { + self::$instance = new PluginsRegistry(); + } + return self::$instance; + } + + /** + * Register the plugin in the singleton + * + * @param string $sNamespace + * @param string $sFilename + */ + public function registerPlugin($sNamespace, $sFilename = null) + { + //require_once ($sFilename); + $sClassName = $sNamespace . "plugin"; + $plugin = new $sClassName($sNamespace, $sFilename); + + if (isset($this->_aPluginDetails[$sNamespace])) { + $this->_aPluginDetails[$sNamespace]->iVersion = $plugin->iVersion; + return; + } + + $detail = new PluginDetail( + $sNamespace, + $sClassName, + $sFilename, + $plugin->sFriendlyName, + $plugin->sPluginFolder, + $plugin->sDescription, + $plugin->sSetupPage, + $plugin->iVersion + ); + + if (isset($plugin->aWorkspaces)) { + $detail->aWorkspaces = $plugin->aWorkspaces; + } + + if (isset($plugin->bPrivate)) { + $detail->bPrivate = $plugin->bPrivate; + } + + //if (isset($this->_aPluginDetails[$sNamespace])){ + // $detail->enabled = $this->_aPluginDetails[$sNamespace]->enabled; + //} + + $this->_aPluginDetails[$sNamespace] = $detail; + } + + /** + * get the plugin details, by filename + * + * @param string $sFilename + * @return null + */ + public function getPluginDetails($sFilename) + { + foreach ($this->_aPluginDetails as $key => $row) { + if ($sFilename == baseName($row->sFilename)) { + return $row; + } + } + return null; + } + + /** + * Enable the plugin in the singleton + * + * @param string $sNamespace + * @return bool + * @throws \Exception + */ + public function enablePlugin($sNamespace) + { + if ($currentPlugin = $this->_aPluginDetails[$sNamespace]) { + $this->registerFolder($sNamespace, $sNamespace, $currentPlugin->sPluginFolder); + //register the default directory, later we can have more + $currentPlugin->enabled = true; + /** @var enterprisePlugin $oPlugin */ + if (class_exists($currentPlugin->sClassName)) { + $oPlugin = new $currentPlugin->sClassName( + $currentPlugin->sNamespace, + $currentPlugin->sFilename + ); + } else { + $oPlugin = $currentPlugin; + } + $this->_aPlugins[$currentPlugin->sNamespace] = $oPlugin; + if (method_exists($oPlugin, 'enable')) { + $oPlugin->enable(); + } + + /* + * 1. register /src directory for autoloading + * 2. verify if rest service is enabled + * 3. register rest service directory + */ + $pluginSrcDir = PATH_PLUGINS . $currentPlugin->sNamespace . PATH_SEP . 'src'; + + if (is_dir($pluginSrcDir)) { + //Bootstrap::registerDir($detail->sNamespace.'/src', $pluginSrcDir); + $loader = ClassLoader::getInstance(); + $loader->add($pluginSrcDir); + } + + if (array_key_exists($currentPlugin->sNamespace, $this->_restServiceEnabled) + && $this->_restServiceEnabled[$currentPlugin->sNamespace] == true + ) { + $oPlugin->registerRestService(); + } + return true; + } else { + throw new \Exception("Unable to enable plugin '$sNamespace' (plugin not found)"); + } + } + + /** + * disable the plugin in the singleton + * + * @param string $sNamespace + * @param int $eventPlugin + * @throws \Exception + */ + public function disablePlugin($sNamespace, $eventPlugin = 1) + { + if ($currentPlugin = $this->_aPluginDetails[$sNamespace]) { + //unset($currentPlugin->_aPluginDetails[$sNamespace]); + $currentPlugin->enabled = false; + if ($eventPlugin == 1) { + //$currentPlugin->_aPlugins[$currentPlugin->sNamespace] = $currentPlugin; + // If plugin class exists check if disable method exist, + // otherwise use default plugin details + if (class_exists($currentPlugin->sClassName)) { + $plugin = new $currentPlugin->sClassName( + $currentPlugin->sNamespace, + $currentPlugin->sFilename + ); + } else { + throw new \Exception("Unable to disable plugin '$sNamespace' (plugin not found)"); + } + if (method_exists($plugin, "disable")) { + $plugin->disable(); + } + } + } else { + throw new \Exception("Unable to disable plugin '$sNamespace' (plugin not found)"); + } + } + + /** + * Get status plugin in the singleton + * @param string $name Plugin name + * @return int|string Return a string with status plugin, 0 otherwise + * @throws \Exception + */ + public function getStatusPlugin($name) + { + try { + return (isset($this->_aPluginDetails[$name])) ? + (($this->_aPluginDetails[$name]->enabled) ? "enabled" : "disabled") : + 0; + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Install a plugin archive. + * If pluginName is specified, the archive will + * only be installed if it contains this plugin. + * + * @param $filename + * @param $pluginName + * return bool true if enabled, false otherwise + * @throws \Exception + */ + public function installPluginArchive($filename, $pluginName) + { + \G::LoadThirdParty("pear/Archive", "Tar"); + $tar = new \Archive_Tar($filename); + $files = $tar->listContent(); + $plugins = array(); + $namePlugin = array(); + foreach ($files as $f) { + if (preg_match("/^([\w\.]*).ini$/", $f["filename"], $matches)) { + //if (preg_match( "/^(.*pluginConfig)\.ini$/", $f["filename"], $matches )) { + $plugins[] = $matches[1]; + } + if (preg_match("/^.*($pluginName)\.php$/", $f["filename"], $matches)) { + $namePlugin[] = $matches[1]; + } + } + + if (count($plugins) > 1) { + throw new \Exception("Multiple plugins in one archive are not supported currently"); + } + + //if (isset($pluginName) && !in_array($pluginName, $plugins)) { + if (isset($pluginName) && !in_array($pluginName, $namePlugin)) { + throw new \Exception("Plugin '$pluginName' not found in archive"); + } + + //$pluginName = $plugins[0]; + $pluginFile = "$pluginName.php"; + + $res = $tar->extract(PATH_PLUGINS); + if (!file_exists(PATH_PLUGINS . $pluginFile)) { + throw (new \Exception("File \"$pluginFile\" doesn't exist")); + } +// $filter = new \InputFilter(); + $path = PATH_PLUGINS . $pluginFile; +// $path = $filter->validateInput($path, 'path'); + require_once($path); + /** @var PluginDetail $details */ + $details = $this->getPluginDetails($pluginFile); + + $this->installPlugin($details->sNamespace); +// $this->setupPlugins(); + + $this->enablePlugin($details->sNamespace); + } + + public function uninstallPlugin($sNamespace) + { + $pluginFile = $sNamespace . ".php"; + + if (!file_exists(PATH_PLUGINS . $pluginFile)) { + throw (new \Exception("File \"$pluginFile\" doesn't exist")); + } + + /////// + $path = PATH_PLUGINS . $pluginFile; + $filter = new \InputFilter(); + $path = $filter->validateInput($path, 'path'); + require_once($path); + + foreach ($this->_aPluginDetails as $namespace => $detail) { + if ($namespace == $sNamespace) { + $this->enablePlugin($detail->sNamespace); + $this->disablePlugin($detail->sNamespace); + + /////// + $plugin = new $detail->sClassName($detail->sNamespace, $detail->sFilename); + $this->_aPlugins[$detail->sNamespace] = $plugin; + + if (method_exists($plugin, "uninstall")) { + $plugin->uninstall(); + } + + /////// + $this->pluginAdapter->savePlugin($detail->sNamespace, $this); + /////// + $pluginDir = PATH_PLUGINS . $detail->sPluginFolder; + + if (isset($detail->sFilename) && !empty($detail->sFilename) && file_exists($detail->sFilename)) { + unlink($detail->sFilename); + } + + if (isset($detail->sPluginFolder) && !empty($detail->sPluginFolder) && file_exists($pluginDir)) { + \G::rm_dir($pluginDir); + } + + /////// + $this->uninstallPluginWorkspaces(array($sNamespace)); + /////// + break; + } + } + } + + /** + * @param $arrayPlugin + */ + public function uninstallPluginWorkspaces($arrayPlugin) + { + $workspace = \System::listWorkspaces(); + + foreach ($workspace as $indexWS => $ws) { + $pluginRegistry =& PluginsRegistry::loadSingleton(); + $attributes = $pluginRegistry->getAttributes(); + + foreach ($arrayPlugin as $index => $value) { + if (isset($attributes["_aPluginDetails"][$value])) { + $pluginRegistry->disablePlugin($value, 0); + } + } + + } + } + + /** + * install the plugin + * + * @param string $sNamespace + */ + public function installPlugin($sNamespace) + { + try { + foreach ($this->_aPluginDetails as $namespace => $detail) { + if ($sNamespace == $namespace) { + $oPlugin = new $detail->sClassName($detail->sNamespace, $detail->sFilename); + $this->_aPlugins[$detail->sNamespace] = $oPlugin; + + $this->pluginAdapter->savePlugin($detail->sNamespace, $this); + + $oPlugin->install(); + } + } + } catch (\Exception $e) { + global $G_PUBLISH; + $aMessage['MESSAGE'] = $e->getMessage(); + $G_PUBLISH = new \Publisher(); + $G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', '', $aMessage); + \G::RenderPage('publish'); + die(); + } + } + + /** + * Register a menu in the singleton + * + * @param string $sNamespace + * @param string $sMenuId + * @param string $sFilename + */ + public function registerMenu($sNamespace, $sMenuId, $sFilename) + { + $found = false; + foreach ($this->_aMenus as $row => $detail) { + if ($sMenuId == $detail->sMenuId && $sNamespace == $detail->sNamespace) { + $found = true; + } + } + if (!$found) { + $menuDetail = new MenuDetail($sNamespace, $sMenuId, $sFilename); + $this->_aMenus[] = $menuDetail; + } + } + + /** + * Register a dashlet class in the singleton + * + * @param string $namespace + */ + public function registerDashlets($namespace) + { + $found = false; + foreach ($this->_aDashlets as $row => $detail) { + if ($namespace == $detail) { + $found = true; + } + } + if (!$found) { + $this->_aDashlets[] = $namespace; + } + } + + /** + * Register a stylesheet in the singleton + * + * @param string $sNamespace + * @param string $sCssFile + */ + public function registerCss($sNamespace, $sCssFile) + { + $found = false; + foreach ($this->_aCSSStyleSheets as $row => $detail) { + if ($sCssFile == $detail->sCssFile && $sNamespace == $detail->sNamespace) { + $detail->sCssFile = $sCssFile; + $found = true; + } + } + if (!$found) { + $cssFile = new CssFile($sNamespace, $sCssFile); + $this->_aCSSStyleSheets[] = $cssFile; + } + } + + /** + * return all css + * + * @return array + */ + public function getRegisteredCss() + { + return $this->_aCSSStyleSheets; + } + + /** + * Register a plugin javascript to run with core js script at same runtime + * + * @param string $sNamespace + * @param string $sCoreJsFile + * @param array /string $pluginJsFile + * @return mixed + * @throws \Exception + */ + public function registerJavascript($sNamespace, $sCoreJsFile, $pluginJsFile) + { + foreach ($this->_aJavascripts as $i => $js) { + if ($sCoreJsFile == $js->sCoreJsFile && $sNamespace == $js->sNamespace) { + if (is_string($pluginJsFile)) { + if (!in_array($pluginJsFile, $this->_aJavascripts[$i]->pluginJsFile)) { + $this->_aJavascripts[$i]->pluginJsFile[] = $pluginJsFile; + } + } elseif (is_array($pluginJsFile)) { + $this->_aJavascripts[$i]->pluginJsFile = array_unique( + array_merge($pluginJsFile, $this->_aJavascripts[$i]->pluginJsFile) + ); + } else { + throw new \Exception( + 'Invalid third param, $pluginJsFile should be a string or array - ' . + gettype($pluginJsFile) . + ' given.' + ); + } + return $this->_aJavascripts[$i]; + } + } + + $js = new \stdClass(); + $js->sNamespace = $sNamespace; + $js->sCoreJsFile = $sCoreJsFile; + $js->pluginJsFile = array(); + + if (is_string($pluginJsFile)) { + $js->pluginJsFile[] = $pluginJsFile; + } elseif (is_array($pluginJsFile)) { + $js->pluginJsFile = array_merge($js->pluginJsFile, $pluginJsFile); + } else { + throw new \Exception( + 'Invalid third param, $pluginJsFile should be a string or array - ' . + gettype($pluginJsFile) . + ' given.' + ); + } + + $this->_aJavascripts[] = $js; + } + + /** + * return all plugin javascripts + * + * @return array + */ + public function getRegisteredJavascript() + { + return $this->_aJavascripts; + } + + /** + * return all plugin javascripts given a core js file, from all namespaces or a single namespace + * + * @param string $sCoreJsFile + * @param string $sNamespace + * @return array + */ + public function getRegisteredJavascriptBy($sCoreJsFile, $sNamespace = '') + { + $scripts = array(); + + if ($sNamespace == '') { + foreach ($this->_aJavascripts as $i => $js) { + if ($sCoreJsFile == $js->sCoreJsFile) { + $scripts = array_merge($scripts, $this->_aJavascripts[$i]->pluginJsFile); + } + } + } else { + foreach ($this->_aJavascripts as $i => $js) { + if ($sCoreJsFile == $js->sCoreJsFile && $sNamespace == $js->sNamespace) { + $scripts = array_merge($scripts, $this->_aJavascripts[$i]->pluginJsFile); + } + } + } + return $scripts; + } + + /** + * unregister all javascripts from a namespace or a js core file given + * + * @param string $sNamespace + * @param string $sCoreJsFile + * @return array + */ + public function unregisterJavascripts($sNamespace, $sCoreJsFile = '') + { + if ($sCoreJsFile == '') { + foreach ($this->_aJavascripts as $i => $js) { + if ($sNamespace == $js->sNamespace) { + unset($this->_aJavascripts[$i]); + } + } + // Re-index when all js were unregistered + $this->_aJavascripts = array_values($this->_aJavascripts); + } else { + foreach ($this->_aJavascripts as $i => $js) { + if ($sCoreJsFile == $js->sCoreJsFile && $sNamespace == $js->sNamespace) { + unset($this->_aJavascripts[$i]); + // Re-index for each js that was unregistered + $this->_aJavascripts = array_values($this->_aJavascripts); + } + } + } + } + + /** + * Register a reports class in the singleton + * + * @param string $sNamespace + */ + public function registerReport($sNamespace) + { + $found = false; + foreach ($this->_aReports as $row => $detail) { + if ($sNamespace == $detail) { + $found = true; + } + } + if (!$found) { + $this->_aReports[] = $sNamespace; + } + } + + /** + * Register a PmFunction class in the singleton + * + * @param string $sNamespace + */ + public function registerPmFunction($sNamespace) + { + $found = false; + foreach ($this->_aPmFunctions as $row => $detail) { + if ($sNamespace == $detail) { + $found = true; + } + } + if (!$found) { + $this->_aPmFunctions[] = $sNamespace; + } + } + + /** + * Register a redirectLogin class in the singleton + * + * @param string $sNamespace + * @param string $sRole + * @param string $sPathMethod + */ + public function registerRedirectLogin($sNamespace, $sRole, $sPathMethod) + { + $found = false; + foreach ($this->_aRedirectLogin as $row => $detail) { + if (($sNamespace == $detail->sNamespace) && ($sRole == $detail->sRoleCode)) { + //Filters based on Workspace and Role Code + $found = true; + } + } + if (!$found) { + $this->_aRedirectLogin[] = new RedirectDetail($sNamespace, $sRole, $sPathMethod); + } + } + + /** + * Register a folder for methods + * + * @param string $sNamespace + * @param string $sFolderId + * @param string $sFolderName + */ + public function registerFolder($sNamespace, $sFolderId, $sFolderName) + { + $found = false; + foreach ($this->_aFolders as $row => $detail) { + if ($sFolderId == $detail->sFolderId && $sNamespace == $detail->sNamespace) { + $found = true; + } + } + + if (!$found) { + $this->_aFolders[] = new FolderDetail($sNamespace, $sFolderId, $sFolderName); + } + } + + /** + * Register a step for process + * + * @param $sNamespace + * @param $sStepId + * @param $sStepName + * @param $sStepTitle + * @param string $setupStepPage + */ + public function registerStep($sNamespace, $sStepId, $sStepName, $sStepTitle, $setupStepPage = '') + { + $found = false; + foreach ($this->_aSteps as $row => $detail) { + if ($sStepId == $detail->sStepId && $sNamespace == $detail->sNamespace) { + $found = true; + } + } + + if (!$found) { + $this->_aSteps[] = new StepDetail($sNamespace, $sStepId, $sStepName, $sStepTitle, $setupStepPage); + } + } + + /** + * Return true if the $sFolderName is registered in the singleton + * + * @param string $sFolderName + * @return bool + */ + public function isRegisteredFolder($sFolderName) + { + foreach ($this->_aFolders as $row => $folder) { + if ($sFolderName == $folder->sFolderName && is_dir(PATH_PLUGINS . $folder->sFolderName)) { + return true; + } elseif ($sFolderName == $folder->sFolderName && + is_dir(PATH_PLUGINS . $folder->sNamespace . PATH_SEP . $folder->sFolderName)) { + return $folder->sNamespace; + } + } + return false; + } + + /** + * Return all menus related to a menuId + * + * @param string $menuId + */ + public function getMenus($menuId) + { + foreach ($this->_aMenus as $row => $detail) { + if ($menuId == $detail->sMenuId && file_exists($detail->sFilename)) { + include($detail->sFilename); + } + } + } + + /** + * return all dashlets classes registered + * + * @return array + */ + public function getDashlets() + { + return $this->_aDashlets; + } + + /** + * This function returns all reports registered + * + * @return array + */ + public function getReports() + { + return $this->_aReports; +// $report = array(); +// foreach ($this->_aReports as $row => $detail) { +// $sClassName = str_replace('plugin', 'class', $this->_aPluginDetails[$detail]->sClassName); +// $report[] = $sClassName; +// } +// return $report; + } + + /** + * This function returns all pmFunctions registered + * + * @return array + */ + public function getPmFunctions() + { + return $this->_aPmFunctions; +// $pmf = array(); +// foreach ($this->_aPmFunctions as $row => $detail) { +// $sClassName = str_replace('plugin', 'class', $this->_aPluginDetails[$detail]->sClassName); +// $pmf[] = $sClassName; +// } +// return $pmf; + } + + /** + * This function returns all steps registered + * + * @return array + */ + public function getSteps() + { + return $this->_aSteps; + } + + /** + * This function returns all redirect registered + * + * @return array + */ + public function getRedirectLogins() + { + return $this->_aRedirectLogin; + } + + /** + * execute all triggers related to a triggerId + * + * TODO + * + * @param string $triggerId + * @param $oData + * @return mixed + */ + public function executeTriggers($triggerId, $oData) + { + \G::LoadThirdParty("pear", "PEAR"); + foreach ($this->_aTriggers as $row => $detail) { + if ($triggerId == $detail->sTriggerId) { + //review all folders registered for this namespace + $found = false; + $classFile = ''; + + foreach ($this->_aFolders as $row => $folder) { + $fname = $folder->sNamespace == 'enterprise' ? + PATH_CORE . 'classes' . PATH_SEP . 'class.' . $folder->sFolderName . '.php' : + PATH_PLUGINS . $folder->sFolderName . PATH_SEP . 'class.' . $folder->sFolderName . '.php'; + if ($detail->sNamespace == $folder->sNamespace && file_exists($fname)) { + $found = true; + $classFile = $fname; + } + } + if ($found) { + require_once($classFile); + $sClassName = substr($this->_aPluginDetails[$detail->sNamespace]->sClassName, 0, 1) . + str_replace( + 'plugin', + 'class', + substr($this->_aPluginDetails[$detail->sNamespace]->sClassName, 1) + ); + $obj = new $sClassName(); + $methodName = $detail->sTriggerName; + $response = $obj->{$methodName}($oData); + if (\PEAR::isError($response)) { + print $response->getMessage(); + return; + } + return $response; + } else { + print "error in call method " . $detail->sTriggerName; + } + } + } + } + + /** + * verify if exists triggers related to a triggerId + * + * @param string $triggerId + * @return bool + */ + public function existsTrigger($triggerId) + { + $found = false; + foreach ($this->_aTriggers as $row => $detail) { + if ($triggerId == $detail->sTriggerId) { + //review all folders registered for this namespace + foreach ($this->_aFolders as $row => $folder) { + $fname = $folder->sNamespace == 'enterprise' ? + PATH_CORE . 'classes' . PATH_SEP . 'class.' . $folder->sFolderName . '.php' : + PATH_PLUGINS . $folder->sFolderName . PATH_SEP . 'class.' . $folder->sFolderName . '.php'; + if ($detail->sNamespace == $folder->sNamespace && file_exists($fname)) { + $found = true; + } + } + + } + } + return $found; + } + + /** + * Return info related to a triggerId + * + * @param int $triggerId + * @return object + */ + public function getTriggerInfo($triggerId) + { + $found = null; + foreach ($this->_aTriggers as $row => $detail) { + if ($triggerId == $detail->sTriggerId) { + //review all folders registered for this namespace + foreach ($this->_aFolders as $row => $folder) { + $fname = PATH_PLUGINS . $folder->sFolderName . PATH_SEP . 'class.' . $folder->sFolderName . '.php'; + if ($detail->sNamespace == $folder->sNamespace && file_exists($fname)) { + $found = $detail; + } + } + } + } + return $found; + } + + /** + * Register a trigger in the Singleton + * + * @param string $sNamespace + * @param string $sTriggerId + * @param string $sTriggerName + */ + public function registerTrigger($sNamespace, $sTriggerId, $sTriggerName) + { + $found = false; + foreach ($this->_aTriggers as $row => $detail) { + if ($sTriggerId == $detail->sTriggerId && $sNamespace == $detail->sNamespace) { + $found = true; + } + } + if (!$found) { + $triggerDetail = new TriggerDetail($sNamespace, $sTriggerId, $sTriggerName); + $this->_aTriggers[] = $triggerDetail; + } + } + + /** + * Get plugin + * + * @param string $sNamespace + * @return mixed + */ + public function &getPlugin($sNamespace) + { + $oPlugin = null; + if (array_key_exists($sNamespace, $this->_aPlugins)) { + $oPlugin = $this->_aPlugins[$sNamespace]; + } + return $oPlugin; + } + + /** + * Set company logo + * + * @param string $sNamespace + * @param string $filename + * @return void + */ + public function setCompanyLogo($sNamespace, $filename) + { + foreach ($this->_aPluginDetails as $row => $detail) { + if ($sNamespace == $detail->sNamespace) { + $this->_aPluginDetails[$sNamespace]->sCompanyLogo = $filename; + } + } + } + + /** + * Get company logo + * + * @param $default + * @return mixed + */ + public function getCompanyLogo($default) + { + $sCompanyLogo = $default; + foreach ($this->_aPluginDetails as $row => $detail) { + if (trim($detail->sCompanyLogo) != '') { + $sCompanyLogo = $detail->sCompanyLogo; + } + } + return $sCompanyLogo; + } + + /** + * get setup Plugins + * + * @param unknown_type $default + * @return void + */ + /** + * @return int + */ + public function setupPlugins() + { + try { + require_once(PATH_CORE . "methods" . PATH_SEP . "enterprise" . PATH_SEP . "enterprise.php"); +// require_once("class.serverConfiguration.php"); + $iPlugins = 0; +// $oServerConf =& \serverConf::getSingleton(); +// $oServerConf->addPlugin(SYS_SYS, $this->_aPluginDetails); + foreach ($this->_aPluginDetails as $namespace => $detail) { + if (isset($detail->enabled) && $detail->enabled) { + if (!empty($detail->sFilename) && file_exists($detail->sFilename)) { + $arrayFileInfo = pathinfo($detail->sFilename); + $sFilename = (($detail->sNamespace == "enterprise") ? + PATH_CORE . "methods" . PATH_SEP . "enterprise" . PATH_SEP : + PATH_PLUGINS + ) . $arrayFileInfo["basename"]; + if (!file_exists($sFilename)) { + continue; + } + require_once $sFilename; + if (class_exists($detail->sClassName)) { + /** @var \enterprisePlugin|\PMPlugin $oPlugin */ + $oPlugin = new $detail->sClassName($detail->sNamespace, $detail->sFilename); + $this->_aPlugins[$detail->sNamespace] = $oPlugin; + $iPlugins++; + $oPlugin->setup(); + } + } + } + } + return $iPlugins; + } catch (\Exception $e) { + global $G_PUBLISH; + $aMessage['MESSAGE'] = $e->getMessage(); + $G_PUBLISH = new \Publisher(); + $G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', '', $aMessage); + \G::RenderPage('publish'); + die(); + } + } + + /** + * this function execute a Method + * + * @param string $sNamespace + * @param string $methodName + * @param object $oData + * @return mixed + * @throws \Exception + */ + public function executeMethod($sNamespace, $methodName, $oData) + { + $response = null; + try { + $details = $this->_aPluginDetails[$sNamespace]; + $pluginFolder = $details->sPluginFolder; + $className = $details->sClassName; + $classFile = PATH_PLUGINS . $pluginFolder . PATH_SEP . 'class.' . $pluginFolder . '.php'; + if (file_exists($classFile)) { + $sClassName = substr_replace($className, "class", -6, 6); + //$sClassName = str_replace ( 'plugin', 'class', $className ); + if (!class_exists($sClassName)) { + require_once $classFile; + } + $obj = new $sClassName(); + if (!in_array($methodName, get_class_methods($obj))) { + throw (new \Exception("The method '$methodName' doesn't exist in class '$sClassName' ")); + } + $obj->sNamespace = $details->sNamespace; + $obj->sClassName = $details->sClassName; + $obj->sFilename = $details->sFilename; + $obj->iVersion = $details->iVersion; + $obj->sFriendlyName = $details->sFriendlyName; + $obj->sPluginFolder = $details->sPluginFolder; + $response = $obj->{$methodName}($oData); + } + return $response; + } catch (\Exception $e) { + throw ($e); + } + } + + /** + * this function gets Fields For Page on Setup + * + * @param string $sNamespace + * @return object + */ + public function getFieldsForPageSetup($sNamespace) + { + $oData = null; + return $this->executeMethod($sNamespace, 'getFieldsForPageSetup', $oData); + } + + /** + * this function updates Fields For Page on Setup + * + * @param string $sNamespace + * @return mixed + * @throws \Exception + */ + public function updateFieldsForPageSetup($sNamespace, $oData) + { + if (!isset($this->_aPluginDetails[$sNamespace])) { + throw (new \Exception("The namespace '$sNamespace' doesn't exist in plugins folder.")); + } + return $this->executeMethod($sNamespace, 'updateFieldsForPageSetup', $oData); + } + + /** + * @deprecated + */ + public function eevalidate() + { +// $fileL = PATH_DATA_SITE . 'license.dat'; +// $fileS = PATH_DATA . 'license.dat'; +// if ((file_exists($fileL)) || (file_exists($fileS))) { +// //Found a License +// if (class_exists('pmLicenseManager')) { +// $sSerializedFile = PATH_DATA_SITE . 'lmn.singleton'; +// $pmLicenseManagerO = &\pmLicenseManager::getSingleton(); +// if (file_exists($sSerializedFile)) { +// $pmLicenseManagerO->unSerializeInstance(file_get_contents($sSerializedFile)); +// } +// } +// } + } + + /** + * Register a toolbar for dynaform editor in the singleton + * + * @param string $sNamespace + * @param string $sToolbarId + * @param string $sFilename + */ + public function registerToolbarFile($sNamespace, $sToolbarId, $sFilename) + { + $found = false; + foreach ($this->_aToolbarFiles as $row => $detail) { + if ($sToolbarId == $detail->sToolbarId && $sNamespace == $detail->sNamespace) { + $found = true; + } + } + if (!$found) { + $toolbarDetail = new ToolbarDetail($sNamespace, $sToolbarId, $sFilename); + $this->_aToolbarFiles[] = $toolbarDetail; + } + } + + /** + * return all toolbar files related to a sToolbarId + * + * @param string $sToolbarId (NORMAL, GRID) + */ + public function getToolbarOptions($sToolbarId) + { + foreach ($this->_aToolbarFiles as $row => $detail) { + if ($sToolbarId == $detail->sToolbarId && file_exists($detail->sFilename)) { + include($detail->sFilename); + } + } + } + + /** + * Register a Case Scheduler Plugin + * + * @param $sNamespace + * @param $sActionId + * @param $sActionForm + * @param $sActionSave + * @param $sActionExecute + * @param $sActionGetFields + */ + public function registerCaseSchedulerPlugin( + $sNamespace, + $sActionId, + $sActionForm, + $sActionSave, + $sActionExecute, + $sActionGetFields + ) + { + $found = false; + foreach ($this->_aCaseSchedulerPlugin as $row => $detail) { + if ($sActionId == $detail->sActionId && $sNamespace == $detail->sNamespace) { + $found = true; + } + } + + if (!$found) { + $this->_aCaseSchedulerPlugin[] = new CaseSchedulerPlugin( + $sNamespace, + $sActionId, + $sActionForm, + $sActionSave, + $sActionExecute, + $sActionGetFields + ); + } + } + + /** + * This function returns all Case Scheduler Plugins registered + * + * @return array + */ + public function getCaseSchedulerPlugins() + { + return $this->_aCaseSchedulerPlugin; + } + + /** + * Register a Task Extended property page in the singleton + * + * @param string $sNamespace + * @param $sPage + * @param $sName + * @param $sIcon + */ + public function registerTaskExtendedProperty($sNamespace, $sPage, $sName, $sIcon) + { + $found = false; + foreach ($this->_aTaskExtendedProperties as $row => $detail) { + if ($sPage == $detail->sPage && $sNamespace == $detail->sNamespace) { + $detail->sName = $sName; + $detail->sIcon = $sIcon; + $found = true; + } + } + if (!$found) { + $taskExtendedProperty = new TaskExtendedProperty($sNamespace, $sPage, $sName, $sIcon); + $this->_aTaskExtendedProperties[] = $taskExtendedProperty; + } + } + + /** + * Register a dashboard page for cases in the singleton + * + * @param string $sNamespace + * @param string $sPage + * @param string $sName + * @param string $sIcon + */ + public function registerDashboardPage($sNamespace, $sPage, $sName, $sIcon) + { + $found = false; + foreach ($this->_aDashboardPages as $row => $detail) { + if ($sPage == $detail->sPage && $sNamespace == $detail->sNamespace) { + $detail->sName = $sName; + $detail->sIcon = $sIcon; + $found = true; + } + } + if (!$found) { + $dashboardPage = new DashboardPage($sNamespace, $sPage, $sName, $sIcon); + $this->_aDashboardPages[] = $dashboardPage; + } + } + + /** + * Register a rest service class from a plugin to be served by processmaker + * + * @param string $sNamespace The namespace for the plugin + * @return bool + */ + public function registerRestService($sNamespace) + { + $baseSrcPluginPath = PATH_PLUGINS . $sNamespace . PATH_SEP . "src"; + $apiPath = PATH_SEP . "Services" . PATH_SEP . "Api" . PATH_SEP . ucfirst($sNamespace); + $classesList = (new \Bootstrap())->rglob('*', 0, $baseSrcPluginPath . $apiPath); + + foreach ($classesList as $classFile) { + if (pathinfo($classFile, PATHINFO_EXTENSION) === 'php') { + $ns = str_replace( + '/', + '\\', + str_replace('.php', '', str_replace($baseSrcPluginPath, '', $classFile)) + ); + + // Ensure that is registering only existent classes. + if (class_exists($ns)) { + $this->_restServices[$sNamespace][] = array( + "filepath" => $classFile, + "namespace" => $ns + ); + } + } + } + + WebApplication::purgeRestApiCache(basename(PATH_DATA_SITE)); + + return true; + } + + /** + * Register a extend rest service class from a plugin to be served by processmaker + * + * @param string $sNamespace The namespace for the plugin + * @param string $className The service (api) class name + */ + public function registerExtendsRestService($sNamespace, $className) + { + $baseSrcPluginPath = PATH_PLUGINS . $sNamespace . PATH_SEP . "src"; + $apiPath = PATH_SEP . "Services" . PATH_SEP . "Ext" . PATH_SEP; + $classFile = $baseSrcPluginPath . $apiPath . 'Ext' . $className . '.php'; + if (file_exists($classFile)) { + $this->_restExtendServices[$sNamespace][$className] = array( + "filePath" => $classFile, + "classParent" => $className, + "classExtend" => 'Ext' . $className + ); + } + } + + /** + * Get a extend rest service class from a plugin to be served by processmaker + * + * @param string $className The service (api) class name + * @return array + */ + public function getExtendsRestService($className) + { + $responseRestExtendService = array(); + foreach ($this->_restExtendServices as $sNamespace => $restExtendService) { + if (isset($restExtendService[$className])) { + $responseRestExtendService = $restExtendService[$className]; + break; + } + } + return $responseRestExtendService; + } + + /** + * Remove a extend rest service class from a plugin to be served by processmaker + * + * @param string $sNamespace + * @param string $className The service (api) class name + * @return bool + */ + public function disableExtendsRestService($sNamespace, $className = '') + { + if (isset($this->_restExtendServices[$sNamespace][$className]) && !empty($className)) { + unset($this->_restExtendServices[$sNamespace][$className]); + } elseif (empty($className)) { + unset($this->_restExtendServices[$sNamespace]); + } + } + + /** + * Unregister a rest service class of a plugin + * + * @param string $sNamespace The namespace for the plugin + */ + public function unregisterRestService($sNamespace) + { + if ($this->_restServices) { + unset($this->_restServices[$sNamespace]); + WebApplication::purgeRestApiCache(basename(PATH_DATA_SITE)); + } + } + + public function getRegisteredRestServices() + { + return $this->_restServices; + } + + /** + * return all dashboard pages + * + * @return array + */ + public function getDashboardPages() + { + return $this->_aDashboardPages; + } + + /** + * return all tasl extended properties + * + * @return array + */ + public function getTaskExtendedProperties() + { + return $this->_aTaskExtendedProperties; + } + + public function registerDashboard() + { + // Dummy function for backwards compatibility + } + + public function getAttributes() + { + return get_object_vars($this); + } + + public function verifyTranslation($namePlugin) + { + $language = new \Language(); + $pathPluginTranslations = PATH_PLUGINS . $namePlugin . PATH_SEP . 'translations' . PATH_SEP; + if (file_exists($pathPluginTranslations . 'translations.php')) { + if (!file_exists($pathPluginTranslations . $namePlugin . '.' . SYS_LANG . '.po')) { + $language->createLanguagePlugin($namePlugin, SYS_LANG); + } + $language->updateLanguagePlugin($namePlugin, SYS_LANG); + } + } + + /** + * Register a cron file in the singleton + * + * @param string $namespace + * @param string $cronFile + */ + public function registerCronFile($namespace, $cronFile) + { + $found = false; + foreach ($this->_aCronFiles as $row => $detail) { + if ($cronFile == $detail->cronFile && $namespace == $detail->namespace) { + $detail->cronFile = $cronFile; + $found = true; + } + } + if (!$found) { + $cronFile = new CronFile($namespace, $cronFile); + $this->_aCronFiles[] = $cronFile; + } + } + + /** + * Function to enable rest service for plugins + * @param string $sNamespace + * @param bool $enable + */ + public function enableRestService($sNamespace, $enable) + { + $this->_restServiceEnabled[$sNamespace] = $enable; + } + + /** + * Return all cron files registered + * + * @return array + */ + public function getCronFiles() + { + return $this->_aCronFiles; + } + + /** + * Update the plugin attributes in all workspaces + * + * @param string $pluginName Plugin name + * @throws \Exception + */ + public function updatePluginAttributesInAllWorkspaces($pluginName) + { + try { + \G::LoadClass("wsTools"); + + //Set variables + $pluginFileName = $pluginName . ".php"; + + //Verify data + if (!file_exists(PATH_PLUGINS . $pluginFileName)) { + throw new \Exception("Error: The plugin not exists"); + } + + //Update plugin attributes + require_once(PATH_PLUGINS . $pluginFileName); + + $pmPluginRegistry =& \PMPluginRegistry::getSingleton(); + + $pluginDetails = $pmPluginRegistry->getPluginDetails($pluginFileName); + + if (isset($pluginDetails->aWorkspaces) && + is_array($pluginDetails->aWorkspaces) && + count($pluginDetails->aWorkspaces) > 0 + ) { + $arrayWorkspace = array(); + + foreach (\System::listWorkspaces() as $value) { + $workspaceTools = $value; + + $arrayWorkspace[] = $workspaceTools->name; + } + + $arrayWorkspaceAux = array_diff($arrayWorkspace, $pluginDetails->aWorkspaces); //Workspaces to update + $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 = PMPluginRegistry::loadSingleton( + $workspacePathDataSite . "plugin.singleton" + ); + + if (isset($pmPluginRegistry->_aPluginDetails[$pluginName])) { + 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 = \PMPluginRegistry::loadSingleton($workspacePathDataSite . "plugin.singleton"); + + $pmPluginRegistry->disablePlugin($pluginName); + + file_put_contents( + $workspacePathDataSite . "plugin.singleton", + $pmPluginRegistry->serializeInstance() + ); + } + } + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Register designer menu file + * + * @param string $pluginName Plugin name + * @param string $file Designer menu file + * @throws \Exception + */ + public function registerDesignerMenu($pluginName, $file) + { + try { + $flagFound = false; + + foreach ($this->_arrayDesignerMenu as $value) { + if ($value->pluginName == $pluginName && $value->file == $file) { + $flagFound = true; + break; + } + } + + if (!$flagFound) { + $obj = new \stdClass(); + $obj->pluginName = $pluginName; + $obj->file = $file; + + $this->_arrayDesignerMenu[] = $obj; + } + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Return all designer menu files registered + * + * @return array + * @throws \Exception + */ + public function getDesignerMenu() + { + try { + return $this->_arrayDesignerMenu; + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Replace new options to menu + * + * @param string $namespace + * @param array $from + * @param array $options + * @return void + */ + public function registerMenuOptionsToReplace($namespace, $from, $options) + { + if (isset($from["section"]) && isset($from["menuId"])) { + $section = $from["section"]; + $oMenuFromPlugin = $this->_aMenuOptionsToReplace; + if (array_key_exists($section, $oMenuFromPlugin)) { + unset($this->_aMenuOptionsToReplace[$from["section"]]); + } + $this->_aMenuOptionsToReplace[$from["section"]][$from["menuId"]][] = $options; + } + } + + /** + * Return all menu Options from a specific section + * + * @param string $strMenuName + * @return array + */ + public function getMenuOptionsToReplace($strMenuName) + { + $oMenuFromPlugin = $this->_aMenuOptionsToReplace; + if (sizeof($oMenuFromPlugin)) { + if (array_key_exists($strMenuName, $oMenuFromPlugin)) { + return $oMenuFromPlugin[$strMenuName]; + } + } + } + + /** + * Register a callBackFile in the singleton + * + * @param string $namespace + * @param string $callBackFile + * @throws \Exception + */ + public function registerImportProcessCallback($namespace, $callBackFile) + { + try { + $found = false; + foreach ($this->_aImportProcessCallbackFile as $row => $detail) { + if ($callBackFile == $detail->callBackFile && $namespace == $detail->namespace) { + $detail->callBackFile = $callBackFile; + $found = true; + } + } + if (!$found) { + $callBackFile = new ImportCallBack($namespace, $callBackFile); + $this->_aImportProcessCallbackFile[] = $callBackFile; + } + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Return all callBackFiles registered + * + * @return array + */ + public function getImportProcessCallback() + { + return $this->_aImportProcessCallbackFile; + } + + /** + * Register a callBackFile in the singleton + * + * @param string $callBackFile + * @throws \Exception + */ + public function registerOpenReassignCallback($callBackFile) + { + try { + $found = false; + foreach ($this->_aOpenReassignCallback as $row => $detail) { + if ($callBackFile == $detail->callBackFile) { + $detail->callBackFile = $callBackFile; + $found = true; + } + } + if (!$found) { + $callBackFile = new OpenReassignCallback($callBackFile); + $this->_aOpenReassignCallback[] = $callBackFile; + } + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Return all callBackFiles registered + * + * @return array + */ + public function getOpenReassignCallback() + { + return $this->_aOpenReassignCallback; + } + + public function getPluginsData() + { + return $this->_aPlugins; + } + + /** + * The following function method extracts the plugin if exists one + * with the same uppercase characters, this is required for the + * + * @param $code + * @return array|object + */ + public function getPluginByCode($code) + { + $plugin = new \stdClass(); + foreach ($this->_aPlugins as $plugin) { + $plugin = (array)$plugin; + if (strtoupper($plugin['sNamespace']) == $code) { + return (object)$plugin; + } + } + return $plugin; + } + + /** + * Checks if the plugin name is Enterprise Plugin + * + * @param string $pluginName Plugin name + * @param string $path Path to plugin + * + * @return bool Returns TRUE when plugin name is Enterprise Plugin, FALSE otherwise + */ + public function isEnterprisePlugin($pluginName, $path = null) + { + $path = (!is_null($path) && $path != '') ? rtrim($path, '/\\') . PATH_SEP : PATH_PLUGINS; + $pluginFile = $pluginName . '.php'; + + //Return + return preg_match( + '/^.*class\s+' . $pluginName . 'Plugin\s+extends\s+(?:enterprisePlugin)\s*\{.*$/i', + str_replace(["\n", "\r", "\t"], ' ', file_get_contents($path . $pluginFile)) + ); + } + + /** + * Registry in an array routes for js or css files. + * @param string $pluginName + * @param string $pathFile + * @throws \Exception + */ + public function registerDesignerSourcePath($pluginName, $pathFile) + { + try { + $flagFound = false; + + foreach ($this->_arrayDesignerSourcePath as $value) { + if ($value->pluginName == $pluginName && $value->pathFile == $pathFile) { + $flagFound = true; + break; + } + } + + if (!$flagFound) { + $obj = new \stdClass(); + $obj->pluginName = $pluginName; + $obj->pathFile = $pathFile; + + $this->_arrayDesignerSourcePath[] = $obj; + } + } catch (\Exception $e) { + throw $e; + } + } + + /** + * You obtain an array containing the routes recorded by the + * function registerDesignerSourcePath. + * @return array + * @throws \Exception + */ + public function getDesignerSourcePath() + { + try { + return $this->_arrayDesignerSourcePath; + } catch (\Exception $e) { + throw $e; + } + } + + public function iterateVisible() + { + $response = array(); + foreach ($this as $key => $value) { + $response[$key] = $value; + } + return $response; + } +} diff --git a/workflow/public_html/sysGeneric.php b/workflow/public_html/sysGeneric.php index 8c2e0961f..a06bf0351 100644 --- a/workflow/public_html/sysGeneric.php +++ b/workflow/public_html/sysGeneric.php @@ -638,17 +638,6 @@ $memcache = & PMmemcached::getSingleton( SYS_SYS ); // load Plugins base class -//here we are loading all plugins registered -//the singleton has a list of enabled plugins -$sSerializedFile = PATH_DATA_SITE . 'plugin.singleton'; - -if (file_exists( $sSerializedFile )) { - $oPluginRegistry = PMPluginRegistry::loadSingleton($sSerializedFile); - $attributes = $oPluginRegistry->getAttributes(); - Bootstrap::LoadTranslationPlugins( defined( 'SYS_LANG' ) ? SYS_LANG : "en" , $attributes); -} else{ - $oPluginRegistry = PMPluginRegistry::getSingleton(); -} // setup propel definitions and logging //changed to autoloader //require_once ("propel/Propel.php"); @@ -689,6 +678,17 @@ if (defined( 'DEBUG_SQL_LOG' ) && DEBUG_SQL_LOG) { Propel::init( PATH_CORE . "config/databases.php" ); } +//here we are loading all plugins registered +//the singleton has a list of enabled plugins +$sSerializedFile = PATH_DATA_SITE . 'plugin.singleton'; +$oPluginRegistry = &ProcessMaker\Plugins\PluginsRegistry::loadSingleton(); +$attributes = $oPluginRegistry->getAttributes(); +Bootstrap::LoadTranslationPlugins( defined( 'SYS_LANG' ) ? SYS_LANG : "en" , $attributes); + +// Setup plugins +$avoidChangedWorkspaceValidation = false; +$oPluginRegistry->setupPlugins(); //get and setup enabled plugins + //Set Time Zone /*----------------------------------********---------------------------------*/ $_SESSION['__SYSTEM_UTC_TIME_ZONE__'] = (int)($config['system_utc_time_zone']) == 1; @@ -740,9 +740,7 @@ if (SYS_LANG != 'en' && ! is_file( PATH_LANGUAGECONT . 'translation.' . SYS_LANG Bootstrap::LoadTranslationObject(SYS_LANG); } -// Setup plugins -$oPluginRegistry->setupPlugins(); //get and setup enabled plugins -$avoidChangedWorkspaceValidation = false; + // Load custom Classes and Model from Plugins. Bootstrap::LoadAllPluginModelClasses();