Skip to content
Snippets Groups Projects
Unverified Commit 9658bf9b authored by mattwire's avatar mattwire Committed by GitHub
Browse files

Merge pull request #21389 from seamuslee001/relationship_cache_table_fix

[REF] Add in upgrade step to align the relationship cache table colla…
parents be16c5ef f210208f
No related branches found
No related tags found
No related merge requests found
......@@ -55,21 +55,29 @@ class CRM_Upgrade_Incremental_php_FiveFortyThree extends CRM_Upgrade_Incremental
* (change the x in the function name):
*/
// /**
// * Upgrade function.
// *
// * @param string $rev
// */
// public function upgrade_5_0_x($rev) {
// $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
// $this->addTask('Do the foo change', 'taskFoo', ...);
// // Additional tasks here...
// // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex.
// // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable.
// }
/**
* Upgrade function.
*
* @param string $rev
*/
public function upgrade_5_43_alpha1($rev) {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addTask('Fix DB Collation if needed on the relatonship cache table', 'fixRelationshipCacheTableCollation');
}
// public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) {
// return TRUE;
// }
public static function fixRelationshipCacheTableCollation():bool {
$contactTableCollation = CRM_Core_BAO_SchemaHandler::getInUseCollation();
$dao = CRM_Core_DAO::executeQuery('SHOW TABLE STATUS LIKE \'civicrm_relationship_cache\'');
$dao->fetch();
$relationshipCacheCollation = $dao->Collation;
$characterSet = 'utf8';
if (stripos($contactTableCollation, 'utf8mb4') !== FALSE) {
$characterSet = 'utf8mb4';
}
if ($contactTableCollation !== $relationshipCacheCollation) {
CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_relationship_cache ENGINE=InnoDB DEFAULT CHARACTER SET ' . $characterSet . ' COLLATE ' . $contactTableCollation);
}
return TRUE;
}
}
......@@ -738,4 +738,14 @@ class CRM_Upgrade_Incremental_BaseTest extends CiviUnitTestCase {
$this->callAPISuccess('ContactType', 'delete', ['id' => $contactType['id']]);
}
public function testUpdateRelationshipCacheTable() {
CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_relationship_cache DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
CRM_Upgrade_Incremental_php_FiveFortyThree::fixRelationshipCacheTableCollation();
$contactTableCollation = CRM_Core_BAO_SchemaHandler::getInUseCollation();
$dao = CRM_Core_DAO::executeQuery('SHOW TABLE STATUS LIKE \'civicrm_relationship_cache\'');
$dao->fetch();
$relationshipCacheCollation = $dao->Collation;
$this->assertEquals($contactTableCollation, $relationshipCacheCollation);
}
}
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