diff options
author | diosmosis <benaka@piwik.pro> | 2015-05-08 02:22:46 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-06-11 09:42:03 +0300 |
commit | b48e09afd39bed3a598287d4aa8ac2a39c2c4082 (patch) | |
tree | 61b2e6e9ecf3bc95733f2b272fd5f69e6e5a94af /plugins/PrivacyManager | |
parent | b8a5e03580b70e723c743541c632076008403f3d (diff) |
Use LogPurger in PrivacyManager's LogDataPurger class and get PrivacyManagerTest to pass.
Diffstat (limited to 'plugins/PrivacyManager')
-rwxr-xr-x | plugins/PrivacyManager/LogDataPurger.php | 59 |
1 files changed, 42 insertions, 17 deletions
diff --git a/plugins/PrivacyManager/LogDataPurger.php b/plugins/PrivacyManager/LogDataPurger.php index 21421f11d2..81b4aaebaa 100755 --- a/plugins/PrivacyManager/LogDataPurger.php +++ b/plugins/PrivacyManager/LogDataPurger.php @@ -9,9 +9,12 @@ namespace Piwik\Plugins\PrivacyManager; use Piwik\Common; +use Piwik\Container\StaticContainer; +use Piwik\DataAccess\RawLogDao; use Piwik\Date; use Piwik\Db; use Piwik\Log; +use Piwik\LogPurger; use Piwik\Piwik; /** @@ -32,11 +35,34 @@ class LogDataPurger private $dimensionMetadataProvider; /** + * TODO + * + * @var LogPurger + */ + private $logPurger; + + /** + * TODO + * + * @var RawLogDao + */ + private $rawLogDao; + + /** + * TODO + * + * @var int + */ + private $logIterationStepSize = 1000; // TODO: make configurable via constructor + + /** * Constructor. */ - public function __construct(DimensionMetadataProvider $dimensionMetadataProvider) + public function __construct(DimensionMetadataProvider $dimensionMetadataProvider, LogPurger $logPurger, RawLogDao $rawLogDao) { $this->dimensionMetadataProvider = $dimensionMetadataProvider; + $this->logPurger = $logPurger; + $this->rawLogDao = $rawLogDao; } /** @@ -55,33 +81,28 @@ class LogDataPurger */ public function purgeData($deleteLogsOlderThan, $maxRowsToDeletePerQuery) { - $maxIdVisit = $this->getDeleteIdVisitOffset($deleteLogsOlderThan); + $dateStart = Date::factory("today")->subDay($deleteLogsOlderThan); // TODO: move logic to constructor + $conditions = array( + array('visit_last_action_time', '<', $dateStart->getDatetime()) + ); - // break if no ID was found (nothing to delete for given period) - if (empty($maxIdVisit)) { - return; - } + $logPurger = $this->logPurger; + $this->rawLogDao->forAllLogs('log_visit', array('idvisit'), $conditions, $this->logIterationStepSize, function ($rows) use ($logPurger) { + $ids = array_map('reset', $rows); + $logPurger->deleteVisits($ids); + }); $logTables = self::getDeleteTableLogTables(); - // delete data from log tables - $where = "WHERE idvisit <= ?"; - 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, "idvisit ASC", $maxRowsToDeletePerQuery, array($maxIdVisit)); - } - } - // delete unused actions from the log_action table (but only if we can lock tables) if (Db::isLockPrivilegeGranted()) { - $this->purgeUnusedLogActions(); + $this->purgeUnusedLogActions(); // TODO: move actual code to DAO/service in core } else { $logMessage = get_class($this) . ": LOCK TABLES privilege not granted; skipping unused actions purge"; Log::warning($logMessage); } - // optimize table overhead after deletion + // optimize table overhead after deletion // TODO: logs:delete command should allow optimization Db::optimizeTables($logTables); } @@ -95,6 +116,10 @@ class LogDataPurger * Visits and related data whose age is greater than this number * will be purged. * @return array + * + * TODO: purge estimate should ideally not use idvisit, but we have to wait until performance tests are done to + * really test this. + * TODO: let's move PrivacyManagerTest to PrivacyManager plugin */ public function getPurgeEstimate($deleteLogsOlderThan) { |