Status Check - Ensure that components are enabled
authorTim Otten <totten@civicrm.org>
Sun, 17 Sep 2023 23:42:03 +0000 (16:42 -0700)
committerTim Otten <totten@civicrm.org>
Sun, 17 Sep 2023 23:42:03 +0000 (16:42 -0700)
CRM/Utils/Check/Component/Env.php

index 337c9e37ddea3123365b3d0b9dd31cbf4378b29f..2ac6246f6f2f483a747db2e1ab019ab8153c6405 100644 (file)
@@ -748,6 +748,44 @@ class CRM_Utils_Check_Component_Env extends CRM_Utils_Check_Component {
     return $messages;
   }
 
+  /**
+   * Ensure that *some* CiviCRM components (component-extensions) are enabled.
+   *
+   * It is believed that some sites lost their list of active-components due to a flawed
+   * upgrade-step circa 5.62/5.63. The upgrade-step has been fixed (civicrm-core#27075),
+   * but some sites may still have bad configurations.
+   *
+   * This problem should generally be obvious after running web-based upgrader, but it's not obvious
+   * in scripted+CLI upgrades.
+   *
+   * @return array
+   * @throws \CRM_Core_Exception
+   * @throws \Civi\API\Exception\UnauthorizedException
+   */
+  public function checkComponents(): array {
+    $messages = [];
+
+    $setting = Civi::settings()->get('enable_components');
+    $exts = \Civi\Api4\Extension::get(FALSE)
+      ->addWhere('key', 'LIKE', 'civi_%')
+      ->addWhere('status', '=', 'installed')
+      ->execute()
+      ->indexBy('key')->column('status');
+    if (empty($setting) || empty($exts)) {
+      $messages[] = new CRM_Utils_Check_Message(
+        __FUNCTION__,
+        ts('None of the CiviCRM components are enabled. This is theoretically legal, but it is most likely a misconfiguration.<br/> Please inspect and re-save the <a %1>component settings</a>.', [
+          1 => sprintf('target="_blank" href="%s"', Civi::url('backend://civicrm/admin/setting/component?reset=1', 'ah')),
+        ]),
+        ts('Missing Components'),
+        \Psr\Log\LogLevel::WARNING,
+        'fa-server'
+      );
+    }
+
+    return $messages;
+  }
+
   /**
    * @return CRM_Utils_Check_Message[]
    */