diff --git a/data/CRMEntity.php b/data/CRMEntity.php index ac5e74d8afa5cee6ad0f854325c1591f8073104f..49045999cfe143d9e5660ff73ba16541b6e55b6d 100755 --- a/data/CRMEntity.php +++ b/data/CRMEntity.php @@ -85,7 +85,7 @@ class CRMEntity { return; } - $userSpecificTableIgnoredModules = array("SMSNotifier", "ModComments"); + $userSpecificTableIgnoredModules = array('SMSNotifier', 'PBXManager', 'ModComments'); if(in_array($moduleName, $userSpecificTableIgnoredModules)) return; $userSpecificTable = Vtiger_Functions::getUserSpecificTableName($moduleName); diff --git a/modules/Migration/schema/701_to_710.php b/modules/Migration/schema/701_to_710.php index f0b0c03c289ad44fbfe032d21145b13852a248ae..2c2ff3de0c73c367d1281f47f83fae3eed680ef2 100644 --- a/modules/Migration/schema/701_to_710.php +++ b/modules/Migration/schema/701_to_710.php @@ -171,11 +171,50 @@ if (defined('VTIGER_UPGRADE')) { //START::Google calendar sync settings if (!Vtiger_Utils::CheckTable('vtiger_google_event_calendar_mapping')) { - $db->pquery('CREATE TABLE vtiger_google_event_calendar_mapping (event_id varchar(255) DEFAULT NULL, calendar_id varchar(255) DEFAULT NULL, user_id int(11) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8', array()); + $db->pquery('CREATE TABLE vtiger_google_event_calendar_mapping (event_id VARCHAR(255) DEFAULT NULL, calendar_id VARCHAR(255) DEFAULT NULL, user_id INT(11) NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8', array()); echo '<br>Succecssfully vtiger_google_event_calendar_mapping table created<br>'; } //END::Google calendar sync settings + //START::Centralize user field table for easy query with context of user across module + $generalUserFieldTable = 'vtiger_crmentity_user_field'; + if (!Vtiger_Utils::CheckTable($generalUserFieldTable)) { + Vtiger_Utils::CreateTable($generalUserFieldTable, + '(`recordid` INT(19) NOT NULL, + `userid` INT(19) NOT NULL, + `starred` VARCHAR(100) DEFAULT NULL, + Index `record_user_idx` (`recordid`, `userid`), + FOREIGN KEY (recordid) REFERENCES vtiger_crmentity(crmid) ON DELETE CASCADE)', true); + } + + $migratedTables = array(); + $result = $db->pquery('SELECT vtiger_tab.tabid, vtiger_tab.name, tablename, fieldid FROM vtiger_field INNER JOIN vtiger_tab ON vtiger_tab.tabid=vtiger_field.tabid WHERE fieldname=?', array('starred')); + while ($row = $db->fetch_array($result)) { + $fieldId = $row['fieldid']; + $moduleName = $row['name']; + $oldTableName = $row['tablename']; + + $db->pquery('UPDATE vtiger_field SET tablename=? WHERE fieldid=? AND tablename=?', array($generalUserFieldTable, $fieldId, $oldTableName)); + echo "Updated starred field for module $moduleName to point generic table => $generalUserFieldTable<br>"; + + if (Vtiger_Utils::CheckTable($oldTableName)) { + if (!in_array($oldTableName, $migratedTables)) { + if ($oldTableName != $generalUserFieldTable) { + //Insert entries from module specific table to generic table for follow up records + $db->pquery("INSERT INTO $generalUserFieldTable (recordid, userid, starred) (SELECT recordid,userid,starred FROM $oldTableName INNER JOIN vtiger_crmentity ON $oldTableName.recordid = vtiger_crmentity.crmid)", array()); + echo "entries moved from $oldTableName to $generalUserFieldTable table<br>"; + + //Drop module specific user table + $db->pquery("DROP TABLE $oldTableName", array()); + echo "module specific user field table $oldTableName has been dropped<br>"; + array_push($migratedTables, $oldTableName); + } + } + } + } + echo '<br>Succesfully centralize user field table for easy query with context of user across module<br>'; + //END::Centralize user field table for easy query with context of user across module + //Update existing package modules Install_Utils_Model::installModules(); diff --git a/vtlib/Vtiger/Functions.php b/vtlib/Vtiger/Functions.php index 0f6fee2d1855f8fcba793490b138c1a5a8b15d94..1cfecae8c9be54549e2715f5840946ec4bdb952b 100644 --- a/vtlib/Vtiger/Functions.php +++ b/vtlib/Vtiger/Functions.php @@ -1320,11 +1320,7 @@ class Vtiger_Functions { * @return type -- table name */ public static function getUserSpecificTableName($moduleName) { - $moduleName = strtolower($moduleName); - if ($moduleName == "events") { - $moduleName = "calendar"; - } - return "vtiger_".$moduleName.'_user_field'; + return 'vtiger_crmentity_user_field'; } /**