From 1d53963979d06973aec35dc999d8ecb09ab105ad Mon Sep 17 00:00:00 2001 From: Rich Lott / Artful Robot Date: Tue, 13 Oct 2020 10:39:35 +0100 Subject: [PATCH] Replace hard-coded utf8_bin with binary in-use collation --- CRM/Contact/BAO/RelationshipCache.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CRM/Contact/BAO/RelationshipCache.php b/CRM/Contact/BAO/RelationshipCache.php index edb76cd1db..c1483973e8 100644 --- a/CRM/Contact/BAO/RelationshipCache.php +++ b/CRM/Contact/BAO/RelationshipCache.php @@ -71,6 +71,9 @@ class CRM_Contact_BAO_RelationshipCache extends CRM_Contact_DAO_RelationshipCach */ public static function onHookTriggerInfo($e) { $relUpdates = self::createInsertUpdateQueries(); + // Use utf8mb4_bin or utf8_bin, depending on what's in use. + $collation = preg_replace('/^(utf8(?:mb4)?)_.*$/', '$1_bin', CRM_Core_BAO_SchemaHandler::getInUseCollation()); + foreach ($relUpdates as $relUpdate) { /** * This trigger runs whenever a "civicrm_relationship" record is inserted or updated. @@ -97,8 +100,8 @@ class CRM_Contact_BAO_RelationshipCache extends CRM_Contact_DAO_RelationshipCach 'sql' => sprintf("\nIF (%s) THEN\n %s;\n END IF;\n", // Condition - implode(' OR ', array_map(function ($col) { - return "(OLD.$col != NEW.$col COLLATE utf8_bin)"; + implode(' OR ', array_map(function ($col) use ($collation) { + return "(OLD.$col != NEW.$col COLLATE $collation)"; }, self::$relTypeWatchFields)), // Action -- 2.25.1