Upgrader - Enqueue extension upgrade tasks
authorTim Otten <totten@civicrm.org>
Wed, 1 Jun 2022 21:10:22 +0000 (14:10 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 20 Jul 2022 20:36:55 +0000 (13:36 -0700)
CRM/Upgrade/Form.php

index 051a259164618299f34c44c17f62e30d1000d62b..9bd995ffa1d72ee95cd46e7c8c2439cd23a0f9a2 100644 (file)
@@ -599,6 +599,14 @@ SET    version = '$version'
     );
     $queue->createItem($task, ['weight' => 1000]);
 
+    $task = new CRM_Queue_Task(
+      ['CRM_Upgrade_Form', 'enqueueExtUpgrades'],
+      [$rev, $latestVer, $latestVer, $postUpgradeMessageFile],
+      "Assess extension upgrades"
+    );
+    // This places the extension-upgrades after `doCoreFinish` - but before new extensions (`addExtensionTask()`)
+    $queue->createItem($task, ['weight' => 1500]);
+
     return $queue;
   }
 
@@ -831,6 +839,23 @@ SET    version = '$version'
     return TRUE;
   }
 
+  /**
+   * After core schema is up-to-date, ensure that
+   * @param \CRM_Queue_TaskContext $ctx
+   * @return bool
+   */
+  public static function enqueueExtUpgrades(CRM_Queue_TaskContext $ctx): bool {
+    CRM_Core_Config::singleton(TRUE, TRUE);
+    CRM_Upgrade_DispatchPolicy::assertActive('upgrade.finish');
+    if (CRM_Extension_Upgrades::hasPending()) {
+      CRM_Extension_Upgrades::fillQueue($ctx->queue);
+      // ISSUE: Core-upgrade tasks and ext-upgrade tasks need to run with different `DispatchPolicy`s
+      // (`upgrade.main` vs `upgrade.finish` or `NULL`).
+      // Can we make policy transitions sticky -- eg maybe a setting or session-variable?
+    }
+    return TRUE;
+  }
+
   /**
    * After finishing the queue, the upgrade-runner calls `doFinish()`.
    *