From a986056d92476532386ba2f434a83da2ab90de8b 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 --- CRM/ACL/BAO/Cache.php | 5 +---- CRM/Contact/BAO/GroupContactCache.php | 23 ++++++++++++++------- CRM/Upgrade/Incremental/sql/4.7.8.mysql.tpl | 4 ++++ CRM/Utils/Date.php | 19 ----------------- xml/schema/ACL/Cache.xml | 2 +- xml/schema/Contact/Group.xml | 4 ++-- 6 files changed, 24 insertions(+), 33 deletions(-) diff --git a/CRM/ACL/BAO/Cache.php b/CRM/ACL/BAO/Cache.php index 6f302a7a68..f0b67a2057 100644 --- a/CRM/ACL/BAO/Cache.php +++ b/CRM/ACL/BAO/Cache.php @@ -149,14 +149,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 242a8110c5..2785d34c0e 100644 --- a/CRM/Contact/BAO/GroupContactCache.php +++ b/CRM/Contact/BAO/GroupContactCache.php @@ -68,7 +68,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 @@ -76,8 +75,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 ) ) "; @@ -177,7 +176,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 @@ -266,7 +265,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 { @@ -329,8 +328,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) { @@ -708,4 +706,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/Upgrade/Incremental/sql/4.7.8.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.7.8.mysql.tpl index 641b3335b7..6fc87f8fc0 100644 --- a/CRM/Upgrade/Incremental/sql/4.7.8.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.7.8.mysql.tpl @@ -3,6 +3,10 @@ #CRM-17967 - Allow conact image file name length during upload up to 255 characters long ALTER TABLE `civicrm_contact` CHANGE `image_URL` `image_URL` VARCHAR(512) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT 'optional URL for preferred image (photo, logo, etc.) to display for this contact.'; +-- CRM-18516 Convert the date fields relating to group caching and acl caching timestamp +ALTER TABLE civicrm_group CHANGE cache_date cache_date timestamp NULL DEFAULT NULL , CHANGE refresh_date refresh_date timestamp NULL DEFAULT NULL; +ALTER TABLE civicrm_acl_cache CHANGE modified_date modified_date timestamp NULL DEFAULT NULL; + -- CRM-18537 DELETE FROM civicrm_state_province WHERE name = 'Fernando de Noronha'; diff --git a/CRM/Utils/Date.php b/CRM/Utils/Date.php index fbf073ab9f..a53acb6cd1 100644 --- a/CRM/Utils/Date.php +++ b/CRM/Utils/Date.php @@ -1836,25 +1836,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 a798dff6ac..781ab64bee 100644 --- a/xml/schema/ACL/Cache.xml +++ b/xml/schema/ACL/Cache.xml @@ -55,7 +55,7 @@ modified_date Cache Modified Date - date + timestamp 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