diff --git a/core/Db.php b/core/Db.php index ef2f756f9d4d2d3dc3c509f4f8e84bb636a4c31b..a8369943ba2031f0a6990c7777af4c64e154a434 100644 --- a/core/Db.php +++ b/core/Db.php @@ -156,11 +156,15 @@ class Db * @param string $where The where clause of the query. Must include the WHERE keyword. * @param int $maxRowsPerQuery The maximum number of rows to delete per DELETE query. * @param array $parameters Parameters to bind in the query. + * @param string $primaryKey Name of primary key to sort by. * @return int The total number of rows deleted. */ - static public function deleteAllRows($table, $where, $maxRowsPerQuery = 100000, $parameters = array()) + static public function deleteAllRows($table, $where, $orderBy, $maxRowsPerQuery = 100000, $parameters = array()) { - $sql = "DELETE FROM $table $where LIMIT " . (int)$maxRowsPerQuery; + $sql = "DELETE FROM $table + $where + ORDER BY $orderBy ASC + LIMIT " . (int)$maxRowsPerQuery; // delete rows w/ a limit $totalRowsDeleted = 0; diff --git a/plugins/Goals/API.php b/plugins/Goals/API.php index 59866c89236ca7e1b66aca207aef088d8388257c..327e643405dc86a00de40ab5451147d8580a3537 100644 --- a/plugins/Goals/API.php +++ b/plugins/Goals/API.php @@ -207,7 +207,7 @@ class API WHERE idsite = ? AND idgoal = ?", array($idSite, $idGoal)); - Db::deleteAllRows(Common::prefixTable("log_conversion"), "WHERE idgoal = ?", 100000, array($idGoal)); + Db::deleteAllRows(Common::prefixTable("log_conversion"), "WHERE idgoal = ?", "idvisit", 100000, array($idGoal)); Cache::regenerateCacheWebsiteAttributes($idSite); } diff --git a/plugins/PrivacyManager/LogDataPurger.php b/plugins/PrivacyManager/LogDataPurger.php index 82b1a284dd124eeb6c1b0459bbc5b8c83d8aeec7..8fc1f3e3b0df8848655108e90773742629e528eb 100755 --- a/plugins/PrivacyManager/LogDataPurger.php +++ b/plugins/PrivacyManager/LogDataPurger.php @@ -76,7 +76,7 @@ class LogDataPurger foreach ($logTables as $logTable) { // deleting from log_action must be handled differently, so we do it later if ($logTable != Common::prefixTable('log_action')) { - Db::deleteAllRows($logTable, $where, $this->maxRowsToDeletePerQuery, array($maxIdVisit)); + Db::deleteAllRows($logTable, $where, "idvisit", $this->maxRowsToDeletePerQuery, array($maxIdVisit)); } } diff --git a/plugins/PrivacyManager/ReportsPurger.php b/plugins/PrivacyManager/ReportsPurger.php index c709cf34dd3408c0965a7e0f257f28dfd02407be..df023999d4a9f16233741f4d303b4904cc8d6e4a 100755 --- a/plugins/PrivacyManager/ReportsPurger.php +++ b/plugins/PrivacyManager/ReportsPurger.php @@ -118,7 +118,7 @@ class ReportsPurger if (!empty($where)) { $where = "WHERE $where"; } - Db::deleteAllRows($table, $where, $this->maxRowsToDeletePerQuery); + Db::deleteAllRows($table, $where, "idarchive", $this->maxRowsToDeletePerQuery); } if ($optimize) { @@ -133,7 +133,7 @@ class ReportsPurger if ($this->keepBasicMetrics == 1 && !empty($this->metricsToKeep)) { $where = "WHERE name NOT IN ('" . implode("','", $this->metricsToKeep) . "') AND name NOT LIKE 'done%'"; foreach ($oldNumericTables as $table) { - Db::deleteAllRows($table, $where, $this->maxRowsToDeletePerQuery); + Db::deleteAllRows($table, $where, "idarchive", $this->maxRowsToDeletePerQuery); } if ($optimize) {