CRM-18516 Convert the date fields relating to group caching & acl caching timestamp
authoreileen <emcnaughton@wikimedia.org>
Sat, 7 May 2016 23:18:10 +0000 (09:18 +1000)
committereileen <emcnaughton@wikimedia.org>
Sun, 5 Jun 2016 15:09:40 +0000 (09:09 -0600)
Conflicts:
CRM/Upgrade/Incremental/sql/4.7.8.mysql.tpl
xml/schema/ACL/Cache.xml

CRM/ACL/BAO/Cache.php
CRM/Contact/BAO/GroupContactCache.php
CRM/Utils/Date.php
xml/schema/ACL/Cache.xml
xml/schema/Contact/Group.xml

index b665d2013d944d2b0898b0bb98ca3cf69b701259..6f88774dec481930039d73dbd4c03cf27c25123a 100644 (file)
@@ -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);
 
index 2e3ee1b0b405a38832ac90117bc73ae6bab78a54..c105e87fa0ce1229c42f1d088e11fb203f16a41e 100644 (file)
@@ -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"));
+  }
+
 }
index f58994f6b3b1dfcabb65da9873923282072718b3..1a313cfc1b63ed3dd1b0c1abe33c87d85b8c30f1 100644 (file)
@@ -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
index 52f34f9b466ed83903d6816f20424cce59b223d2..3c1c44a793e0e1c8b928b2f5e1c0083d1b3199ac 100644 (file)
@@ -51,7 +51,9 @@
   </index>
   <field>
     <name>modified_date</name>
-    <type>date</type>
+    <title>Cache Modified Date</title>
+    <type>timestamp</type>
+    <required>false</required>
     <comment>When was this cache entry last modified</comment>
     <add>1.6</add>
   </field>
index 6f68023e738a90d31f2fe2d8cc1df84205bb5596..d1c94a4e9314b4af6e24bf965078301bae099fea 100644 (file)
   </field>
   <field>
     <name>cache_date</name>
-    <type>datetime</type>
+    <type>timestamp</type>
     <title>Group Cache Date</title>
     <comment>Date when we created the cache for a smart group</comment>
     <add>2.1</add>
   </field>
   <field>
     <name>refresh_date</name>
-    <type>datetime</type>
+    <type>timestamp</type>
     <title>Next Group Refresh Time</title>
     <comment>Date and time when we need to refresh the cache next.</comment>
     <add>4.3</add>