From: colemanw Date: Tue, 7 Nov 2023 01:36:56 +0000 (-0500) Subject: dev/core#4754 - Add status check to warn of missing/outdated public assets X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=524383d8b69499e3116711f6b437ce2dec4d4641;p=civicrm-core.git dev/core#4754 - Add status check to warn of missing/outdated public assets --- diff --git a/CRM/Utils/Check/Component/Cms.php b/CRM/Utils/Check/Component/Cms.php index 1c4c7a41dd..d69083c462 100644 --- a/CRM/Utils/Check/Component/Cms.php +++ b/CRM/Utils/Check/Component/Cms.php @@ -16,6 +16,45 @@ */ 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 => 'composer civicrm:publish']) . + ' ' . + 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 index 0000000000..aea10b9966 --- /dev/null +++ b/js/version.json @@ -0,0 +1 @@ +"5.69.alpha1" diff --git a/tools/bin/scripts/set-version.php b/tools/bin/scripts/set-version.php index 3e5b0cd453..7f01e65332 100755 --- a/tools/bin/scripts/set-version.php +++ b/tools/bin/scripts/set-version.php @@ -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) {