Skip to content
Snippets Groups Projects
Commit 7f1204e6 authored by deepak-srivastava's avatar deepak-srivastava
Browse files

Merge pull request #1705 from ravishnair/CRM-13417fix

-- fix for CRM-13417
parents 79828a2d b0c27559
Branches
Tags
No related merge requests found
......@@ -237,6 +237,8 @@ UPDATE civicrm_dedupe_rule_group
$substrLenghts = array();
$tables = array();
$daoObj = new CRM_Core_DAO();
$database = $daoObj->database();
for ($count = 0; $count < self::RULES_COUNT; $count++) {
if (!CRM_Utils_Array::value("where_$count", $values)) {
continue;
......@@ -265,6 +267,23 @@ UPDATE civicrm_dedupe_rule_group
if (!isset($substrLenghts[$table])) {
$substrLenghts[$table] = array();
}
//CRM-13417 to avoid fatal error "Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys, 1089"
$schemaQuery = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = '{$database}' AND
TABLE_NAME = '{$table}' AND COLUMN_NAME = '{$field}';";
$dao = CRM_Core_DAO::executeQuery($schemaQuery);
if ($dao->fetch()) {
// set the length to null for all the fields where prefix length is not supported. eg. int,tinyint,date,enum etc dataTypes.
if ($dao->COLUMN_NAME == $field && !in_array($dao->DATA_TYPE, array('char', 'varchar', 'binary', 'varbinary', 'text', 'blob'))) {
$length = NULL;
}
elseif ($dao->COLUMN_NAME == $field && !empty($dao->CHARACTER_MAXIMUM_LENGTH) && ($length > $dao->CHARACTER_MAXIMUM_LENGTH)) {
//set the length to CHARACTER_MAXIMUM_LENGTH in case the length provided by the user is greater than the limit
$length = $dao->CHARACTER_MAXIMUM_LENGTH;
}
}
$substrLenghts[$table][$field] = $length;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment