From: Tim Otten Date: Tue, 19 Apr 2016 03:22:28 +0000 (-0700) Subject: CRM-18212 - Use SqlTriggers::enqueueQuery() instead of DAO::executeQuery() X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=7a29e4556fcb32104e8724d4e8d938d126f91c82;p=civicrm-core.git CRM-18212 - Use SqlTriggers::enqueueQuery() instead of DAO::executeQuery() --- diff --git a/CRM/Logging/Schema.php b/CRM/Logging/Schema.php index 959b1a1326..6d0248470f 100644 --- a/CRM/Logging/Schema.php +++ b/CRM/Logging/Schema.php @@ -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}"); } } } diff --git a/Civi/Core/SqlTriggers.php b/Civi/Core/SqlTriggers.php index 9621f1c819..64e8ea7cef 100644 --- a/Civi/Core/SqlTriggers.php +++ b/Civi/Core/SqlTriggers.php @@ -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); } } }