Skip to content
Snippets Groups Projects
Unverified Commit d9920c52 authored by totten's avatar totten Committed by GitHub
Browse files

Merge pull request #25367 from totten/5.58-check-tz

System Status - Add check to ensure that MySQL timezones are operational
parents 2f604542 274a128b
Branches
Tags
No related merge requests found
......@@ -18,6 +18,54 @@ class CRM_Utils_Check_Component_Timestamps extends CRM_Utils_Check_Component {
const DOCTOR_WHEN = 'https://github.com/civicrm/org.civicrm.doctorwhen';
/**
* Check that MySQL actually supports timezone operations.
*
* @return CRM_Utils_Check_Message[]
*/
public function checkTimezoneAPIs() {
$messages = [];
try {
$convertedTimeNY = CRM_Core_DAO::singleValueQuery('SELECT CONVERT_TZ("2001-02-03 04:05:00", "GMT", "America/New_York")');
}
catch (\Exception $e) {
$convertedTimeNY = NULL;
}
$expectedTimeNY = '2001-02-02 23:05:00';
$oldTz = CRM_Core_DAO::singleValueQuery('SELECT @@time_zone');
try {
CRM_Core_DAO::singleValueQuery('SET @@time_zone = "Europe/Berlin"');
$convertedTimeDE = CRM_Core_DAO::singleValueQuery('SELECT FROM_UNIXTIME(981176700)');
}
catch (\Exception $e) {
$convertedTimeDE = NULL;
}
finally {
CRM_Core_DAO::singleValueQuery('SET @@time_zone = %1', [1 => [$oldTz, 'String']]);
}
$expectedTimeDE = '2001-02-03 06:05:00';
if ($convertedTimeNY !== $expectedTimeNY || $convertedTimeDE !== $expectedTimeDE) {
$messages[] = new CRM_Utils_Check_Message(
__FUNCTION__,
ts('The MySQL database does not fully support timezones. Please ask the database administrator to <a %1>load timezone data</a>.', [
// If we had a manual page, it would make sense to link to that. Such a page might
// (a) point out that the process is similar for MySQL 5.x/8.x and MariaDB,
// and (b) talk more about potential impacts (re: current code; extensions; future changes).
// We don't have that page. But this link gives the general gist.
1 => 'target="_blank" href="https://dev.mysql.com/doc/refman/8.0/en/mysql-tzinfo-to-sql.html"',
]),
ts('MySQL Timezone Problem'),
\Psr\Log\LogLevel::WARNING,
'fa-clock-o'
);
}
return $messages;
}
/**
* Check that various columns are TIMESTAMP and not DATETIME. (CRM-9683, etal)
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment