update Piwik to version 2.16 (fixes #91)
This commit is contained in:
parent
296343bf3b
commit
d885a4baa9
5833 changed files with 418860 additions and 226988 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
*/
|
||||
namespace Piwik\Plugins\PrivacyManager;
|
||||
|
||||
use Piwik\Common;
|
||||
use Piwik\DataAccess\ArchiveTableCreator;
|
||||
use Piwik\Date;
|
||||
use Piwik\Db;
|
||||
|
|
@ -80,12 +81,12 @@ class ReportsPurger
|
|||
public function __construct($deleteReportsOlderThan, $keepBasicMetrics, $reportPeriodsToKeep,
|
||||
$keepSegmentReports, $metricsToKeep, $maxRowsToDeletePerQuery)
|
||||
{
|
||||
$this->deleteReportsOlderThan = $deleteReportsOlderThan;
|
||||
$this->keepBasicMetrics = $keepBasicMetrics;
|
||||
$this->deleteReportsOlderThan = (int) $deleteReportsOlderThan;
|
||||
$this->keepBasicMetrics = (bool) $keepBasicMetrics;
|
||||
$this->reportPeriodsToKeep = $reportPeriodsToKeep;
|
||||
$this->keepSegmentReports = $keepSegmentReports;
|
||||
$this->keepSegmentReports = (bool) $keepSegmentReports;
|
||||
$this->metricsToKeep = $metricsToKeep;
|
||||
$this->maxRowsToDeletePerQuery = $maxRowsToDeletePerQuery;
|
||||
$this->maxRowsToDeletePerQuery = (int) $maxRowsToDeletePerQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -102,44 +103,50 @@ class ReportsPurger
|
|||
*/
|
||||
public function purgeData($optimize = false)
|
||||
{
|
||||
// find archive tables to purge
|
||||
list($oldNumericTables, $oldBlobTables) = $this->getArchiveTablesToPurge();
|
||||
|
||||
// process blob tables first, since archive status is stored in the numeric archives
|
||||
if (!empty($oldBlobTables)) {
|
||||
// if no reports should be kept, drop tables, otherwise drop individual reports
|
||||
if (empty($this->reportPeriodsToKeep) && !$this->keepSegmentReports) {
|
||||
Db::dropTables($oldBlobTables);
|
||||
} else {
|
||||
foreach ($oldBlobTables as $table) {
|
||||
$where = $this->getBlobTableWhereExpr($oldNumericTables, $table);
|
||||
if (!empty($where)) {
|
||||
$where = "WHERE $where";
|
||||
}
|
||||
Db::deleteAllRows($table, $where, "idarchive ASC", $this->maxRowsToDeletePerQuery);
|
||||
foreach ($oldBlobTables as $table) {
|
||||
$where = $this->getBlobTableWhereExpr($oldNumericTables, $table);
|
||||
if (!empty($where)) {
|
||||
$where = "WHERE $where";
|
||||
}
|
||||
|
||||
if ($optimize) {
|
||||
Db::optimizeTables($oldBlobTables);
|
||||
}
|
||||
Db::deleteAllRows($table, $where, "idarchive ASC", $this->maxRowsToDeletePerQuery);
|
||||
}
|
||||
|
||||
if ($optimize) {
|
||||
Db::optimizeTables($oldBlobTables);
|
||||
}
|
||||
}
|
||||
|
||||
// deal with numeric tables
|
||||
$this->segmentArchiveIds = null;
|
||||
|
||||
if (!empty($oldNumericTables)) {
|
||||
// if keep_basic_metrics is set, empty all numeric tables of metrics to purge
|
||||
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, "idarchive ASC", $this->maxRowsToDeletePerQuery);
|
||||
foreach ($oldNumericTables as $table) {
|
||||
$conditions = array("name NOT LIKE 'done%'");
|
||||
$bind = array();
|
||||
|
||||
if ($this->keepBasicMetrics && !empty($this->metricsToKeep)) {
|
||||
$metricFields = Common::getSqlStringFieldsArray($this->metricsToKeep);
|
||||
$bind = $this->metricsToKeep;
|
||||
$conditions[] = sprintf("name NOT IN (%s)", $metricFields);
|
||||
}
|
||||
|
||||
if ($optimize) {
|
||||
Db::optimizeTables($oldNumericTables);
|
||||
$keepWhere = $this->getBlobTableWhereExpr($oldNumericTables, $table);
|
||||
|
||||
if (!empty($keepWhere)) {
|
||||
$conditions[] = $keepWhere;
|
||||
}
|
||||
} else // drop numeric tables
|
||||
{
|
||||
Db::dropTables($oldNumericTables);
|
||||
|
||||
$where = 'WHERE ' . implode(' AND ', $conditions);
|
||||
|
||||
Db::deleteAllRows($table, $where, "idarchive ASC", $this->maxRowsToDeletePerQuery, $bind);
|
||||
}
|
||||
|
||||
if ($optimize) {
|
||||
Db::optimizeTables($oldNumericTables);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -177,7 +184,7 @@ class ReportsPurger
|
|||
}
|
||||
|
||||
// deal w/ numeric tables
|
||||
if ($this->keepBasicMetrics == 1) {
|
||||
if ($this->keepBasicMetrics) {
|
||||
// figure out which rows will be deleted
|
||||
foreach ($oldNumericTables as $table) {
|
||||
$rowCount = $this->getNumericTableDeleteCount($table);
|
||||
|
|
@ -253,12 +260,11 @@ class ReportsPurger
|
|||
{
|
||||
$maxIdArchive = Db::fetchOne("SELECT MAX(idarchive) FROM $table");
|
||||
|
||||
$sql = "SELECT COUNT(*)
|
||||
FROM $table
|
||||
WHERE name NOT IN ('" . implode("','", $this->metricsToKeep) . "')
|
||||
AND name NOT LIKE 'done%'
|
||||
AND idarchive >= ?
|
||||
AND idarchive < ?";
|
||||
$sql = "SELECT COUNT(*) FROM $table
|
||||
WHERE name NOT IN ('" . implode("','", $this->metricsToKeep) . "')
|
||||
AND name NOT LIKE 'done%'
|
||||
AND idarchive >= ?
|
||||
AND idarchive < ?";
|
||||
|
||||
$segments = Db::segmentedFetchOne($sql, 0, $maxIdArchive, self::$selectSegmentSize);
|
||||
return array_sum($segments);
|
||||
|
|
@ -268,11 +274,10 @@ class ReportsPurger
|
|||
{
|
||||
$maxIdArchive = Db::fetchOne("SELECT MAX(idarchive) FROM $table");
|
||||
|
||||
$sql = "SELECT COUNT(*)
|
||||
FROM $table
|
||||
WHERE " . $this->getBlobTableWhereExpr($oldNumericTables, $table) . "
|
||||
AND idarchive >= ?
|
||||
AND idarchive < ?";
|
||||
$sql = "SELECT COUNT(*) FROM $table
|
||||
WHERE " . $this->getBlobTableWhereExpr($oldNumericTables, $table) . "
|
||||
AND idarchive >= ?
|
||||
AND idarchive < ?";
|
||||
|
||||
$segments = Db::segmentedFetchOne($sql, 0, $maxIdArchive, self::$selectSegmentSize);
|
||||
return array_sum($segments);
|
||||
|
|
@ -289,10 +294,12 @@ class ReportsPurger
|
|||
// if not keeping segments make sure segments w/ kept periods are also deleted
|
||||
if (!$this->keepSegmentReports) {
|
||||
$this->findSegmentArchives($oldNumericTables);
|
||||
$archiveIds = $this->segmentArchiveIds[ArchiveTableCreator::getDateFromTableName($table)];
|
||||
|
||||
if (!empty($archiveIds)) {
|
||||
$where .= " OR idarchive IN (" . implode(',', $archiveIds) . ")";
|
||||
$dateFromTable = ArchiveTableCreator::getDateFromTableName($table);
|
||||
|
||||
if (!empty($this->segmentArchiveIds[$dateFromTable])) {
|
||||
$archiveIds = $this->segmentArchiveIds[$dateFromTable];
|
||||
$where .= " OR idarchive IN (" . implode(',', $archiveIds) . ")";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -307,7 +314,7 @@ class ReportsPurger
|
|||
*/
|
||||
private function findSegmentArchives($numericTables)
|
||||
{
|
||||
if (!is_null($this->segmentArchiveIds)) {
|
||||
if (!is_null($this->segmentArchiveIds) || empty($numericTables)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -316,12 +323,15 @@ class ReportsPurger
|
|||
|
||||
$maxIdArchive = Db::fetchOne("SELECT MAX(idarchive) FROM $table");
|
||||
|
||||
$sql = "SELECT idarchive
|
||||
FROM $table
|
||||
WHERE name != 'done'
|
||||
AND name LIKE 'done_%.%'
|
||||
AND idarchive >= ?
|
||||
AND idarchive < ?";
|
||||
$sql = "SELECT idarchive FROM $table
|
||||
WHERE name != 'done'
|
||||
AND name LIKE 'done_%.%'
|
||||
AND idarchive >= ?
|
||||
AND idarchive < ?";
|
||||
|
||||
if (is_null($this->segmentArchiveIds)) {
|
||||
$this->segmentArchiveIds = array();
|
||||
}
|
||||
|
||||
$this->segmentArchiveIds[$tableDate] = array();
|
||||
foreach (Db::segmentedFetchAll($sql, 0, $maxIdArchive, self::$selectSegmentSize) as $row) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue