Merge pull request #6091 from davecivicrm/CRM-16747
[civicrm-core.git] / CRM / Contact / BAO / GroupContactCache.php
index e3917eb887975a40b12fbae80b77e55fdbdaba3a..a1cf6d594e87940aa3b09b1a5c1415bf47c97f06 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -244,7 +244,7 @@ AND    g.refresh_date IS NULL
   }
 
   /**
-   * Change the cache_date
+   * Change the cache_date.
    *
    * @param array $groupID
    * @param bool $processed
@@ -273,7 +273,7 @@ WHERE  id IN ( $groupIDs )
   }
 
   /**
-   * Removes all the cache entries pertaining to a specific group
+   * Removes all the cache entries pertaining to a specific group.
    * If no groupID is passed in, removes cache entries for all groups
    * Has an optimization to bypass repeated invocations of this function.
    * Note that this function is an advisory, i.e. the removal respects the
@@ -394,7 +394,7 @@ WHERE  id = %1
   }
 
   /**
-   * Removes one or more contacts from the smart group cache
+   * Removes one or more contacts from the smart group cache.
    * @param int|array $cid
    * @param int $groupId
    * @return bool
@@ -419,7 +419,7 @@ WHERE  id = %1
   }
 
   /**
-   * Load the smart group cache for a saved search
+   * Load the smart group cache for a saved search.
    *
    * @param object $group
    *   The smart group that needs to be loaded.
@@ -434,8 +434,7 @@ WHERE  id = %1
     }
 
     // grab a lock so other processes dont compete and do the same query
-    $lockName = "civicrm.group.{$groupID}";
-    $lock = new CRM_Core_Lock($lockName);
+    $lock = Civi\Core\Container::singleton()->get('lockManager')->acquire("data.core.group.{$groupID}");
     if (!$lock->isAcquired()) {
       // this can cause inconsistent results since we dont know if the other process
       // will fill up the cache before our calling routine needs it.
@@ -543,7 +542,7 @@ WHERE  civicrm_group_contact.status = 'Added'
         "INSERT IGNORE INTO civicrm_group_contact_cache (contact_id, group_id)
         SELECT DISTINCT $idName, group_id FROM $tempTable
       ");
-      CRM_Core_DAO::executeQuery(" DROP TABLE $tempTable");
+      CRM_Core_DAO::executeQuery(" DROP TEMPORARY TABLE $tempTable");
     }
 
     self::updateCacheTime($groupIDs, $processed);
@@ -600,7 +599,7 @@ AND  civicrm_group_contact.group_id = $groupID ";
   }
 
   /**
-   * Get all the smart groups that this contact belongs to
+   * Get all the smart groups that this contact belongs to.
    * Note that this could potentially be a super slow function since
    * it ensure that all contact groups are loaded in the cache
    *