FiveFortySeven - Leave `civigrant` inactive during inconsistent period
authorTim Otten <totten@civicrm.org>
Fri, 4 Mar 2022 00:37:38 +0000 (16:37 -0800)
committerTim Otten <totten@civicrm.org>
Fri, 4 Mar 2022 01:56:39 +0000 (17:56 -0800)
Before
------

`migrateCiviGrant()` migrates some metadata from core-ownership to
core-extension-ownership...  and it ALSO activates the extension.  However,
the extension depends on other (possibly-inactive) extensions.  This
creates an inconsistent state (where active parts of `civigrant`
depend on inactive parts of `search_kit`).

In this inconsistent state, `ManagedEntities::reconcile()` fails.

After
-----

`migrateCiviGrant()` still migrates metadata.  However, it initially leaves
the extension inactive.  So `ManagedEntities::reconcile()` won't try to
setup these records.

After core schema is fully resolved, then it installs all necessary
extensions using normal mechanisms (with normal ordering).

CRM/Upgrade/Incremental/php/FiveFortySeven.php

index 6ce55145ecccaaff9cd5fc97b4e03fdbd1b8fab9..4626507168890474ebfd0e002a98484a3a2c242c 100644 (file)
@@ -59,7 +59,7 @@ class CRM_Upgrade_Incremental_php_FiveFortySeven extends CRM_Upgrade_Incremental
     $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
     $this->addTask('Migrate CiviGrant component to an extension', 'migrateCiviGrant');
     if (CRM_Core_Component::isEnabled('CiviGrant')) {
-      $this->addExtensionTask('Enable CiviGrant dependencies', ['org.civicrm.search_kit', 'org.civicrm.afform']);
+      $this->addExtensionTask('Enable CiviGrant extension', ['civigrant']);
     }
     $this->addTask('Add created_date to civicrm_relationship', 'addColumn', 'civicrm_relationship', 'created_date',
       "timestamp NOT NULL  DEFAULT CURRENT_TIMESTAMP COMMENT 'Relationship created date'"
@@ -110,6 +110,9 @@ class CRM_Upgrade_Incremental_php_FiveFortySeven extends CRM_Upgrade_Incremental
       }
       CRM_Core_DAO::executeQuery("DELETE FROM civicrm_component WHERE name = 'CiviGrant'", [], TRUE, NULL, FALSE, FALSE);
     }
+
+    // There are existing records which should be managed by `civigrant`. To assign ownership, we need
+    // placeholders in `civicrm_extension` and `civicrm_managed`.
     $ext = new CRM_Core_DAO_Extension();
     $ext->full_name = 'civigrant';
     if (!$ext->find(TRUE)) {
@@ -117,8 +120,9 @@ class CRM_Upgrade_Incremental_php_FiveFortySeven extends CRM_Upgrade_Incremental
       $ext->name = 'CiviGrant';
       $ext->label = ts('CiviGrant');
       $ext->file = 'civigrant';
-      $ext->is_active = (int) $civiGrantEnabled;
+      $ext->is_active = 0; /* Not active _yet_. If site uses CiviGrant, we will re-activate once the core-schema has been revised. */
       $ext->save();
+      CRM_Extension_System::singleton()->getManager()->refresh();
 
       $managedItems = [
         'OptionGroup_advanced_search_options_OptionValue_CiviGrant' => [