Merge remote-tracking branch 'upstream/4.4' into 4.4-4.5-2014-09-29-14-51-22
[civicrm-core.git] / CRM / Contact / BAO / GroupContactCache.php
index 9a82607c459b5f84fc804a525ecda5b7132911bf..a88d317325675d0aa44f7623b0036b4d1ed86331 100644 (file)
@@ -190,6 +190,18 @@ AND    g.refresh_date IS NULL
     }
   }
 
+  /**
+   * FIXME: This function should not be needed, because the cache table should not be getting truncated
+   */
+  static function fillIfEmpty() {
+    if (!CRM_Core_DAO::singleValueQuery("SELECT COUNT(id) FROM civicrm_group_contact_cache")) {
+      self::loadAll();
+    }
+  }
+
+  /**
+   * @param $groupID
+   */
   static function add($groupID) {
     // first delete the current cache
     self::remove($groupID);
@@ -205,6 +217,10 @@ AND    g.refresh_date IS NULL
     }
   }
 
+  /**
+   * @param $groupID
+   * @param $values
+   */
   static function store(&$groupID, &$values) {
     $processed = FALSE;
 
@@ -435,6 +451,7 @@ WHERE  id = %1
         $customClass =
           CRM_Contact_BAO_SearchCustom::customClass($ssParams['customSearchID'], $savedSearchID);
         $searchSQL = $customClass->contactIDs();
+        $searchSQL = str_replace('ORDER BY contact_a.id ASC', '', $searchSQL);
         $idName = 'contact_id';
       }
       else {
@@ -533,6 +550,9 @@ AND  civicrm_group_contact.group_id = $groupID ";
     $lock->release();
   }
 
+  /**
+   * @return int
+   */
   static function smartGroupCacheTimeout() {
     $config = CRM_Core_Config::singleton();
 
@@ -616,7 +636,7 @@ ORDER BY   gc.contact_id, g.children
       $contactGroup[$prevContactID]['groupTitle'] = implode(', ', $contactGroup[$prevContactID]['groupTitle']);
     }
 
-    if (is_numeric($contactID)) {
+    if ((!empty($contactGroup[$contactID]) && is_numeric($contactID))) {
       return $contactGroup[$contactID];
     }
     else {