Add system check to warn if CiviReport disabled & logging enabled
authoreileen <emcnaughton@wikimedia.org>
Thu, 4 Jan 2024 01:02:26 +0000 (14:02 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 4 Jan 2024 04:02:28 +0000 (17:02 +1300)
CRM/Utils/Check/Component/Env.php
tests/phpunit/CRM/Utils/Check/Component/EnvTest.php

index d37a0ce6cb9db4764a1d52b6089cfe4621d2057c..72427d69f99c7fbe89d63c1e5271244817fb5967 100644 (file)
@@ -9,6 +9,9 @@
  +--------------------------------------------------------------------+
  */
 
+use Civi\Api4\Extension;
+use Psr\Log\LogLevel;
+
 /**
  *
  * @package CRM
@@ -200,7 +203,7 @@ class CRM_Utils_Check_Component_Env extends CRM_Utils_Check_Component {
       return $messages;
     }
 
-    list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(TRUE);
+    [$domainEmailName, $domainEmailAddress] = CRM_Core_BAO_Domain::getNameAndEmail(TRUE);
     $domain        = CRM_Core_BAO_Domain::getDomain();
     $domainName    = $domain->name;
     $fixEmailUrl   = CRM_Utils_System::url("civicrm/admin/options/from_email_address", "&reset=1");
@@ -766,7 +769,7 @@ class CRM_Utils_Check_Component_Env extends CRM_Utils_Check_Component {
     $messages = [];
 
     $setting = Civi::settings()->get('enable_components');
-    $exts = \Civi\Api4\Extension::get(FALSE)
+    $exts = Extension::get(FALSE)
       ->addWhere('key', 'LIKE', 'civi_%')
       ->addWhere('status', '=', 'installed')
       ->execute()
@@ -859,6 +862,31 @@ class CRM_Utils_Check_Component_Env extends CRM_Utils_Check_Component {
     return [];
   }
 
+  /**
+   * Checks if logging is enabled but Civi-report is not.
+   *
+   * @return CRM_Utils_Check_Message[]
+   * @throws \CRM_Core_Exception
+   */
+  public function checkLoggingHasCiviReport(): array {
+    if (Civi::settings()->get('logging')) {
+      $isEnabledCiviReport = (bool) Extension::get(FALSE)
+        ->addWhere('key', '=', 'civi_report')
+        ->addWhere('status', '=', 'installed')
+        ->execute()->countFetched();
+      return $isEnabledCiviReport ? [] : [
+        new CRM_Utils_Check_Message(
+          __FUNCTION__,
+          ts('You have enabled detailed logging but to display this in the change log tab CiviReport must be enabled'),
+          ts('CiviReport required to display detailed logging.'),
+          LogLevel::WARNING,
+          'fa-plug'
+        ),
+      ];
+    }
+    return [];
+  }
+
   /**
    * Checks if CiviCRM database version is up-to-date
    * @return CRM_Utils_Check_Message[]
index 45efbd877672f264760f6e94b8b2dad94ac77fda..ff32ff323a672f0c6142c2059a7fed7044785650 100644 (file)
@@ -18,7 +18,7 @@ class CRM_Utils_Check_Component_EnvTest extends CiviUnitTestCase {
    * @throws \GuzzleHttp\Exception\GuzzleException
    */
   public function testResourceUrlCheck(): void {
-    $check = new \CRM_Utils_Check_Component_Env();
+    $check = new CRM_Utils_Check_Component_Env();
     $failRequest = $check->fileExists('https://civicrm.org', 0.001);
     $successRequest = $check->fileExists('https://civicrm.org', 0);