dev/core#4116 Add in rebuilding log table schema when modifying schema
authorSeamus Lee <seamuslee001@gmail.com>
Sat, 11 Feb 2023 05:14:19 +0000 (16:14 +1100)
committerSeamus Lee <seamuslee001@gmail.com>
Sat, 11 Feb 2023 05:20:42 +0000 (16:20 +1100)
Only rebuild if logging is enabled

CRM/Upgrade/Incremental/Base.php

index 2dc039a4bd20c86758ce7b25ea80f3792a5ef77b..7e6f85142a72db9679be2b8fb0ef14414a6b5ffc 100644 (file)
@@ -225,7 +225,9 @@ class CRM_Upgrade_Incremental_Base {
     // Hrm, `enable()` normally does these things... but not during upgrade...
     // Note: A good test-scenario is to install 5.45; enable logging and CiviGrant; disable searchkit+afform; then upgrade to 5.47.
     $schema = new CRM_Logging_Schema();
-    $schema->fixSchemaDifferences();
+    if ($schema->isEnabled()) {
+      $schema->fixSchemaDifferences();
+    }
 
     CRM_Core_Invoke::rebuildMenuAndCaches(FALSE, FALSE);
     // sessionReset is FALSE because upgrade status/postUpgradeMessages are needed by the page. We reset later in doFinish().
@@ -299,6 +301,10 @@ class CRM_Upgrade_Incremental_Base {
       foreach ($queries as $query) {
         CRM_Core_DAO::executeQuery($query, [], TRUE, NULL, FALSE, FALSE);
       }
+      $schema = new CRM_Logging_Schema();
+      if ($schema->isEnabled()) {
+        $schema->fixSchemaDifferencesFor($table);
+      }
     }
     if ($locales && $triggerRebuild) {
       CRM_Core_I18n_Schema::rebuildMultilingualSchema($locales, $version, TRUE);
@@ -517,6 +523,10 @@ class CRM_Upgrade_Incremental_Base {
       CRM_Core_DAO::executeQuery("ALTER TABLE `$table` DROP COLUMN `$column`",
         [], TRUE, NULL, FALSE, FALSE);
     }
+    $schema = new CRM_Logging_Schema();
+    if ($schema->isEnabled()) {
+      $schema->fixSchemaDifferencesFor($table);
+    }
     return TRUE;
   }
 
@@ -599,6 +609,10 @@ class CRM_Upgrade_Incremental_Base {
     foreach ($queries as $query) {
       CRM_Core_DAO::executeQuery($query, [], TRUE, NULL, FALSE, FALSE);
     }
+    $schema = new CRM_Logging_Schema();
+    if ($schema->isEnabled()) {
+      $schema->fixSchemaDifferencesFor($table);
+    }
     return TRUE;
   }