diff --git a/workflow/engine/bin/tasks/cliWorkspaces.php b/workflow/engine/bin/tasks/cliWorkspaces.php index 6b5f216c9..56a50872e 100644 --- a/workflow/engine/bin/tasks/cliWorkspaces.php +++ b/workflow/engine/bin/tasks/cliWorkspaces.php @@ -315,6 +315,17 @@ CLI::taskOpt("lang", "", "lLANG", "lang=LANG"); CLI::taskArg('workspace'); CLI::taskRun("cliListIds"); +/** + * Upgrade the CONTENT table + */ +CLI::taskName('upgrade-content'); +CLI::taskDescription(<<name); + } + } +} +/** + * This function will upgrade the CONTENT table for a workspace + * This function is executed only for one workspace + * @param array $args, workspaceName that we will to apply the command + * @param array $opts, we can send additional parameters + * + * @return void + */ +function upgradeContent($args, $opts) +{ + try { + //Load the attributes for the workspace + $arrayWorkspace = get_workspaces_from_args($args); + //Loop, read all the attributes related to the one workspace + $wsName = $arrayWorkspace[key($arrayWorkspace)]->name; + Bootstrap::setConstantsRelatedWs($wsName); + $workspaces = get_workspaces_from_args($args); + foreach ($workspaces as $workspace) { + try { + G::outRes("Upgrading content for " . pakeColor::colorize($workspace->name, "INFO") . "\n"); + $workspace->upgradeContent($workspace->name, true); + } catch (Exception $e) { + G::outRes("Errors upgrading content of workspace " . CLI::info($workspace->name) . ": " . CLI::error($e->getMessage()) . "\n"); + } + } + } catch (Exception $e) { + G::outRes(CLI::error($e->getMessage()) . "\n"); + } +} + /** * We will repair the translation in the languages defined in the workspace * Verify if we need to execute an external program for each workspace diff --git a/workflow/engine/classes/WorkspaceTools.php b/workflow/engine/classes/WorkspaceTools.php index 6edfc8bce..26ed884e5 100644 --- a/workflow/engine/classes/WorkspaceTools.php +++ b/workflow/engine/classes/WorkspaceTools.php @@ -57,6 +57,8 @@ class WorkspaceTools 'UPDATE LIST_UNASSIGNED_GROUP SET USR_ID=(SELECT USR_ID FROM USERS WHERE USERS.USR_UID=LIST_UNASSIGNED_GROUP.USR_UID)', ); + private $lastContentMigrateTable = false; + private $listContentMigrateTable = []; /** * Create a workspace tools object. @@ -76,6 +78,124 @@ class WorkspaceTools if ($this->workspaceExists()) { $this->getDBInfo(); } + $this->setListContentMigrateTable(); + } + + /** + * Gets the last content migrate table + * + * @return string + */ + public function getLastContentMigrateTable() + { + return $this->lastContentMigrateTable; + } + + /** + * Sets the last content migrate table + * + * @param string $tableColumn + * + */ + public function setLastContentMigrateTable($tableColumn) + { + $this->lastContentMigrateTable = $tableColumn; + } + + /** + * Gets the array for list content migrate table + * + * @return array + */ + public function getListContentMigrateTable() + { + return $this->listContentMigrateTable; + } + + /** + * Sets the array list content migrate table + */ + public function setListContentMigrateTable() + { + $migrateTables = array( + 'Groupwf' => array( + 'uid' => 'GRP_UID', + 'fields' => array('GRP_TITLE'), + 'methods' => array('exists' => 'GroupwfExists') + ), + 'Process' => array( + 'uid' => 'PRO_UID', + 'fields' => array('PRO_TITLE', 'PRO_DESCRIPTION'), + 'methods' => array('exists' => 'exists') + ), + 'Department' => array( + 'uid' => 'DEP_UID', + 'fields' => array('DEPO_TITLE'), + 'alias' => array('DEPO_TITLE' => 'DEP_TITLE'), + 'methods' => array('exists' => 'existsDepartment') + ), + 'Task' => array( + 'uid' => 'TAS_UID', + 'fields' => array('TAS_TITLE', 'TAS_DESCRIPTION', 'TAS_DEF_TITLE', 'TAS_DEF_SUBJECT_MESSAGE', 'TAS_DEF_PROC_CODE', 'TAS_DEF_MESSAGE', 'TAS_DEF_DESCRIPTION'), + 'methods' => array('exists' => 'taskExists') + ), + 'InputDocument' => array( + 'uid' => 'INP_DOC_UID', + 'fields' => array('INP_DOC_TITLE', 'INP_DOC_DESCRIPTION'), + 'methods' => array('exists' => 'InputExists') + ), + 'Application' => array( + 'uid' => 'APP_UID', + 'fields' => array('APP_TITLE', 'APP_DESCRIPTION'), + 'methods' => array('exists' => 'exists') + ), + 'AppDocument' => array( + 'uid' => 'APP_DOC_UID', + 'alias' => array('CON_PARENT' => 'DOC_VERSION'), + 'fields' => array('APP_DOC_TITLE', 'APP_DOC_COMMENT', 'APP_DOC_FILENAME'), + 'methods' => array('exists' => 'exists') + ), + 'Dynaform' => array( + 'uid' => 'DYN_UID', + 'fields' => array('DYN_TITLE', 'DYN_DESCRIPTION'), + 'methods' => array('exists' => 'exists') + ), + 'OutputDocument' => array( + 'uid' => 'OUT_DOC_UID', + 'fields' => array('OUT_DOC_TITLE', 'OUT_DOC_DESCRIPTION', 'OUT_DOC_FILENAME', 'OUT_DOC_TEMPLATE'), + 'methods' => array('exists' => 'OutputExists') + ), + 'ReportTable' => array( + 'uid' => 'REP_TAB_UID', + 'fields' => array('REP_TAB_TITLE'), + 'methods' => array('exists' => 'reportTableExists', 'update' => function ($row) { + $oRepTab = \ReportTablePeer::retrieveByPK($row['REP_TAB_UID']); + $oRepTab->fromArray($row, BasePeer::TYPE_FIELDNAME); + if ($oRepTab->validate()) { + $result = $oRepTab->save(); + } + }) + ), + 'Triggers' => array( + 'uid' => 'TRI_UID', + 'fields' => array('TRI_TITLE', 'TRI_DESCRIPTION'), + 'methods' => array('exists' => 'TriggerExists') + ), + '\ProcessMaker\BusinessModel\WebEntryEvent' => array( + 'uid' => 'WEE_UID', + 'fields' => array('WEE_TITLE', 'WEE_DESCRIPTION'), + 'methods' => array('exists' => 'exists', 'update' => function ($row) { + $webEntry = \WebEntryEventPeer::retrieveByPK($row['WEE_UID']); + $webEntry->fromArray($row, BasePeer::TYPE_FIELDNAME); + if ($webEntry->validate()) { + $result = $webEntry->save(); + } + }), + 'peer' => 'WebEntryEventPeer' + ) + ); + + $this->listContentMigrateTable = $migrateTables; } /** @@ -469,19 +589,52 @@ class WorkspaceTools /** * Upgrade this workspace Content. + * @param string $workspace + * @param boolean $executeRegenerateContent + * @return void */ - public function upgradeContent($workSpace = SYS_SYS) + public function upgradeContent($workspace = SYS_SYS, $executeRegenerateContent = false) { $this->initPropel(true); - //require_once 'classes/model/Translation.php'; - $translation = new Translation(); - $information = $translation->getTranslationEnvironments(); - $arrayLang = array(); - foreach ($information as $key => $value) { - $arrayLang[] = trim($value['LOCALE']); + //If the execute flag is false we will check if we needed + if (!$executeRegenerateContent) { + $conf = new Configuration(); + $blackList = []; + if ($conf->exists('MIGRATED_CONTENT', 'content')) { + $configData = $conf->load('MIGRATED_CONTENT', 'content'); + $blackList = unserialize($configData['CFG_VALUE']); + } + + $content = $this->getListContentMigrateTable(); + + foreach ($content as $className => $fields) { + //We check if all the label was migrated from content table + if (!in_array($className, $blackList)) { + $executeRegenerateContent = true; + break; + } + } + + //If the flag is not created we will check the last Content migration + //The $lastContentMigrateTable return true if content is migrated + if (!$executeRegenerateContent && !$this->getLastContentMigrateTable()) { + $executeRegenerateContent = true; + } } - $regenerateContent = new Content(); - $regenerateContent->regenerateContent($arrayLang, $workSpace); + + //We will to regenerate the Content table + if ($executeRegenerateContent) { + CLI::logging("-> Start To update...\n"); + $translation = new Translation(); + $information = $translation->getTranslationEnvironments(); + $arrayLang = []; + foreach ($information as $key => $value) { + $arrayLang[] = trim($value['LOCALE']); + } + $regenerateContent = new Content(); + $regenerateContent->regenerateContent($arrayLang, $workspace); + } + } /** @@ -1004,6 +1157,10 @@ class WorkspaceTools } } $workspaceSchema = $this->getSchema($rbac); + + //We will check if the database has the last content table migration + $this->checkLastContentMigrate($workspaceSchema); + $changes = System::compareSchema($workspaceSchema, $schema); $changed = (count($changes['tablesToAdd']) > 0 || count($changes['tablesToAlter']) > 0 || count($changes['tablesWithNewIndex']) > 0 || count($changes['tablesToAlterIndex']) > 0); @@ -3421,83 +3578,7 @@ class WorkspaceTools if ((!class_exists('Memcache') || !class_exists('Memcached')) && !defined('MEMCACHED_ENABLED')) { define('MEMCACHED_ENABLED', false); } - $content = array( - 'Groupwf' => array( - 'uid' => 'GRP_UID', - 'fields' => array('GRP_TITLE'), - 'methods' => array('exists' => 'GroupwfExists') - ), - 'Process' => array( - 'uid' => 'PRO_UID', - 'fields' => array('PRO_TITLE', 'PRO_DESCRIPTION'), - 'methods' => array('exists' => 'exists') - ), - 'Department' => array( - 'uid' => 'DEP_UID', - 'fields' => array('DEPO_TITLE'), - 'alias' => array('DEPO_TITLE' => 'DEP_TITLE'), - 'methods' => array('exists' => 'existsDepartment') - ), - 'Task' => array( - 'uid' => 'TAS_UID', - 'fields' => array('TAS_TITLE', 'TAS_DESCRIPTION', 'TAS_DEF_TITLE', 'TAS_DEF_SUBJECT_MESSAGE', 'TAS_DEF_PROC_CODE', 'TAS_DEF_MESSAGE', 'TAS_DEF_DESCRIPTION'), - 'methods' => array('exists' => 'taskExists') - ), - 'InputDocument' => array( - 'uid' => 'INP_DOC_UID', - 'fields' => array('INP_DOC_TITLE', 'INP_DOC_DESCRIPTION'), - 'methods' => array('exists' => 'InputExists') - ), - 'Application' => array( - 'uid' => 'APP_UID', - 'fields' => array('APP_TITLE', 'APP_DESCRIPTION'), - 'methods' => array('exists' => 'exists') - ), - 'AppDocument' => array( - 'uid' => 'APP_DOC_UID', - 'alias' => array('CON_PARENT' => 'DOC_VERSION'), - 'fields' => array('APP_DOC_TITLE', 'APP_DOC_COMMENT', 'APP_DOC_FILENAME'), - 'methods' => array('exists' => 'exists') - ), - 'Dynaform' => array( - 'uid' => 'DYN_UID', - 'fields' => array('DYN_TITLE', 'DYN_DESCRIPTION'), - 'methods' => array('exists' => 'exists') - ), - 'OutputDocument' => array( - 'uid' => 'OUT_DOC_UID', - 'fields' => array('OUT_DOC_TITLE', 'OUT_DOC_DESCRIPTION', 'OUT_DOC_FILENAME', 'OUT_DOC_TEMPLATE'), - 'methods' => array('exists' => 'OutputExists') - ), - 'ReportTable' => array( - 'uid' => 'REP_TAB_UID', - 'fields' => array('REP_TAB_TITLE'), - 'methods' => array('exists' => 'reportTableExists', 'update' => function ($row) { - $oRepTab = \ReportTablePeer::retrieveByPK($row['REP_TAB_UID']); - $oRepTab->fromArray($row, BasePeer::TYPE_FIELDNAME); - if ($oRepTab->validate()) { - $result = $oRepTab->save(); - } - }) - ), - 'Triggers' => array( - 'uid' => 'TRI_UID', - 'fields' => array('TRI_TITLE', 'TRI_DESCRIPTION'), - 'methods' => array('exists' => 'TriggerExists') - ), - '\ProcessMaker\BusinessModel\WebEntryEvent' => array( - 'uid' => 'WEE_UID', - 'fields' => array('WEE_TITLE', 'WEE_DESCRIPTION'), - 'methods' => array('exists' => 'exists', 'update' => function ($row) { - $webEntry = \WebEntryEventPeer::retrieveByPK($row['WEE_UID']); - $webEntry->fromArray($row, BasePeer::TYPE_FIELDNAME); - if ($webEntry->validate()) { - $result = $webEntry->save(); - } - }), - 'peer' => 'WebEntryEventPeer' - ) - ); + $content = $this->getListContentMigrateTable(); foreach ($content as $className => $fields) { if (!in_array($className, $blackList)) { @@ -3950,4 +4031,17 @@ class WorkspaceTools CLI::logging(" $path [" . (file_exists($path) ? 'OK' : 'MISSING') . "]\n"); } } + + /** + * This function get the last table migrated for the labels + * @param array $workspaceSchema, the current schema in the database + * @return void + */ + private function checkLastContentMigrate(array $workspaceSchema){ + $content = end($this->getListContentMigrateTable()); + $lastContent = isset($content['peer']) ? $content['peer'] : null; + if (!is_null($lastContent) && isset($workspaceSchema[$lastContent::TABLE_NAME][$content['fields'][0]])) { + $this->setLastContentMigrateTable(true); + } + } } diff --git a/workflow/engine/data/mysql/insert.sql b/workflow/engine/data/mysql/insert.sql index 524d1777b..7345d4a7e 100644 --- a/workflow/engine/data/mysql/insert.sql +++ b/workflow/engine/data/mysql/insert.sql @@ -61560,7 +61560,8 @@ INSERT INTO CONFIGURATION (CFG_UID,OBJ_UID,CFG_VALUE,PRO_UID,USR_UID,APP_UID) VA ('MIGRATED_LIST','list','true','list','list','list'), ('MIGRATED_LIST_UNASSIGNED','list','true','list','list','list'), ('SKIN_CRON','','s:10:"neoclassic";','','',''), -('AUDIT_LOG','log','s:5:"false";','','',''); +('AUDIT_LOG','log','s:5:"false";','','',''), +('MIGRATED_CONTENT', 'content', 'a:12:{i:0;s:7:"Groupwf";i:1;s:7:"Process";i:2;s:10:"Department";i:3;s:4:"Task";i:4;s:13:"InputDocument";i:5;s:11:"Application";i:6;s:11:"AppDocument";i:7;s:8:"Dynaform";i:8;s:14:"OutputDocument";i:9;s:11:"ReportTable";i:10;s:8:"Triggers";i:11;s:41:"\\ProcessMaker\\BusinessModel\\WebEntryEvent";}', '', '', ''); INSERT INTO CATALOG (CAT_UID, CAT_LABEL_ID, CAT_TYPE, CAT_FLAG, CAT_OBSERVATION, CAT_CREATE_DATE, CAT_UPDATE_DATE) VALUES ('10','ID_BARS','GRAPHIC','','','2015-03-04','2015-03-04'),