Merge pull request #19187 from civicrm/5.33
[civicrm-core.git] / Civi / Api4 / Action / System / Check.php
CommitLineData
19b53e5b 1<?php
380f3545
TO
2
3/*
4 +--------------------------------------------------------------------+
41498ac5 5 | Copyright CiviCRM LLC. All rights reserved. |
380f3545 6 | |
41498ac5
TO
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
380f3545
TO
10 +--------------------------------------------------------------------+
11 */
12
19b53e5b
C
13namespace Civi\Api4\Action\System;
14
15/**
16 * Retrieve system notices, warnings, errors, etc.
675e2573 17 * @method bool getIncludeDisabled()
19b53e5b
C
18 */
19class Check extends \Civi\Api4\Generic\BasicGetAction {
20
675e2573
CW
21 /**
22 * Run checks that have been explicitly disabled (default false)
23 * @var bool
24 */
25 protected $includeDisabled = FALSE;
26
27 /**
28 * @param bool $includeDisabled
29 * @return Check
30 */
31 public function setIncludeDisabled(bool $includeDisabled): Check {
32 $this->includeDisabled = $includeDisabled;
33 return $this;
34 }
35
19b53e5b 36 protected function getRecords() {
675e2573
CW
37 $messages = $names = [];
38
39 // Filtering by name relies on the component check rather than the api arrayQuery
40 // @see \CRM_Utils_Check_Component::isCheckable
41 foreach ($this->where as $i => $clause) {
42 if ($clause[0] == 'name' && !empty($clause[2]) && in_array($clause[1], ['=', 'IN'], TRUE)) {
43 $names = (array) $clause[2];
44 unset($this->where[$i]);
45 break;
46 }
47 }
48
49 foreach (\CRM_Utils_Check::checkStatus($names, $this->includeDisabled) as $message) {
19b53e5b
C
50 $messages[] = $message->toArray();
51 }
52 return $messages;
53 }
54
55 public static function fields() {
56 return [
57 [
58 'name' => 'name',
59 'title' => 'Name',
60 'description' => 'Unique identifier',
61 'data_type' => 'String',
62 ],
63 [
64 'name' => 'title',
65 'title' => 'Title',
66 'description' => 'Short title text',
67 'data_type' => 'String',
68 ],
69 [
70 'name' => 'message',
71 'title' => 'Message',
72 'description' => 'Long description html',
73 'data_type' => 'String',
74 ],
75 [
76 'name' => 'help',
77 'title' => 'Help',
78 'description' => 'Optional extra help (html string)',
79 'data_type' => 'String',
80 ],
81 [
82 'name' => 'icon',
83 'description' => 'crm-i class of icon to display with message',
84 'data_type' => 'String',
85 ],
86 [
87 'name' => 'severity',
88 'title' => 'Severity',
89 'description' => 'Psr\Log\LogLevel string',
90 'data_type' => 'String',
91 'options' => array_combine(\CRM_Utils_Check::getSeverityList(), \CRM_Utils_Check::getSeverityList()),
92 ],
93 [
94 'name' => 'severity_id',
95 'title' => 'Severity ID',
96 'description' => 'Integer representation of Psr\Log\LogLevel',
97 'data_type' => 'Integer',
98 'options' => \CRM_Utils_Check::getSeverityList(),
99 ],
100 [
101 'name' => 'is_visible',
102 'title' => 'is visible',
103 'description' => '0 if message has been hidden by the user',
104 'data_type' => 'Boolean',
105 ],
106 [
107 'name' => 'hidden_until',
108 'title' => 'Hidden until',
109 'description' => 'When will hidden message be visible again?',
110 'data_type' => 'Date',
111 ],
112 [
113 'name' => 'actions',
114 'title' => 'Actions',
115 'description' => 'List of actions user can perform',
116 'data_type' => 'Array',
117 ],
118 ];
119 }
120
121}