Skip to content

Commit c12e84a

Browse files
committed
* This fix will ensure the timezone set in the database matches the timezone
set in Drupal. Note: this will fix the timezone for some dates such as the scheduled and completed dates in mailings. It will only affect *future* mailings. Without this change these date fields use the database timezone which is in UTC. If you set the timezone in Drupal to something other than UTC then the scheduled then this is confusing. If you have questions contact https://civicrmstarterkit.org/contact. We provide some basic general support for the public. If you require help with your specific website there will likely be a cost.
1 parent 3b3ac6d commit c12e84a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

profiles/civicrm_starterkit/civicrm_starterkit.profile

+23
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,29 @@
44
* Enables modules and site configuration for a site installation with CiviCRM.
55
*/
66

7+
/**
8+
* Implements hook_init().
9+
*
10+
* Set the database to use the same timezone as the default in Drupal.
11+
* We need this because we Pantheon often migrates databases to new dbserver
12+
* instances, which resets the db settings.
13+
*
14+
* Drupal is fine with changing this since it doesn't rely on it for saving
15+
* dates. But it will confuse the CiviCRM reporting if moving the database to
16+
* a different timezone on new hosting.
17+
*/
18+
function civicrm_starterkit_init() {
19+
// We know it's Pantheon and MySQL so we don't need to check for other dbs.
20+
// See also class date_sql_handler and views_get_timezone().
21+
$php_tz = (new DateTime('now'))->format('P');
22+
$db_tz = db_query("SELECT @@global.time_zone;")->fetchField();
23+
24+
// If they don't match we set the global db to match the PHP timezone.
25+
if ($db_tz != $php_tz) {
26+
db_query("SET @@global.time_zone = :tz;", [':tz' => $php_tz]);
27+
}
28+
}
29+
730
/**
831
* Implements hook_form_FORM_ID_alter() for install_configure_form().
932
*

0 commit comments

Comments
 (0)