From 60f9a8e0942491edf8aa4e8e2ebf23e390bd38eb Mon Sep 17 00:00:00 2001 From: qronald Date: Thu, 7 Jul 2016 14:25:04 -0400 Subject: [PATCH] HOR-1330 Modificar el upgrade para colocar los valores de las nuevas columnas copiadas de CONTENT up observations remove method migrate_content in database-upgrade fix in Application and InputDocument --- workflow/engine/bin/tasks/cliWorkspaces.php | 69 +++++++++++++++++++ workflow/engine/classes/class.wsTools.php | 47 ++++++++++++- workflow/engine/classes/model/Application.php | 14 ++-- .../engine/classes/model/InputDocument.php | 28 +++++--- 4 files changed, 139 insertions(+), 19 deletions(-) diff --git a/workflow/engine/bin/tasks/cliWorkspaces.php b/workflow/engine/bin/tasks/cliWorkspaces.php index 090860e6e..00c03db36 100755 --- a/workflow/engine/bin/tasks/cliWorkspaces.php +++ b/workflow/engine/bin/tasks/cliWorkspaces.php @@ -257,6 +257,19 @@ CLI::taskArg('workspace', true, true); CLI::taskRun("run_migrate_new_cases_lists"); /*----------------------------------********---------------------------------*/ +CLI::taskName('migrate-content'); +CLI::taskDescription(<<xssFilterHard($args); + $workspaces = get_workspaces_from_args($args); + foreach ($workspaces as $workspace) { + if (!defined('SYS_SYS')) { + define('SYS_SYS', $workspace->name); + } + print_r('Regenerating content in: ' . pakeColor::colorize($workspace->name, 'INFO') . "\n"); + migrate_content($workspace); + } +} + +function migrate_content($workspace) { + 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') + ) + ); + CLI::logging("-> Regenerating content \n"); + foreach ($content as $className => $fields) { + $workspace->migrateContent($className, $fields, $workspace->name); + } +} \ No newline at end of file diff --git a/workflow/engine/classes/class.wsTools.php b/workflow/engine/classes/class.wsTools.php index 78f1153ae..54ae4942d 100755 --- a/workflow/engine/classes/class.wsTools.php +++ b/workflow/engine/classes/class.wsTools.php @@ -3099,5 +3099,50 @@ class workspaceTools } return $response; } - + + /** + * Migrate this workspace table Content. + * + * @param $className + * @param $fields + * @param $workSpace + * @param mixed|string $sys_lang + * @throws Exception + */ + public function migrateContent($className, $fields, $workSpace, $sys_lang = SYS_LANG) + { + try { + $this->initPropel(true); + $_SESSION['sys_sys'] = $workSpace; + $fieldUidName = $fields['uid']; + $oCriteria = new Criteria(); + $oCriteria->clearSelectColumns(); + $oCriteria->addAsColumn($fieldUidName, ContentPeer::CON_ID); + $oCriteria->addSelectColumn(ContentPeer::CON_CATEGORY); + $oCriteria->addSelectColumn(ContentPeer::CON_VALUE); + $oCriteria->add(ContentPeer::CON_CATEGORY, $fields['fields'], Criteria::IN); + $oCriteria->add(ContentPeer::CON_LANG, $sys_lang); + $oDataset = ContentPeer::doSelectRS($oCriteria); + $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); + $methods = $fields['methods']; + while ($oDataset->next()) { + $row = $oDataset->getRow(); + $fieldName = $row['CON_CATEGORY']; + $fieldName = isset($fields['alias']) && isset($fields['alias'][$fieldName]) ? $fields['alias'][$fieldName] : $fieldName; + unset($row['CON_CATEGORY']); + $fieldValue = $row['CON_VALUE']; + unset($row['CON_VALUE']); + $row[$fieldName] = $fieldValue; + $oTable = new $className(); + $mExists = $methods['exists']; + if ($oTable->$mExists($row[$fieldUidName])){ + $oTable->update($row); + } + } + $classNamePeer = $className . 'Peer'; + CLI::logging("|--> Add content in table " . $classNamePeer::TABLE_NAME . "\n"); + } catch (Exception $e) { + throw ($e); + } + } } diff --git a/workflow/engine/classes/model/Application.php b/workflow/engine/classes/model/Application.php index 937cc48c6..cd3c53a43 100755 --- a/workflow/engine/classes/model/Application.php +++ b/workflow/engine/classes/model/Application.php @@ -62,7 +62,7 @@ class Application extends BaseApplication } if ($this->getAppUid() == '') { - throw (new Exception( "Error in getAppTitle, the APP_UID can't be blank")); + throw (new Exception( "Error in getAppTitleContent, the APP_UID can't be blank")); } $lang = defined('SYS_LANG')? SYS_LANG : 'en'; @@ -80,7 +80,7 @@ class Application extends BaseApplication public function setAppTitleContent($v) { if ($this->getAppUid() == '') { - throw (new Exception( "Error in setAppTitle, the APP_UID can't be blank")); + throw (new Exception( "Error in setAppTitleContent, the APP_UID can't be blank")); } //Since the native PHP type for this column is string, @@ -103,7 +103,7 @@ class Application extends BaseApplication public function getAppDescriptionContent() { if ($this->getAppUid() == '') { - throw (new Exception( "Error in getAppDescription, the APP_UID can't be blank")); + throw (new Exception( "Error in getAppDescriptionContent, the APP_UID can't be blank")); } $lang = defined('SYS_LANG')? SYS_LANG : 'en'; @@ -121,7 +121,7 @@ class Application extends BaseApplication public function setAppDescriptionContent($v) { if ($this->getAppUid() == '') { - throw ( new Exception( "Error in setAppTitle, the APP_UID can't be blank") ); + throw ( new Exception( "Error in setAppDescriptionContent, the APP_UID can't be blank") ); } // Since the native PHP type for this column is string, @@ -295,10 +295,10 @@ class Application extends BaseApplication if ($oApp->validate()) { if (isset($aData['APP_TITLE'])) { - $this->setAppTitleContent($aData['APP_TITLE']); + $oApp->setAppTitleContent($aData['APP_TITLE']); } if (isset($aData['APP_DESCRIPTION'])) { - $this->setAppDescriptionContent($aData['APP_DESCRIPTION']); + $oApp->setAppDescriptionContent($aData['APP_DESCRIPTION']); } //if ( isset ( $aData['APP_PROC_CODE'] ) ) @@ -311,7 +311,7 @@ class Application extends BaseApplication } else { $msg = ''; - foreach ($this->getValidationFailures() as $objValidationFailure) { + foreach ($oApp->getValidationFailures() as $objValidationFailure) { $msg .= $objValidationFailure->getMessage() . "
"; } diff --git a/workflow/engine/classes/model/InputDocument.php b/workflow/engine/classes/model/InputDocument.php index 2987077ed..1556a6ff7 100755 --- a/workflow/engine/classes/model/InputDocument.php +++ b/workflow/engine/classes/model/InputDocument.php @@ -197,23 +197,29 @@ class InputDocument extends BaseInputDocument $iResult = $oInputDocument->save(); $oConnection->commit(); //Add Audit Log - switch ($aData['INP_DOC_FORM_NEEDED']){ - case 'VIRTUAL': - $docType = 'Digital'; - break; - case 'REAL': - $docType = 'Printed'; - break; - case 'VREAL': - $docType = 'Digital/Printed'; - break; + $docType = ''; + if(!empty($aData['INP_DOC_FORM_NEEDED'])) { + switch ($aData['INP_DOC_FORM_NEEDED']) { + case 'VIRTUAL': + $docType = 'Digital'; + break; + case 'REAL': + $docType = 'Printed'; + break; + case 'VREAL': + $docType = 'Digital/Printed'; + break; + } } if(isset($aData['INP_DOC_VERSIONING']) && $aData['INP_DOC_VERSIONING'] == 1){ $enableVersion = 'Yes'; }else{ $enableVersion = 'No'; } - $description = "Input Document Title: ".$aData['INP_DOC_TITLE'].", Input Document Uid: ".$aData['INP_DOC_UID'].", Document Type: ".$docType; + $description = ''; + if (!empty( $aData['INP_DOC_TITLE'] )) { + $description = "Input Document Title: ".$aData['INP_DOC_TITLE'].", Input Document Uid: ".$aData['INP_DOC_UID'].", Document Type: ".$docType; + } if(!empty($aData['INP_DOC_DESCRIPTION'])){ $description .= ", Description: ".$aData['INP_DOC_DESCRIPTION']; }