Merge pull request #20115 from larssandergreen/fix-internal-anchor-URLs-in-mailings
[civicrm-core.git] / CRM / Logging / Schema.php
index 1deff564930c4faee67f465609bff4466c05918f..ad09e3a32c20431bbc7266fee8c543f441424377 100644 (file)
@@ -131,6 +131,15 @@ AND    TABLE_NAME LIKE 'civicrm_%'
     while ($dao->fetch()) {
       $this->tables[] = $dao->TABLE_NAME;
     }
+    // Get any non standard table names used for custom groups.
+    // include these BEFORE the hook is called.
+    $customFieldDAO = CRM_Core_DAO::executeQuery("
+      SELECT DISTINCT table_name as TABLE_NAME FROM civicrm_custom_group
+      where table_name NOT LIKE 'civicrm_%';
+    ");
+    while ($customFieldDAO->fetch()) {
+      $this->tables[] = $customFieldDAO->TABLE_NAME;
+    }
 
     // do not log temp import, cache, menu and log tables
     $this->tables = preg_grep('/^civicrm_import_job_/', $this->tables, PREG_GREP_INVERT);
@@ -226,7 +235,7 @@ AND    (TABLE_NAME LIKE 'log_civicrm_%' $nonStandardTableNameString )
    *
    * @param string $tableName
    */
-  public function dropTriggers($tableName = NULL) {
+  public function dropTriggers($tableName = NULL): void {
     /** @var \Civi\Core\SqlTriggers $sqlTriggers */
     $sqlTriggers = Civi::service('sql_triggers');
     $dao = new CRM_Core_DAO();
@@ -238,6 +247,9 @@ AND    (TABLE_NAME LIKE 'log_civicrm_%' $nonStandardTableNameString )
       $tableNames = $this->tables;
     }
 
+    // Sort the table names so the sql output is consistent for those sites
+    // loading it asynchronously (using the setting 'logging_no_trigger_permission')
+    asort($tableNames);
     foreach ($tableNames as $table) {
       $validName = CRM_Core_DAO::shortenSQLName($table, 48, TRUE);