Merge remote-tracking branch 'origin/5.52' into master-552
authorTim Otten <totten@civicrm.org>
Wed, 27 Jul 2022 23:39:17 +0000 (16:39 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 27 Jul 2022 23:39:17 +0000 (16:39 -0700)
1  2 
CRM/Upgrade/Form.php

index 9bd995ffa1d72ee95cd46e7c8c2439cd23a0f9a2,4d950c66ac37eecafa10c53399f039c3ce5415a1..2627f28c298c0e794b0e771a032eb51eee5474fe
@@@ -599,14 -599,13 +599,21 @@@ 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]);
 +
+     $task = new CRM_Queue_Task(
+       ['CRM_Upgrade_Form', 'doFinalMessages'],
+       [$currentVer, $latestVer, $postUpgradeMessageFile],
+       'Generate final messages'
+     );
+     $queue->createItem($task, ['weight' => 3000]);
      return $queue;
    }
  
      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;
 +  }
 +
+   /**
+    * Generate any standard post-upgrade messages (which are not version-specific).
+    *
+    * @param \CRM_Queue_TaskContext $ctx
+    * @param string $originalVer
+    *   the original revision.
+    * @param string $latestVer
+    *   the target (final) revision.
+    * @param string $postUpgradeMessageFile
+    *   path of a modifiable file which lists the post-upgrade messages.
+    *
+    * @return bool
+    */
+   public static function doFinalMessages(CRM_Queue_TaskContext $ctx, $originalVer, $latestVer, $postUpgradeMessageFile): bool {
+     // NOTE: This step should be automated circa 5.53.
+     $originalMajorMinor = array_slice(explode('.', $originalVer), 0, 2);
+     $latestMajorMinor = array_slice(explode('.', $latestVer), 0, 2);
+     if ($originalMajorMinor !== $latestMajorMinor) {
+       file_put_contents($postUpgradeMessageFile,
+         '<br/><br/>' . ts('<strong>WARNING</strong>: Core extensions may also require database updates. Please <a %1>execute extension updates</a> immediately.', [
+           1 => sprintf('href="%s" target="_blank" ', CRM_Utils_System::url('civicrm/admin/extensions/upgrade', 'reset=1', TRUE)),
+         ]),
+         FILE_APPEND
+       );
+     }
+     return TRUE;
+   }
    /**
     * After finishing the queue, the upgrade-runner calls `doFinish()`.
     *