From 6491539b0bc0e91dd78c904d3ae6652b712d3673 Mon Sep 17 00:00:00 2001 From: "Donald A. Lobo" Date: Tue, 3 Dec 2013 09:01:03 -0800 Subject: [PATCH] CRM-13885 - Set timezone for WP on Cron http://issues.civicrm.org/jira/browse/CRM-13885 --- CRM/Utils/System/Base.php | 30 ++++++++++++++++++++++++++++++ CRM/Utils/System/WordPress.php | 13 +++++++++++++ 2 files changed, 43 insertions(+) diff --git a/CRM/Utils/System/Base.php b/CRM/Utils/System/Base.php index e9acb7df1a..e9767fc162 100644 --- a/CRM/Utils/System/Base.php +++ b/CRM/Utils/System/Base.php @@ -175,11 +175,41 @@ abstract class CRM_Utils_System_Base { } } + /** * Get timezone from CMS * @return boolean|string */ + /** + * Get timezone from Drupal + * @return boolean|string + */ function getTimeZoneOffset(){ + $timezone = $this->getTimeZoneString(); + if($timezone){ + $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; + } + } + + /** + * Over-ridable function to get timezone as a string eg. + * @return string Timezone e.g. 'America/Los_Angeles' + */ + function getTimeZoneString() { + return NULL; } } diff --git a/CRM/Utils/System/WordPress.php b/CRM/Utils/System/WordPress.php index 42649a736d..389c2c0692 100644 --- a/CRM/Utils/System/WordPress.php +++ b/CRM/Utils/System/WordPress.php @@ -433,6 +433,11 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { } require_once ($cmsRootPath . DIRECTORY_SEPARATOR . 'wp-load.php'); + $wpUserTimezone = get_option('timezone_string'); + if ($wpUserTimezone) { + date_default_timezone_set($wpUserTimezone); + CRM_Core_Config::singleton()->userSystem->setMySQLTimeZone(); + } return true; } @@ -622,5 +627,13 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base { return 'Unknown'; } } + + /** + * get timezone as a string + * @return string Timezone e.g. 'America/Los_Angeles' + */ + function getTimeZoneString() { + return get_option('timezone_string'); + } } -- 2.25.1