From 99c22a45c66c88bea0e330f7e5f1ca1d3d2a74f1 Mon Sep 17 00:00:00 2001 From: eileen Date: Sun, 8 May 2016 09:18:10 +1000 Subject: [PATCH] CRM-18516 Convert the date fields relating to group caching & acl caching timestamp Conflicts: CRM/Upgrade/Incremental/sql/4.7.8.mysql.tpl xml/schema/ACL/Cache.xml --- CRM/ACL/BAO/Cache.php | 5 +---- CRM/Contact/BAO/GroupContactCache.php | 23 ++++++++++++++++------- CRM/Utils/Date.php | 19 ------------------- xml/schema/ACL/Cache.xml | 4 +++- xml/schema/Contact/Group.xml | 4 ++-- 5 files changed, 22 insertions(+), 33 deletions(-) diff --git a/CRM/ACL/BAO/Cache.php b/CRM/ACL/BAO/Cache.php index b665d2013d..6f88774dec 100644 --- a/CRM/ACL/BAO/Cache.php +++ b/CRM/ACL/BAO/Cache.php @@ -151,14 +151,11 @@ WHERE contact_id = %1 $config = CRM_Core_Config::singleton(); $smartGroupCacheTimeout = CRM_Contact_BAO_GroupContactCache::smartGroupCacheTimeout(); - //make sure to give original timezone settings again. - $now = CRM_Utils_Date::getUTCTime(); - $query = " DELETE FROM civicrm_acl_cache WHERE modified_date IS NULL - OR (TIMESTAMPDIFF(MINUTE, modified_date, $now) >= $smartGroupCacheTimeout) + OR (TIMESTAMPDIFF(MINUTE, modified_date, NOW()) >= $smartGroupCacheTimeout) "; CRM_Core_DAO::singleValueQuery($query); diff --git a/CRM/Contact/BAO/GroupContactCache.php b/CRM/Contact/BAO/GroupContactCache.php index 2e3ee1b0b4..c105e87fa0 100644 --- a/CRM/Contact/BAO/GroupContactCache.php +++ b/CRM/Contact/BAO/GroupContactCache.php @@ -69,7 +69,6 @@ class CRM_Contact_BAO_GroupContactCache extends CRM_Contact_DAO_GroupContactCach */ public static function groupRefreshedClause($groupIDClause = NULL, $includeHiddenGroups = FALSE) { $smartGroupCacheTimeout = self::smartGroupCacheTimeout(); - $now = CRM_Utils_Date::getUTCTime(); $query = " SELECT g.id @@ -77,8 +76,8 @@ FROM civicrm_group g WHERE ( g.saved_search_id IS NOT NULL OR g.children IS NOT NULL ) AND g.is_active = 1 AND ( g.cache_date IS NULL OR - ( TIMESTAMPDIFF(MINUTE, g.cache_date, $now) >= $smartGroupCacheTimeout ) OR - ( $now >= g.refresh_date ) + ( TIMESTAMPDIFF(MINUTE, g.cache_date, NOW()) >= $smartGroupCacheTimeout ) OR + ( NOW() >= g.refresh_date ) ) "; @@ -178,7 +177,7 @@ AND ( g.cache_date IS NULL OR if (!empty($refreshGroupIDs)) { $refreshGroupIDString = CRM_Core_DAO::escapeString(implode(', ', $refreshGroupIDs)); - $time = CRM_Utils_Date::getUTCTime(self::smartGroupCacheTimeout() * 60); + $time = self::getRefreshDateTime(); $query = " UPDATE civicrm_group g SET g.refresh_date = $time @@ -267,7 +266,7 @@ AND g.refresh_date IS NULL if ($processed) { // also update the group with cache date information //make sure to give original timezone settings again. - $now = CRM_Utils_Date::getUTCTime(); + $now = date('YmdHis'); $refresh = 'null'; } else { @@ -332,8 +331,7 @@ WHERE id IN ( $groupIDs ) $params = array(); $smartGroupCacheTimeout = self::smartGroupCacheTimeout(); - $now = CRM_Utils_Date::getUTCTime(); - $refreshTime = CRM_Utils_Date::getUTCTime($smartGroupCacheTimeout * 60); + $refreshTime = self::getRefreshDateTime(); if (!isset($groupID)) { if ($smartGroupCacheTimeout == 0) { @@ -705,4 +703,15 @@ ORDER BY gc.contact_id, g.children } } + /** + * Get the date when the cache should be refreshed from. + * + * Ie. now + the offset & we will delete anything prior to then. + * + * @return string + */ + protected static function getRefreshDateTime() { + return date('Ymdhis', strtotime("+ " . self::smartGroupCacheTimeout() . " Minutes")); + } + } diff --git a/CRM/Utils/Date.php b/CRM/Utils/Date.php index f58994f6b3..1a313cfc1b 100644 --- a/CRM/Utils/Date.php +++ b/CRM/Utils/Date.php @@ -1785,25 +1785,6 @@ class CRM_Utils_Date { return $format; } - /** - * Get the time in UTC for the current time. You can optionally send an offset from the current time if needed - * - * @param int $offset - * the offset from the current time in seconds. - * - * @return string - * the time in UTC - */ - public static function getUTCTime($offset = 0) { - $originalTimezone = date_default_timezone_get(); - date_default_timezone_set('UTC'); - $time = time() + $offset; - $now = date('YmdHis', $time); - date_default_timezone_set($originalTimezone); - return $now; - } - - /** * @param $date * @param $dateType diff --git a/xml/schema/ACL/Cache.xml b/xml/schema/ACL/Cache.xml index 52f34f9b46..3c1c44a793 100644 --- a/xml/schema/ACL/Cache.xml +++ b/xml/schema/ACL/Cache.xml @@ -51,7 +51,9 @@ modified_date - date + Cache Modified Date + timestamp + false When was this cache entry last modified 1.6 diff --git a/xml/schema/Contact/Group.xml b/xml/schema/Contact/Group.xml index 6f68023e73..d1c94a4e93 100644 --- a/xml/schema/Contact/Group.xml +++ b/xml/schema/Contact/Group.xml @@ -123,14 +123,14 @@ cache_date - datetime + timestamp Group Cache Date Date when we created the cache for a smart group 2.1 refresh_date - datetime + timestamp Next Group Refresh Time Date and time when we need to refresh the cache next. 4.3 -- 2.25.1