/** * Executes a data purge, deleting log data and report data using the current config * options. Echo's the result of getDatabaseSize after purging. */ public function executeDataPurge() { Piwik::checkUserHasSuperUserAccess(); $this->checkTokenInUrl(); // if the request isn't a POST, redirect to index if ($_SERVER["REQUEST_METHOD"] != "POST" && !Common::isPhpCliMode()) { $this->redirectToIndex('PrivacyManager', 'privacySettings'); return; } $settings = PrivacyManager::getPurgeDataSettings(); if ($settings['delete_logs_enable']) { $logDataPurger = LogDataPurger::make($settings); $logDataPurger->purgeData(); } if ($settings['delete_reports_enable']) { $reportsPurger = ReportsPurger::make($settings, PrivacyManager::getAllMetricsToKeep()); $reportsPurger->purgeData(true); } }
/** * Returns an array describing what data would be purged if both log data & report * purging is invoked. * * The returned array maps table names with the number of rows that will be deleted. * If the table name is mapped with -1, the table will be dropped. * * @param array $settings The config options to use in the estimate. If null, the real * options are used. * @return array */ public static function getPurgeEstimate($settings = null) { if (is_null($settings)) { $settings = self::getPurgeDataSettings(); } $result = array(); if ($settings['delete_logs_enable']) { $logDataPurger = LogDataPurger::make($settings); $result = array_merge($result, $logDataPurger->getPurgeEstimate()); } if ($settings['delete_reports_enable']) { $reportsPurger = ReportsPurger::make($settings, self::getAllMetricsToKeep()); $result = array_merge($result, $reportsPurger->getPurgeEstimate()); } return $result; }
/** * Test no concurrency issues when deleting log data from log_action table. * * @group Integration */ public function testPurgeLogDataConcurrency() { \Piwik\Piwik::addAction("LogDataPurger.ActionsToKeepInserted.olderThan", array($this, 'addReferenceToUnusedAction')); $purger = LogDataPurger::make($this->settings, true); $this->unusedIdAction = Db::fetchOne("SELECT idaction FROM " . Common::prefixTable('log_action') . " WHERE name = ?", array('whatever.com/_40')); $this->assertTrue($this->unusedIdAction > 0); // purge data $purger->purgeData(); // check that actions were purged $this->assertEquals(22 + $this->getCountEventIdsNotPurged(), $this->_getTableCount('log_action')); // January // check that the unused action still exists $count = Db::fetchOne("SELECT COUNT(*) FROM " . Common::prefixTable('log_action') . " WHERE idaction = ?", array($this->unusedIdAction)); $this->assertEquals(1, $count); $this->unusedIdAction = null; // so the hook won't get executed twice }