(dev/core#217) Campaign Selector - Change direct SQL call to `prevnext->fillWithSql...
authorTim Otten <totten@civicrm.org>
Mon, 2 Jul 2018 22:58:45 +0000 (15:58 -0700)
committerTim Otten <totten@civicrm.org>
Tue, 24 Jul 2018 00:40:48 +0000 (17:40 -0700)
CRM/Campaign/Selector/Search.php

index 6f7d3fccab94728bb7ef983e2af516e82d35a514..08b233be673a1ba5537b66445ee0a6d416dfea38 100644 (file)
@@ -281,18 +281,19 @@ class CRM_Campaign_Selector_Search extends CRM_Core_Selector_Base implements CRM
         $this->_campaignFromClause
       );
       list($select, $from) = explode(' FROM ', $sql);
-      $insertSQL = "
-INSERT INTO civicrm_prevnext_cache ( entity_table, entity_id1, entity_id2, cacheKey, data )
-SELECT 'civicrm_contact', contact_a.id, contact_a.id, '$cacheKey', contact_a.display_name
+      $selectSQL = "
+      SELECT 'civicrm_contact', contact_a.id, contact_a.id, '$cacheKey', contact_a.display_name
 FROM {$from}
 ";
-      $errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
-      $result = CRM_Core_DAO::executeQuery($insertSQL);
-      unset($errorScope);
 
-      if (is_a($result, 'DB_Error')) {
+      try {
+        Civi::service('prevnext')->fillWithSql($cacheKey, $selectSQL);
+      }
+      catch (CRM_Core_Exception $e) {
+        // Heavy handed, no? Seems like this merits an explanation.
         return;
       }
+
       // also record an entry in the cache key table, so we can delete it periodically
       CRM_Core_BAO_Cache::setItem($cacheKey, 'CiviCRM Search PrevNextCache', $cacheKey);
     }