Skip to content
Snippets Groups Projects
Commit 9804f787 authored by Prasad's avatar Prasad
Browse files

Fixes #1094::Uma::Migration code updated to move tags from custom table to base table

parents feb48145 07cdc622
No related branches found
No related tags found
No related merge requests found
...@@ -81,23 +81,30 @@ if (defined('VTIGER_UPGRADE')) { ...@@ -81,23 +81,30 @@ if (defined('VTIGER_UPGRADE')) {
//START::Tag fields are pointed to cf table for the modules Assets, Services etc.. //START::Tag fields are pointed to cf table for the modules Assets, Services etc..
$fieldName = 'tags'; $fieldName = 'tags';
$moduleModels = Vtiger_Module_Model::getAll(); $moduleModels = Vtiger_Module_Model::getAll();
foreach ($moduleModels as $moduleModel) { $restrictedModules = array('Dashboard', 'Home', 'Rss', 'Portal', 'Webmails', 'Import');
$baseTableId = $moduleModel->basetableid; foreach ($moduleModels as $moduleModel) {
if ($baseTableId) { if(in_array($moduleModel->getName(), $restrictedModules)) {
$baseTableName = $moduleModel->basetable; continue;
$customTableName = $baseTableName.'cf'; }
$customTableColumns = $db->getColumnNames($customTableName); $moduleClass = CRMEntity::getInstance($moduleModel->getName());
if (in_array($fieldName, $customTableColumns)) { $baseTableId = $moduleClass->table_index;
$fieldModel = Vtiger_Field_Model::getInstance($fieldName, $moduleModel); if ($baseTableId) {
$db->pquery("UPDATE vtiger_field SET tablename=? WHERE fieldid=?", array($baseTableName, $fieldModel->id)); $baseTableName = $moduleClass->table_name;
$db->pquery("ALTER TABLE $baseTableName ADD COLUMN $fieldName VARCHAR(1)", array()); $customTable = $moduleClass->customFieldTable;
$customTableName = $customTable[0];
$db->pquery("UPDATE $baseTableName, $customTableName SET $baseTableName.tags=$customTableName.tags WHERE $baseTableName.$baseTableId=$customTableName.$baseTableId", array()); $customTableId = $customTable[1];
$db->pquery("ALTER TABLE $customTableName DROP COLUMN $fieldName", array()); $customTableColumns = $db->getColumnNames($customTableName);
} if (in_array($fieldName, $customTableColumns)) {
} $fieldModel = Vtiger_Field_Model::getInstance($fieldName, $moduleModel);
} $db->pquery("UPDATE vtiger_field SET tablename=? WHERE fieldid=?", array($baseTableName, $fieldModel->id));
$db->pquery("ALTER TABLE $baseTableName ADD COLUMN $fieldName VARCHAR(1)", array());
$db->pquery("UPDATE $baseTableName, $customTableName SET $baseTableName.tags=$customTableName.tags WHERE $baseTableName.$baseTableId=$customTableName.$customTableId", array());
$db->pquery("ALTER TABLE $customTableName DROP COLUMN $fieldName", array());
}
}
}
echo '<br>Succecssfully generalized tag fields<br>'; echo '<br>Succecssfully generalized tag fields<br>';
//END::Tag fields are pointed to cf table for the modules Assets, Services etc.. //END::Tag fields are pointed to cf table for the modules Assets, Services etc..
......
  • Alan Lord @lord_alan ·
    Contributor

    @uma.s

    One other thing you might want to change in piece of code is the initial Vtiger_Module_Model::getAll(); call.

    As far as I understand it, tags are only relevant to entity modules so using Vtiger_Module_Model::getEntityModules(); would reduce the number of iterations which the foreach loop has to check.

    In my own scripts I use the getEntityModules() method and I also added a short test for the class file before calling $moduleClass = CRMEntity::getInstance($moduleModel->getName());:

    if(!class_exists($moduleName)) {
        continue;
    }

    I could probably remove the $restrictedModules test completely with these changes...

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment