X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FUtils%2FCheck.php;h=1e4d9f7df707bee0cd99aa5e5944f0ea89299cd7;hb=f2403471b460a122ac834d3c980e8c227b08ac79;hp=e92bb9ec7c24180c7d9769b568d4ef4bb2ceb3f6;hpb=0ea6deefe8bdebaeecd9655fac3823f24e6e526e;p=civicrm-core.git diff --git a/CRM/Utils/Check.php b/CRM/Utils/Check.php index e92bb9ec7c..1e4d9f7df7 100644 --- a/CRM/Utils/Check.php +++ b/CRM/Utils/Check.php @@ -170,7 +170,7 @@ class CRM_Utils_Check { } /** - * Run all system checks. + * Run all enabled system checks. * * This functon is wrapped by the System.check api. * @@ -180,21 +180,10 @@ class CRM_Utils_Check { * @param bool $max * Whether to return just the maximum non-hushed severity * - * @return array - * Array of CRM_Utils_Check_Message objects + * @return CRM_Utils_Check_Message[] */ public static function checkAll($max = FALSE) { - $messages = []; - foreach (glob(__DIR__ . '/Check/Component/*.php') as $filePath) { - $className = 'CRM_Utils_Check_Component_' . basename($filePath, '.php'); - /* @var CRM_Utils_Check_Component $check */ - $check = new $className(); - if ($check->isEnabled()) { - $messages = array_merge($messages, $check->checkAll()); - } - } - - CRM_Utils_Hook::check($messages); + $messages = self::checkStatus(); uasort($messages, [__CLASS__, 'severitySort']); @@ -212,6 +201,38 @@ class CRM_Utils_Check { return ($max) ? $maxSeverity : $messages; } + /** + * @param array $statusNames + * Optionally specify the names of specific checks to run, or leave empty to run all + * @param bool $includeDisabled + * Run checks that have been explicitly disabled (default false) + * + * @return CRM_Utils_Check_Message[] + */ + public static function checkStatus($statusNames = [], $includeDisabled = FALSE) { + $messages = []; + $checksNeeded = $statusNames; + foreach (glob(__DIR__ . '/Check/Component/*.php') as $filePath) { + $className = 'CRM_Utils_Check_Component_' . basename($filePath, '.php'); + /* @var CRM_Utils_Check_Component $component */ + $component = new $className(); + if ($includeDisabled || $component->isEnabled()) { + $messages = array_merge($messages, $component->checkAll($statusNames, $includeDisabled)); + } + if ($statusNames) { + // Early return if we have already run (or skipped) all the requested checks. + $checksNeeded = array_diff($checksNeeded, $component->getAllChecks()); + if (!$checksNeeded) { + return $messages; + } + } + } + + CRM_Utils_Hook::check($messages, $statusNames, $includeDisabled); + + return $messages; + } + /** * @param int $level * @return string