Skip to content

Commit

Permalink
* This fix will ensure the timezone set in the database matches the t…
Browse files Browse the repository at this point in the history
…imezone

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.
  • Loading branch information
herbdool committed Oct 5, 2020
1 parent 3b3ac6d commit c12e84a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions profiles/civicrm_starterkit/civicrm_starterkit.profile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@
* Enables modules and site configuration for a site installation with CiviCRM.
*/

/**
* Implements hook_init().
*
* Set the database to use the same timezone as the default in Drupal.
* We need this because we Pantheon often migrates databases to new dbserver
* instances, which resets the db settings.
*
* Drupal is fine with changing this since it doesn't rely on it for saving
* dates. But it will confuse the CiviCRM reporting if moving the database to
* a different timezone on new hosting.
*/
function civicrm_starterkit_init() {
// We know it's Pantheon and MySQL so we don't need to check for other dbs.
// See also class date_sql_handler and views_get_timezone().
$php_tz = (new DateTime('now'))->format('P');
$db_tz = db_query("SELECT @@global.time_zone;")->fetchField();

// If they don't match we set the global db to match the PHP timezone.
if ($db_tz != $php_tz) {
db_query("SET @@global.time_zone = :tz;", [':tz' => $php_tz]);
}
}

/**
* Implements hook_form_FORM_ID_alter() for install_configure_form().
*
Expand Down

0 comments on commit c12e84a

Please sign in to comment.