return $messages;
}
+ /**
+ * Ensure that the CMS is providing a supported timezone.
+ *
+ * @return CRM_Utils_Check_Message[]
+ */
+ public function checkUFTimezoneValid() {
+ $messages = [];
+ $check_tz = CRM_Core_Config::singleton()->userSystem->getTimeZoneString();
+
+ if (!array_key_exists($check_tz, CRM_Core_SelectValues::timezone())) {
+ $messages[] = new CRM_Utils_Check_Message(
+ __FUNCTION__,
+ ts('This system has an invalid timezone set. Please verify that your CMS has a timezone configured that is listed under the <a href="%1">PHP List of Supported Timezones</a>.', [1 => 'https://www.php.net/manual/en/timezones.php']),
+ ts('Missing or Invalid Timezone'),
+ \Psr\Log\LogLevel::ERROR,
+ 'fa-clock-o'
+ );
+ }
+
+ return $messages;
+ }
+
}
--- /dev/null
+<?php
+
+/**
+ * @package CRM
+ */
+class CRM_Utils_Check_Component_Event extends CRM_Utils_Check_Component {
+
+ /**
+ * Check events have timezone set.
+ *
+ * @return CRM_Utils_Check_Message[]
+ * @throws \API_Exception
+ */
+ public function checkTimezones() {
+ $messages = [];
+
+ try {
+ $count = \Civi\Api4\Event::get(FALSE)
+ ->selectRowCount()
+ ->addWhere('event_tz', 'IS EMPTY')
+ ->execute()
+ ->rowCount;
+
+ if ($count) {
+ $msg = new CRM_Utils_Check_Message(
+ __FUNCTION__,
+ '<p>' . ts('%count Event has no timezone set', ['count' => $count, 'plural' => '%count Events have no timezone set.']) . '</p>',
+ ts('Events with Missing Timezone'),
+ \Psr\Log\LogLevel::WARNING,
+ 'fa-calendar'
+ );
+ $msg->addAction(
+ ts('Fix Events with Missing Timezone'),
+ ts('This will set the system default timezone "%1" for all Events with no timezone set.', [1 => CRM_Core_Config::singleton()->userSystem->getTimeZoneString()]),
+ 'api3',
+ ['Event', 'addMissingTimezones']
+ );
+ $messages[] = $msg;
+ }
+ }
+ catch (API_Exception $e) {
+ $messages[] = new CRM_Utils_Check_Message(
+ __FUNCTION__,
+ ts('API Exception: %1 while checking events for timezones.', ['1' => $e->getMessage()]),
+ ts('Event timezone check failed'),
+ \Psr\Log\LogLevel::ERROR,
+ 'fa-calendar'
+ );
+ }
+
+ return $messages;
+ }
+
+}
}
return $output;
}
+
+/**
+ * Add missing timezones to all events.
+ *
+ * @return array
+ */
+function civicrm_api3_event_addmissingtimezones($params) {
+ $defaultTZ = CRM_Core_Config::singleton()->userSystem->getTimeZoneString();
+
+ CRM_Core_DAO::executeQuery('UPDATE civicrm_event SET event_tz = %1 WHERE event_tz IS NULL OR event_tz = ""', [1 => [$defaultTZ, 'String']]);
+ return civicrm_api3_create_success($events, $params, 'Event', 'addMissingTimezones');
+}