diff --git a/modules/Migration/schema/701_to_710.php b/modules/Migration/schema/701_to_710.php index a08b053c50791a835fa8a1af01822df27d9308f9..7bfed2c07c4d80db698d530c4f11edadf79dd220 100644 --- a/modules/Migration/schema/701_to_710.php +++ b/modules/Migration/schema/701_to_710.php @@ -342,7 +342,7 @@ if (defined('VTIGER_UPGRADE')) { } //END::Supporting to store dashboard size - //START:Profile save failures because of Reports module + //START::Profile save failures because of Reports module entry is not available in the vtiger_profile2standardpermissions $query = 'SELECT DISTINCT profileid FROM vtiger_profile'; $result = $adb->pquery($query, array()); @@ -369,7 +369,69 @@ if (defined('VTIGER_UPGRADE')) { } } } - //END:Profile save failures because of Reports module + //END::Profile save failures because of Reports module entry is not available in the vtiger_profile2standardpermissions + + //START::Updating custom view and report columns, filters for createdtime and modifiedtime fields as typeofdata (T~...) is being transformed to (DT~...) + $cvTables = array('vtiger_cvcolumnlist', 'vtiger_cvadvfilter'); + foreach ($cvTables as $tableName) { + $updatedColumnsList = array(); + $result = $db->pquery("SELECT columnname FROM $tableName WHERE columnname LIKE ? OR columnname LIKE ?", array('vtiger_crmentity:createdtime%:T', 'vtiger_crmentity:modifiedtime%:T')); + while ($rowData = $db->fetch_array($result)) { + $columnName = $rowData['columnname']; + if (!array_key_exists($columnName, $updatedColumnsList)) { + if (preg_match('/vtiger_crmentity:createdtime:(\w*\:)*T/', $columnName) || preg_match('/vtiger_crmentity:modifiedtime:(\w*\:)*T/', $columnName)) { + $columnParts = explode(':', $columnName); + $lastKey = count($columnParts)-1; + + if ($columnParts[$lastKey] == 'T') { + $columnParts[$lastKey] = 'DT'; + $updatedColumnsList[$columnName] = implode(':', $columnParts); + } + } + } + } + + if ($updatedColumnsList) { + $cvQuery = "UPDATE $tableName SET columnname = CASE columnname"; + foreach ($updatedColumnsList as $oldColumnName => $newColumnName) { + $cvQuery .= " WHEN '$oldColumnName' THEN '$newColumnName'"; + } + $cvQuery .= ' ELSE columnname END'; + } + $db->pquery($cvQuery, array()); + echo "<br>Succecssfully migrated columns in <b>$tableName</b> table<br>"; + } + + $reportTables = array('vtiger_selectcolumn', 'vtiger_relcriteria'); + foreach ($reportTables as $tableName) { + $updatedColumnsList = array(); + $result = $db->pquery("SELECT columnname FROM $tableName WHERE columnname LIKE ? OR columnname LIKE ?", array('vtiger_crmentity%:createdtime:%T', 'vtiger_crmentity%:modifiedtime:%T')); + while ($rowData = $db->fetch_array($result)) { + $columnName = $rowData['columnname']; + if (!array_key_exists($columnName, $updatedColumnsList)) { + if (preg_match('/vtiger_crmentity(\w*):createdtime:(\w*\:)*T/', $columnName) || preg_match('/vtiger_crmentity(\w*):modifiedtime:(\w*\:)*T/', $columnName)) { + $columnParts = explode(':', $columnName); + $lastKey = count($columnParts)-1; + + if ($columnParts[$lastKey] == 'T') { + $columnParts[$lastKey] = 'DT'; + $updatedColumnsList[$columnName] = implode(':', $columnParts); + } + } + } + } + + if ($updatedColumnsList) { + $reportQuery = "UPDATE $tableName SET columnname = CASE columnname"; + foreach ($updatedColumnsList as $oldColumnName => $newColumnName) { + $reportQuery .= " WHEN '$oldColumnName' THEN '$newColumnName'"; + } + $reportQuery .= ' ELSE columnname END'; + } + $db->pquery($reportQuery, array()); + echo "<br>Succecssfully migrated columns in <b>$tableName</b> table<br>"; + } + //END::Updating custom view and report columns, filters for createdtime and modifiedtime fields as typeofdata (T~...) is being transformed to (DT~...) //Update existing package modules Install_Utils_Model::installModules();