Merge pull request #14103 from jitendrapurohit/core-889
[civicrm-core.git] / CRM / Core / PrevNextCache / Sql.php
index efa1756a0219b7e932d01a79b453b676bca95ab4..86e1034ff364569cd98a66eadeab701ab121ed78 100644 (file)
@@ -34,10 +34,10 @@ class CRM_Core_PrevNextCache_Sql implements CRM_Core_PrevNextCache_Interface {
 
   /**
    * Store the results of a SQL query in the cache.
-   *
+   * @param string $cacheKey
    * @param string $sql
    *   A SQL query. The query *MUST* be a SELECT statement which yields
-   *   the following columns (in order): cacheKey, entity_id1, data
+   *   the following columns (in order): cachekey, entity_id1, data
    * @param array $sqlParams
    *   An array of parameters to be used with $sql.
    *   Use the same interpolation format as CRM_Core_DAO (composeQuery/executeQuery).
@@ -48,7 +48,7 @@ class CRM_Core_PrevNextCache_Sql implements CRM_Core_PrevNextCache_Interface {
    */
   public function fillWithSql($cacheKey, $sql, $sqlParams = []) {
     $insertSQL = "
-INSERT INTO civicrm_prevnext_cache (cacheKey, entity_id1, data)
+INSERT INTO civicrm_prevnext_cache (cachekey, entity_id1, data)
 ";
     $result = CRM_Core_DAO::executeQuery($insertSQL . $sql, $sqlParams, FALSE, NULL, FALSE, TRUE, TRUE);
     if (is_a($result, 'DB_Error')) {
@@ -65,12 +65,12 @@ INSERT INTO civicrm_prevnext_cache (cacheKey, entity_id1, data)
     $insert = CRM_Utils_SQL_Insert::into('civicrm_prevnext_cache')
       ->columns([
         'entity_id1',
-        'cacheKey',
-        'data'
+        'cachekey',
+        'data',
       ]);
 
     foreach ($rows as &$row) {
-      $insert->row($row + ['cacheKey' => $cacheKey]);
+      $insert->row($row + ['cachekey' => $cacheKey]);
     }
 
     CRM_Core_DAO::executeQuery($insert->toSQL());
@@ -83,7 +83,7 @@ INSERT INTO civicrm_prevnext_cache (cacheKey, entity_id1, data)
    * @param string $cacheKey
    * @param string $action
    *   Ex: 'select', 'unselect'.
-   * @param array|int|NULL $ids
+   * @param array|int|null $ids
    *   A list of contact IDs to (un)select.
    *   To unselect all contact IDs, use NULL.
    */
@@ -91,32 +91,32 @@ INSERT INTO civicrm_prevnext_cache (cacheKey, entity_id1, data)
     if (!$cacheKey) {
       return;
     }
-    $params = array();
+    $params = [];
 
     if ($ids && $cacheKey && $action) {
       if (is_array($ids)) {
         $cIdFilter = "(" . implode(',', $ids) . ")";
         $whereClause = "
-WHERE cacheKey = %1
+WHERE cachekey = %1
 AND (entity_id1 IN {$cIdFilter} OR entity_id2 IN {$cIdFilter})
 ";
       }
       else {
         $whereClause = "
-WHERE cacheKey = %1
+WHERE cachekey = %1
 AND (entity_id1 = %2 OR entity_id2 = %2)
 ";
-        $params[2] = array("{$ids}", 'Integer');
+        $params[2] = ["{$ids}", 'Integer'];
       }
       if ($action == 'select') {
         $whereClause .= "AND is_selected = 0";
         $sql = "UPDATE civicrm_prevnext_cache SET is_selected = 1 {$whereClause}";
-        $params[1] = array($cacheKey, 'String');
+        $params[1] = [$cacheKey, 'String'];
       }
       elseif ($action == 'unselect') {
         $whereClause .= "AND is_selected = 1";
         $sql = "UPDATE civicrm_prevnext_cache SET is_selected = 0 {$whereClause}";
-        $params[1] = array($cacheKey, 'String');
+        $params[1] = [$cacheKey, 'String'];
       }
       // default action is reseting
     }
@@ -124,9 +124,9 @@ AND (entity_id1 = %2 OR entity_id2 = %2)
       $sql = "
 UPDATE civicrm_prevnext_cache
 SET    is_selected = 0
-WHERE  cacheKey = %1 AND is_selected = 1
+WHERE  cachekey = %1 AND is_selected = 1
 ";
-      $params[1] = array($cacheKey, 'String');
+      $params[1] = [$cacheKey, 'String'];
     }
     CRM_Core_DAO::executeQuery($sql, $params);
   }
@@ -147,19 +147,19 @@ WHERE  cacheKey = %1 AND is_selected = 1
     if (!$cacheKey) {
       return NULL;
     }
-    $params = array();
+    $params = [];
 
     if ($cacheKey && ($action == 'get' || $action == 'getall')) {
       $actionGet = ($action == "get") ? " AND is_selected = 1 " : "";
       $sql = "
 SELECT entity_id1 FROM civicrm_prevnext_cache
-WHERE cacheKey = %1
+WHERE cachekey = %1
       $actionGet
 ORDER BY id
 ";
-      $params[1] = array($cacheKey, 'String');
+      $params[1] = [$cacheKey, 'String'];
 
-      $contactIds = array($cacheKey => array());
+      $contactIds = [$cacheKey => []];
       $cIdDao = CRM_Core_DAO::executeQuery($sql, $params);
       while ($cIdDao->fetch()) {
         $contactIds[$cacheKey][$cIdDao->entity_id1] = 1;
@@ -178,7 +178,7 @@ ORDER BY id
    */
   public function getPositions($cacheKey, $id1) {
     $mergeId = CRM_Core_DAO::singleValueQuery(
-      "SELECT id FROM civicrm_prevnext_cache WHERE cacheKey = %2 AND entity_id1 = %1",
+      "SELECT id FROM civicrm_prevnext_cache WHERE cachekey = %2 AND entity_id1 = %1",
       [
         1 => [$id1, 'Integer'],
         2 => [$cacheKey, 'String'],
@@ -190,8 +190,8 @@ ORDER BY id
       $pos['foundEntry'] = 1;
 
       $sql = "SELECT pn.id, pn.entity_id1, pn.entity_id2, pn.data FROM civicrm_prevnext_cache pn ";
-      $wherePrev = " WHERE pn.id < %1 AND pn.cacheKey = %2 ORDER BY ID DESC LIMIT 1";
-      $whereNext = " WHERE pn.id > %1 AND pn.cacheKey = %2 ORDER BY ID ASC LIMIT 1";
+      $wherePrev = " WHERE pn.id < %1 AND pn.cachekey = %2 ORDER BY ID DESC LIMIT 1";
+      $whereNext = " WHERE pn.id > %1 AND pn.cachekey = %2 ORDER BY ID ASC LIMIT 1";
       $p = [
         1 => [$mergeId, 'Integer'],
         2 => [$cacheKey, 'String'],
@@ -223,16 +223,16 @@ ORDER BY id
    */
   public function deleteItem($id = NULL, $cacheKey = NULL) {
     $sql = "DELETE FROM civicrm_prevnext_cache WHERE (1)";
-    $params = array();
+    $params = [];
 
     if (is_numeric($id)) {
       $sql .= " AND ( entity_id1 = %2 OR entity_id2 = %2 )";
-      $params[2] = array($id, 'Integer');
+      $params[2] = [$id, 'Integer'];
     }
 
     if (isset($cacheKey)) {
-      $sql .= " AND cacheKey = %3";
-      $params[3] = array($cacheKey, 'String');
+      $sql .= " AND cachekey = %3";
+      $params[3] = [$cacheKey, 'String'];
     }
     CRM_Core_DAO::executeQuery($sql, $params);
   }
@@ -244,7 +244,7 @@ ORDER BY id
    * @return int
    */
   public function getCount($cacheKey) {
-    $query = "SELECT COUNT(*) FROM civicrm_prevnext_cache pn WHERE pn.cacheKey = %1";
+    $query = "SELECT COUNT(*) FROM civicrm_prevnext_cache pn WHERE pn.cachekey = %1";
     $params = [1 => [$cacheKey, 'String']];
     return (int) CRM_Core_DAO::singleValueQuery($query, $params, TRUE, FALSE);
   }
@@ -259,9 +259,9 @@ ORDER BY id
    *   List of contact IDs.
    */
   public function fetch($cacheKey, $offset, $rowCount) {
-    $cids = array();
+    $cids = [];
     $dao = CRM_Utils_SQL_Select::from('civicrm_prevnext_cache pnc')
-      ->where('pnc.cacheKey = @cacheKey', ['cacheKey' => $cacheKey])
+      ->where('pnc.cachekey = @cacheKey', ['cacheKey' => $cacheKey])
       ->select('pnc.entity_id1 as cid')
       ->orderBy('pnc.id')
       ->limit($rowCount, $offset)