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
This commit is contained in:
qronald
2016-07-07 14:25:04 -04:00
committed by Ronald Q
parent 8116ea4b3b
commit 60f9a8e094
4 changed files with 139 additions and 19 deletions

View File

@@ -257,6 +257,19 @@ CLI::taskArg('workspace', true, true);
CLI::taskRun("run_migrate_new_cases_lists"); CLI::taskRun("run_migrate_new_cases_lists");
/*----------------------------------********---------------------------------*/ /*----------------------------------********---------------------------------*/
CLI::taskName('migrate-content');
CLI::taskDescription(<<<EOT
Migrating the content schema to match the latest version
  Specify the WORKSPACE to migrate from a existing workspace.
If no workspace is specified, then the tables schema will be upgraded or
migrate on all available workspaces.
EOT
);
CLI::taskArg('workspace', true, true);
CLI::taskRun("run_migrate_content");
/** /**
* Function run_info * Function run_info
* access public * access public
@@ -811,3 +824,59 @@ function migrate_counters($command, $args) {
} }
/*----------------------------------********---------------------------------*/ /*----------------------------------********---------------------------------*/
function run_migrate_content($args) {
G::LoadSystem('inputfilter');
$filter = new InputFilter();
$args = $filter->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);
}
}

View File

@@ -3100,4 +3100,49 @@ class workspaceTools
return $response; 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);
}
}
} }

View File

@@ -62,7 +62,7 @@ class Application extends BaseApplication
} }
if ($this->getAppUid() == '') { 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'; $lang = defined('SYS_LANG')? SYS_LANG : 'en';
@@ -80,7 +80,7 @@ class Application extends BaseApplication
public function setAppTitleContent($v) public function setAppTitleContent($v)
{ {
if ($this->getAppUid() == '') { 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, //Since the native PHP type for this column is string,
@@ -103,7 +103,7 @@ class Application extends BaseApplication
public function getAppDescriptionContent() public function getAppDescriptionContent()
{ {
if ($this->getAppUid() == '') { 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'; $lang = defined('SYS_LANG')? SYS_LANG : 'en';
@@ -121,7 +121,7 @@ class Application extends BaseApplication
public function setAppDescriptionContent($v) public function setAppDescriptionContent($v)
{ {
if ($this->getAppUid() == '') { 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, // Since the native PHP type for this column is string,
@@ -295,10 +295,10 @@ class Application extends BaseApplication
if ($oApp->validate()) { if ($oApp->validate()) {
if (isset($aData['APP_TITLE'])) { if (isset($aData['APP_TITLE'])) {
$this->setAppTitleContent($aData['APP_TITLE']); $oApp->setAppTitleContent($aData['APP_TITLE']);
} }
if (isset($aData['APP_DESCRIPTION'])) { if (isset($aData['APP_DESCRIPTION'])) {
$this->setAppDescriptionContent($aData['APP_DESCRIPTION']); $oApp->setAppDescriptionContent($aData['APP_DESCRIPTION']);
} }
//if ( isset ( $aData['APP_PROC_CODE'] ) ) //if ( isset ( $aData['APP_PROC_CODE'] ) )
@@ -311,7 +311,7 @@ class Application extends BaseApplication
} else { } else {
$msg = ''; $msg = '';
foreach ($this->getValidationFailures() as $objValidationFailure) { foreach ($oApp->getValidationFailures() as $objValidationFailure) {
$msg .= $objValidationFailure->getMessage() . "<br/>"; $msg .= $objValidationFailure->getMessage() . "<br/>";
} }

View File

@@ -197,23 +197,29 @@ class InputDocument extends BaseInputDocument
$iResult = $oInputDocument->save(); $iResult = $oInputDocument->save();
$oConnection->commit(); $oConnection->commit();
//Add Audit Log //Add Audit Log
switch ($aData['INP_DOC_FORM_NEEDED']){ $docType = '';
case 'VIRTUAL': if(!empty($aData['INP_DOC_FORM_NEEDED'])) {
$docType = 'Digital'; switch ($aData['INP_DOC_FORM_NEEDED']) {
break; case 'VIRTUAL':
case 'REAL': $docType = 'Digital';
$docType = 'Printed'; break;
break; case 'REAL':
case 'VREAL': $docType = 'Printed';
$docType = 'Digital/Printed'; break;
break; case 'VREAL':
$docType = 'Digital/Printed';
break;
}
} }
if(isset($aData['INP_DOC_VERSIONING']) && $aData['INP_DOC_VERSIONING'] == 1){ if(isset($aData['INP_DOC_VERSIONING']) && $aData['INP_DOC_VERSIONING'] == 1){
$enableVersion = 'Yes'; $enableVersion = 'Yes';
}else{ }else{
$enableVersion = 'No'; $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'])){ if(!empty($aData['INP_DOC_DESCRIPTION'])){
$description .= ", Description: ".$aData['INP_DOC_DESCRIPTION']; $description .= ", Description: ".$aData['INP_DOC_DESCRIPTION'];
} }