dev/core#4754 - Add status check to warn of missing/outdated public assets
authorcolemanw <coleman@civicrm.org>
Tue, 7 Nov 2023 01:36:56 +0000 (20:36 -0500)
committercolemanw <coleman@civicrm.org>
Tue, 14 Nov 2023 14:20:36 +0000 (09:20 -0500)
CRM/Utils/Check/Component/Cms.php
js/version.json [new file with mode: 0644]
tools/bin/scripts/set-version.php

index 1c4c7a41dd237ee0b001bfe395d3590dff7116eb..d69083c46249ee9a6311ce98e9af591751c52258 100644 (file)
  */
 class CRM_Utils_Check_Component_Cms extends CRM_Utils_Check_Component {
 
+  /**
+   * For sites running from Composer, ensure public assets have been correctly installed.
+   *
+   * @return CRM_Utils_Check_Message[]
+   */
+  public static function checkPublicAssets(): array {
+    $checks = [];
+    $assetDir = $GLOBALS['civicrm_asset_map']['civicrm/civicrm-core']['dest'] ?? NULL;
+    // No asset directory so this is not a composer-based install
+    if (!$assetDir) {
+      return [];
+    }
+    $errorMsg = NULL;
+    $versionFile = $assetDir . '/js/version.json';
+    if (!file_exists($versionFile)) {
+      $errorMsg = ts('Assets missing from public web directory.');
+    }
+    else {
+      $currentVersion = CRM_Utils_System::version();
+      $assetVersion = json_decode(file_get_contents($versionFile), TRUE);
+      if ($assetVersion !== $currentVersion) {
+        $errorMsg = ts('Wrong version of assets in public web directory: expected %1 but found %2.', [1 => $currentVersion, 2 => $assetVersion]);
+      }
+    }
+    if ($errorMsg) {
+      $checks[] = new CRM_Utils_Check_Message(
+        __FUNCTION__,
+        "$errorMsg " .
+          ts('Use the command %1 to resolve.', [1 => '<code>composer civicrm:publish</code>']) .
+          ' ' .
+          CRM_Utils_System::docURL2('sysadmin/upgrade/drupal8/#additional-cleanup'),
+        ts('Public Assets Not Published'),
+        \Psr\Log\LogLevel::ERROR,
+        'fa-code'
+      );
+    }
+    return $checks;
+  }
+
   /**
    * For sites running in WordPress, make sure the configured base page exists.
    *
diff --git a/js/version.json b/js/version.json
new file mode 100644 (file)
index 0000000..aea10b9
--- /dev/null
@@ -0,0 +1 @@
+"5.69.alpha1"
index 3e5b0cd4536f783830553ac71715c3df310e593b..7f01e65332062e00ce633a4e142a1d030f6e18e2 100755 (executable)
@@ -82,6 +82,10 @@ updateFile("sql/test_data_second_domain.mysql", function ($content) use ($newVer
   return str_replace($oldVersion, $newVersion, $content);
 });
 
+updateFile("js/version.json", function () use ($newVersion) {
+  return json_encode($newVersion) . '\n';
+});
+
 // Update core extensions if this is a stable release
 $infoXmls = isPreReleaseIncrement($newVersion) ? [] : findCoreInfoXml();
 foreach ($infoXmls as $infoXml) {