DO NOT MERGE patch for CRM-12840 by Jamie McClelland
authorColeman Watts <coleman@civicrm.org>
Tue, 20 Aug 2013 03:33:32 +0000 (20:33 -0700)
committerColeman Watts <coleman@civicrm.org>
Tue, 20 Aug 2013 03:33:32 +0000 (20:33 -0700)
CRM/Contact/Selector.php

index 31d1aa2fb1a177be0afc65f9587cd29be986e7dd..ebe9c15b0710408465d47aca9f5ffe6825ba5626 100644 (file)
@@ -911,6 +911,13 @@ SELECT 'civicrm_contact', contact_a.id, contact_a.id, '$cacheKey', contact_a.dis
 
     $sql = str_replace($replaceSQL, $insertSQL, $sql);
 
+    // The prevnext_cache does not need to be in order, and the ORDER BY clause
+    // can break the query if it we're in advanced search and we are using a
+    // search view that uses fields not in the civicrm_contact table.
+    // See: 12840.
+    if(preg_match('/(.*) ORDER BY .*/is',$sql, $matches)) {
+      $sql = $matches[1];
+    }
 
     CRM_Core_Error::ignoreException();
     $result = CRM_Core_DAO::executeQuery($sql);