From 5a604d61530b9960f810000684e3c2a6e27c7322 Mon Sep 17 00:00:00 2001 From: Eileen Date: Thu, 24 Oct 2013 20:04:25 +1300 Subject: [PATCH] CRM-9683 add functions to set timezone in mysql based on UF, note that this is not currently called but anticipate it will be called from the drupal integration code (civicrm_initialize) ---------------------------------------- * CRM-9683: Implement timezone support for CiviMail http://issues.civicrm.org/jira/browse/CRM-9683 --- CRM/Utils/System/Base.php | 18 ++++++++++++++++++ CRM/Utils/System/Drupal.php | 26 ++++++++++++++++++++++++++ CRM/Utils/System/Drupal6.php | 25 ++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/CRM/Utils/System/Base.php b/CRM/Utils/System/Base.php index 93cd88b0c3..e9acb7df1a 100644 --- a/CRM/Utils/System/Base.php +++ b/CRM/Utils/System/Base.php @@ -163,5 +163,23 @@ abstract class CRM_Utils_System_Base { */ function userLoginFinalize($params = array()){ } + + /** + * Set timezone in mysql so that timestamp fields show the correct time + */ + function setMySQLTimeZone(){ + $timeZoneOffset = $this->getTimeZoneOffset(); + if($timeZoneOffset){ + $sql = "SET time_zone = '$timeZoneOffset'"; + CRM_Core_DAO::executequery($sql); + } + } + + /** + * Get timezone from CMS + * @return boolean|string + */ + function getTimeZoneOffset(){ + } } diff --git a/CRM/Utils/System/Drupal.php b/CRM/Utils/System/Drupal.php index 3ff008b6b7..fda57c0385 100644 --- a/CRM/Utils/System/Drupal.php +++ b/CRM/Utils/System/Drupal.php @@ -1065,6 +1065,32 @@ AND u.status = 1 } } + /** + * Get timezone from Drupal + * @return boolean|string + */ + function getTimeZoneOffset(){ + global $user; + if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) { + $timezone = $user->timezone; + } else { + $timezone = variable_get('date_default_timezone', null); + } + $tzObj = new DateTimeZone($timezone); + $dateTime = new DateTime("now", $tzObj); + $tz = $tzObj->getOffset($dateTime); + + if(empty($tz)){ + return false; + } + + $timeZoneOffset = sprintf("%02d:%02d", $tz / 3600, ($tz/60)%60 ); + + if($timeZoneOffset > 0){ + $timeZoneOffset = '+' . $timeZoneOffset; + } + return $timeZoneOffset; + } /** * Reset any system caches that may be required for proper CiviCRM * integration. diff --git a/CRM/Utils/System/Drupal6.php b/CRM/Utils/System/Drupal6.php index 23fca40ec7..8ceba7259d 100644 --- a/CRM/Utils/System/Drupal6.php +++ b/CRM/Utils/System/Drupal6.php @@ -180,7 +180,7 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { if (!$row) { return; } - + $user = NULL; if (!empty($row)) { @@ -1016,6 +1016,29 @@ class CRM_Utils_System_Drupal6 extends CRM_Utils_System_DrupalBase { og_delete_subscription( $ogID, $drupalID ); } + /** + * Get timezone from Drupal + * @return boolean|string + */ + function getTimeZoneOffset(){ + global $user; + if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) { + $timezone = $user->timezone; + } else { + $timezone = variable_get('date_default_timezone', null); + } + if(empty($timezone)){ + return false; + } + $hour = $user->timezone / 3600; + $timeZoneOffset = sprintf("%02d:%02d", $timezone / 3600, ($timezone/60)%60 ); + if($timeZoneOffset > 0){ + $timeZoneOffset = '+' . $timeZoneOffset; + } + return $timeZoneOffset; + } + + /** * Reset any system caches that may be required for proper CiviCRM * integration. -- 2.25.1