3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
12 use Civi\Api4\StatusPreference
;
17 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 abstract class CRM_Utils_Check_Component
{
22 * Get the configured status checks.
26 * @throws \API_Exception
27 * @throws \Civi\API\Exception\UnauthorizedException
29 public function getChecksConfig() {
30 if (empty(Civi
::$statics[__FUNCTION__
])) {
31 Civi
::$statics[__FUNCTION__
] = (array) StatusPreference
::get(FALSE)
32 ->addWhere('domain_id', '=', 'current_domain')
33 ->execute()->indexBy('name');
35 return Civi
::$statics[__FUNCTION__
];
39 * Should these checks be run?
43 public function isEnabled() {
48 * Run all checks in this class.
51 * [CRM_Utils_Check_Message]
53 * @throws \API_Exception
54 * @throws \Civi\API\Exception\UnauthorizedException
56 public function checkAll() {
58 foreach (get_class_methods($this) as $method) {
59 // Note that we should check if the test is disabled BEFORE running it in case it's disabled for performance.
60 if ($method !== 'checkAll' && strpos($method, 'check') === 0 && !$this->isDisabled($method)) {
61 $messages = array_merge($messages, $this->$method());
68 * Is the specified check disabled.
70 * @param string $method
74 * @throws \API_Exception
75 * @throws \Civi\API\Exception\UnauthorizedException
77 public function isDisabled($method) {
78 $checks = $this->getChecksConfig();
79 if (isset($checks[$method]['is_active'])) {
80 return !$checks[$method]['is_active'];
86 * Check if file exists on given URL.
89 * @param float|bool $timeoutOverride
92 * @throws \GuzzleHttp\Exception\GuzzleException
94 public function fileExists($url, $timeoutOverride = FALSE) {
95 // Timeout past in maybe 0 in which case we should still permit it (0 is infinite).
96 if (!$timeoutOverride && $timeoutOverride !== 0) {
97 $timeoutOverride = (float) Civi
::settings()->get('http_timeout');
101 $guzzleClient = new GuzzleHttp\
Client();
102 $guzzleResponse = $guzzleClient->request('GET', $url, array(
103 'timeout' => $timeoutOverride,
105 $fileExists = ($guzzleResponse->getStatusCode() == 200);
107 catch (Exception
$e) {
108 // At this stage we are not checking for variants of not being able to receive it.
109 // However, we might later enhance this to distinguish forbidden from a 500 error.