Merge pull request #11972 from eileenmcnaughton/sch
[civicrm-core.git] / CRM / Contact / Selector.php
index b4135b71851605240edcc75a2f8e39ac115d7ee4..a4145e062044d80c45fb6f21a4720d9497d23078 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.7                                                |
+ | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
@@ -1029,7 +1029,10 @@ SELECT DISTINCT 'civicrm_contact', contact_a.id, contact_a.id, '$cacheKey', cont
 
     $sql = str_replace(array("SELECT contact_a.id as contact_id", "SELECT contact_a.id as id"), $insertSQL, $sql);
     try {
-      CRM_Core_DAO::executeQuery($sql);
+      $result = CRM_Core_DAO::executeQuery($sql, [], FALSE, NULL, FALSE, TRUE, TRUE);
+      if (is_a($result, 'DB_Error')) {
+        throw new CRM_Core_Exception($result->message);
+      }
     }
     catch (CRM_Core_Exception $e) {
       if ($coreSearch) {
@@ -1038,7 +1041,10 @@ SELECT DISTINCT 'civicrm_contact', contact_a.id, contact_a.id, '$cacheKey', cont
         $this->rebuildPreNextCache($start, $end, $sort, $cacheKey);
       }
       else {
-        CRM_Core_Session::setStatus(ts('Query Failed'));
+        // This will always show for CiviRules :-( as a) it orders by 'rule_label'
+        // which is not available in the query & b) it uses contact not contact_a
+        // as an alias.
+        // CRM_Core_Session::setStatus(ts('Query Failed'));
         return;
       }
     }