X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FUtils%2FCheck.php;h=1e4d9f7df707bee0cd99aa5e5944f0ea89299cd7;hb=d155cca02e23d432694139bbf81b907a4e47c077;hp=e8eb744ab21a43d9902982032d12d29df0a834d3;hpb=bd4c91fa63ea1884bcb352aa2a27952f2a0862df;p=civicrm-core.git diff --git a/CRM/Utils/Check.php b/CRM/Utils/Check.php index e8eb744ab2..1e4d9f7df7 100644 --- a/CRM/Utils/Check.php +++ b/CRM/Utils/Check.php @@ -170,31 +170,20 @@ class CRM_Utils_Check { } /** - * Run all system checks. + * Run all enabled system checks. * * This functon is wrapped by the System.check api. * * Calls hook_civicrm_check() for extensions to add or modify messages. - * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_check + * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_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