This commit is contained in:
Paula Quispe
2017-10-09 16:19:12 -04:00
parent 958e1255a8
commit d0483f8b44
3 changed files with 243 additions and 87 deletions

View File

@@ -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);
}
}
}