Replace hard-coded utf8_bin with binary in-use collation
authorRich Lott / Artful Robot <forums@artfulrobot.uk>
Tue, 13 Oct 2020 09:39:35 +0000 (10:39 +0100)
committerRich Lott / Artful Robot <forums@artfulrobot.uk>
Tue, 13 Oct 2020 09:39:35 +0000 (10:39 +0100)
CRM/Contact/BAO/RelationshipCache.php

index edb76cd1dba402000a508a3582b26162c474a32d..c1483973e8120dfed4339228f97e1d4777a486aa 100644 (file)
@@ -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