From 1948b754cc13fa8a144bf8ac63f9fed1b24470cd Mon Sep 17 00:00:00 2001
From: mattab <matthieu.aubry@gmail.com>
Date: Wed, 22 Jan 2014 11:10:17 +1300
Subject: [PATCH] Call Table\Manager::deleteAll() for both Days and Periods,
 not only for Periods

---
 core/ArchiveProcessor.php                 | 3 ---
 core/ArchiveProcessor/PluginsArchiver.php | 8 ++++++++
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/core/ArchiveProcessor.php b/core/ArchiveProcessor.php
index 6aa62cdc9d..a8eaaf7056 100644
--- a/core/ArchiveProcessor.php
+++ b/core/ArchiveProcessor.php
@@ -194,8 +194,6 @@ class ArchiveProcessor
                                               &$columnsAggregationOperation = null,
                                               $columnsToRenameAfterAggregation = null)
     {
-        // We clean up below all tables created during this function call (and recursive calls)
-        $latestUsedTableId = Manager::getInstance()->getMostRecentTableId();
         if (!is_array($recordNames)) {
             $recordNames = array($recordNames);
         }
@@ -210,7 +208,6 @@ class ArchiveProcessor
             Common::destroy($table);
             $this->insertBlobRecord($recordName, $blob);
         }
-        Manager::getInstance()->deleteAll($latestUsedTableId);
 
         return $nameToCount;
     }
diff --git a/core/ArchiveProcessor/PluginsArchiver.php b/core/ArchiveProcessor/PluginsArchiver.php
index 671e8272fb..c8a6859b53 100644
--- a/core/ArchiveProcessor/PluginsArchiver.php
+++ b/core/ArchiveProcessor/PluginsArchiver.php
@@ -15,6 +15,7 @@ use Piwik\Archive;
 use Piwik\ArchiveProcessor;
 use Piwik\DataAccess\ArchiveSelector;
 use Piwik\DataAccess\ArchiveWriter;
+use Piwik\DataTable\Manager;
 use Piwik\Metrics;
 use Piwik\Plugin\Archiver;
 
@@ -87,6 +88,10 @@ class PluginsArchiver
         $archivers = $this->getPluginArchivers();
 
         foreach($archivers as $pluginName => $archiverClass) {
+
+            // We clean up below all tables created during this function call (and recursive calls)
+            $latestUsedTableId = Manager::getInstance()->getMostRecentTableId();
+
             /** @var Archiver $archiver */
             $archiver = new $archiverClass($this->archiveProcessor);
 
@@ -97,6 +102,9 @@ class PluginsArchiver
                     $archiver->aggregateMultipleReports();
                 }
             }
+
+            Manager::getInstance()->deleteAll($latestUsedTableId);
+            unset($archiver);
         }
     }
 
-- 
GitLab