X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FLogging%2FDiffer.php;h=b6040c7bbac6aa531bcb12ae1efd75adec8c0492;hb=4a857b55aa93910463dad24efcdf76035b50a517;hp=863322bb2aae8f04b3499783396023da5b6fe5a0;hpb=58d1e21e44d0392974b0cf596d69e735c7fe9d2b;p=civicrm-core.git diff --git a/CRM/Logging/Differ.php b/CRM/Logging/Differ.php index 863322bb2a..b6040c7bba 100644 --- a/CRM/Logging/Differ.php +++ b/CRM/Logging/Differ.php @@ -403,11 +403,20 @@ ORDER BY log_date * * @param array $tables * Array of tables to inspect. + * @param int $limit + * Limit result to x + * @param int $offset + * Offset result to y * * @return array */ - public function getAllChangesForConnection($tables) { - $params = [1 => [$this->log_conn_id, 'String']]; + public function getAllChangesForConnection($tables, $limit = 0, $offset = 0) { + $params = [ + 1 => [$this->log_conn_id, 'String'], + 2 => [$limit, 'Integer'], + 3 => [$offset, 'Integer'], + ]; + foreach ($tables as $table) { if (empty($sql)) { $sql = " SELECT '{$table}' as table_name, id FROM {$this->db}.log_{$table} WHERE log_conn_id = %1"; @@ -416,17 +425,48 @@ ORDER BY log_date $sql .= " UNION SELECT '{$table}' as table_name, id FROM {$this->db}.log_{$table} WHERE log_conn_id = %1"; } } + if ($limit) { + $sql .= " LIMIT %2"; + } + if ($offset) { + $sql .= " OFFSET %3"; + } $diffs = []; $dao = CRM_Core_DAO::executeQuery($sql, $params); while ($dao->fetch()) { if (empty($this->log_date)) { - $this->log_date = CRM_Core_DAO::singleValueQuery("SELECT log_date FROM {$this->db}.log_{$table} WHERE log_conn_id = %1 LIMIT 1", $params); + // look for available table in above query instead of looking for last table. this will avoid multiple loops + $this->log_date = CRM_Core_DAO::singleValueQuery("SELECT log_date FROM {$this->db}.log_{$dao->table_name} WHERE log_conn_id = %1 LIMIT 1", $params); } $diffs = array_merge($diffs, $this->diffsInTableForId($dao->table_name, $dao->id)); } return $diffs; } + /** + * Get count of all changes made in the connection. + * + * @param array $tables + * Array of tables to inspect. + * + * @return array + */ + public function getCountOfAllContactChangesForConnection($tables) { + $count = 0; + $params = [1 => [$this->log_conn_id, 'String']]; + foreach ($tables as $table) { + if (empty($sql)) { + $sql = " SELECT '{$table}' as table_name, id FROM {$this->db}.log_{$table} WHERE log_conn_id = %1"; + } + else { + $sql .= " UNION SELECT '{$table}' as table_name, id FROM {$this->db}.log_{$table} WHERE log_conn_id = %1"; + } + } + $countSQL = " SELECT count(*) as countOfContacts FROM ({$sql}) count"; + $count = CRM_Core_DAO::singleValueQuery($countSQL, $params); + return $count; + } + /** * Check that the log record relates to a unique log id. *