Exemple #1
0
 public function test_deleteVisitsFor_DeletesVisitsForSpecifiedRangeAndSites_AndInvokesCallbackAfterEveryChunkIsDeleted()
 {
     $iterationCount = 0;
     $this->logDeleter->deleteVisitsFor('2012-01-01', '2012-01-02 05:05:05', 2, $iterationStep = 1, function () use(&$iterationCount) {
         ++$iterationCount;
     });
     $this->assertEquals(2, $iterationCount);
     // visits for idSite = 1 do not get deleted
     $this->assertVisitExists(1);
     $this->assertVisitExists(2);
     // visits for idSite = 2 do get deleted
     $this->assertVisitNotExists(3);
     $this->assertVisitNotExists(4);
 }
Exemple #2
0
 /**
  * Purges old data from the following tables:
  * - log_visit
  * - log_link_visit_action
  * - log_conversion
  * - log_conversion_item
  * - log_action
  *
  * @param int $deleteLogsOlderThan The number of days after which log entires are considered old.
  *                                 Visits and related data whose age is greater than this number
  *                                 will be purged.
  */
 public function purgeData($deleteLogsOlderThan)
 {
     $dateUpperLimit = Date::factory("today")->subDay($deleteLogsOlderThan);
     $this->logDeleter->deleteVisitsFor($start = null, $dateUpperLimit->getDatetime());
     $logTables = self::getDeleteTableLogTables();
     // delete unused actions from the log_action table (but only if we can lock tables)
     if (Db::isLockPrivilegeGranted()) {
         $this->rawLogDao->deleteUnusedLogActions();
     } else {
         $logMessage = get_class($this) . ": LOCK TABLES privilege not granted; skipping unused actions purge";
         Log::warning($logMessage);
     }
     // optimize table overhead after deletion
     Db::optimizeTables($logTables);
 }
Exemple #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     list($from, $to) = $this->getDateRangeToDeleteFrom($input);
     $idSite = $this->getSiteToDeleteFrom($input);
     $step = $this->getRowIterationStep($input);
     $output->writeln(sprintf("<info>Preparing to delete all visits belonging to %s between {$from} and {$to}.</info>", $idSite ? "website {$idSite}" : "ALL websites"));
     $confirm = $this->askForDeleteConfirmation($input, $output);
     if (!$confirm) {
         return;
     }
     $timer = new Timer();
     try {
         $logsDeleted = $this->logDeleter->deleteVisitsFor($from, $to, $idSite, $step, function () use($output) {
             $output->write('.');
         });
     } catch (\Exception $ex) {
         $output->writeln("");
         throw $ex;
     }
     $this->writeSuccessMessage($output, array("Successfully deleted {$logsDeleted} visits. <comment>" . $timer . "</comment>"));
     if ($input->getOption('optimize-tables')) {
         $this->optimizeTables($output);
     }
 }