CRM-18212 - Use SqlTriggers::enqueueQuery() instead of DAO::executeQuery()
authorTim Otten <totten@civicrm.org>
Tue, 19 Apr 2016 03:22:28 +0000 (20:22 -0700)
committerTim Otten <totten@civicrm.org>
Tue, 19 Apr 2016 05:02:10 +0000 (22:02 -0700)
CRM/Logging/Schema.php
Civi/Core/SqlTriggers.php

index 959b1a1326b756abc6010618fbd86afa0e6ada3e..6d0248470fcb7789ce32f7987aeefe3c5c48a0b6 100644 (file)
@@ -205,6 +205,8 @@ AND    TABLE_NAME LIKE 'log_civicrm_%'
    * @param string $tableName
    */
   public function dropTriggers($tableName = NULL) {
+    /** @var \Civi\Core\SqlTriggers $sqlTriggers */
+    $sqlTriggers = Civi::service('sql_triggers');
     $dao = new CRM_Core_DAO();
 
     if ($tableName) {
@@ -218,14 +220,14 @@ AND    TABLE_NAME LIKE 'log_civicrm_%'
       $validName = CRM_Core_DAO::shortenSQLName($table, 48, TRUE);
 
       // before triggers
-      $dao->executeQuery("DROP TRIGGER IF EXISTS {$validName}_before_insert");
-      $dao->executeQuery("DROP TRIGGER IF EXISTS {$validName}_before_update");
-      $dao->executeQuery("DROP TRIGGER IF EXISTS {$validName}_before_delete");
+      $sqlTriggers->enqueueQuery("DROP TRIGGER IF EXISTS {$validName}_before_insert");
+      $sqlTriggers->enqueueQuery("DROP TRIGGER IF EXISTS {$validName}_before_update");
+      $sqlTriggers->enqueueQuery("DROP TRIGGER IF EXISTS {$validName}_before_delete");
 
       // after triggers
-      $dao->executeQuery("DROP TRIGGER IF EXISTS {$validName}_after_insert");
-      $dao->executeQuery("DROP TRIGGER IF EXISTS {$validName}_after_update");
-      $dao->executeQuery("DROP TRIGGER IF EXISTS {$validName}_after_delete");
+      $sqlTriggers->enqueueQuery("DROP TRIGGER IF EXISTS {$validName}_after_insert");
+      $sqlTriggers->enqueueQuery("DROP TRIGGER IF EXISTS {$validName}_after_update");
+      $sqlTriggers->enqueueQuery("DROP TRIGGER IF EXISTS {$validName}_after_delete");
     }
 
     // now lets also be safe and drop all triggers that start with
@@ -236,9 +238,7 @@ AND    TABLE_NAME LIKE 'log_civicrm_%'
       $triggers = $dao->executeQuery("SHOW TRIGGERS LIKE 'civicrm_%'");
 
       while ($triggers->fetch()) {
-        // note that drop trigger has a weird syntax and hence we do not
-        // send the trigger name as a string (i.e. its not quoted
-        $dao->executeQuery("DROP TRIGGER IF EXISTS {$triggers->Trigger}");
+        $sqlTriggers->enqueueQuery("DROP TRIGGER IF EXISTS {$triggers->Trigger}");
       }
     }
   }
index 9621f1c819e134523b3d697c8bb13cd244aa0695..64e8ea7cef11caaf91e023e2f20dc203886e6a46 100644 (file)
@@ -167,15 +167,8 @@ class SqlTriggers {
           $triggerName = "{$validName}_{$whenName}_{$eventName}";
           $triggerSQL = "CREATE TRIGGER $triggerName $whenName $eventName ON $tableName FOR EACH ROW BEGIN $varString $sqlString END";
 
-          \CRM_Core_DAO::executeQuery("DROP TRIGGER IF EXISTS $triggerName");
-          \CRM_Core_DAO::executeQuery(
-            $triggerSQL,
-            array(),
-            TRUE,
-            NULL,
-            FALSE,
-            FALSE
-          );
+          $this->enqueueQuery("DROP TRIGGER IF EXISTS $triggerName");
+          $this->enqueueQuery($triggerSQL);
         }
       }
     }