Respect zero value
[civicrm-core.git] / CRM / Utils / Check / Component / Event.php
CommitLineData
cd2d8d98
FW
1<?php
2
3/**
4 * @package CRM
5 */
6class CRM_Utils_Check_Component_Event extends CRM_Utils_Check_Component {
7
53893720
JG
8 /**
9 * @inheritDoc
10 */
11 public function isEnabled() {
12 return CRM_Core_Component::isEnabled('CiviEvent');
13 }
14
cd2d8d98
FW
15 /**
16 * Check events have timezone set.
17 *
18 * @return CRM_Utils_Check_Message[]
19 * @throws \API_Exception
20 */
21 public function checkTimezones() {
22 $messages = [];
23
24 try {
25 $count = \Civi\Api4\Event::get(FALSE)
26 ->selectRowCount()
27 ->addWhere('event_tz', 'IS EMPTY')
28 ->execute()
29 ->rowCount;
30
31 if ($count) {
32 $msg = new CRM_Utils_Check_Message(
33 __FUNCTION__,
34 '<p>' . ts('%count Event has no timezone set', ['count' => $count, 'plural' => '%count Events have no timezone set.']) . '</p>',
35 ts('Events with Missing Timezone'),
36 \Psr\Log\LogLevel::WARNING,
37 'fa-calendar'
38 );
39 $msg->addAction(
40 ts('Fix Events with Missing Timezone'),
41 ts('This will set the system default timezone "%1" for all Events with no timezone set.', [1 => CRM_Core_Config::singleton()->userSystem->getTimeZoneString()]),
42 'api3',
43 ['Event', 'addMissingTimezones']
44 );
45 $messages[] = $msg;
46 }
47 }
48 catch (API_Exception $e) {
49 $messages[] = new CRM_Utils_Check_Message(
50 __FUNCTION__,
51 ts('API Exception: %1 while checking events for timezones.', ['1' => $e->getMessage()]),
52 ts('Event timezone check failed'),
53 \Psr\Log\LogLevel::ERROR,
54 'fa-calendar'
55 );
56 }
57
58 return $messages;
59 }
60
61}