Beispiel #1
0
 /**
  * Purges old data from the following tables:
  * - log_visit
  * - log_link_visit_action
  * - log_conversion
  * - log_conversion_item
  * - log_action
  */
 public function purgeData()
 {
     $maxIdVisit = $this->getDeleteIdVisitOffset();
     // break if no ID was found (nothing to delete for given period)
     if (empty($maxIdVisit)) {
         return;
     }
     $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 != Piwik_Common::prefixTable('log_action')) {
             Piwik_DeleteAllRows($logTable, $where, $this->maxRowsToDeletePerQuery, array($maxIdVisit));
         }
     }
     // delete unused actions from the log_action table (but only if we can lock tables)
     if (Piwik::isLockPrivilegeGranted()) {
         $this->purgeUnusedLogActions();
     } else {
         $logMessage = get_class($this) . ": LOCK TABLES privilege not granted; skipping unused actions purge";
         Piwik::log($logMessage);
     }
     // optimize table overhead after deletion
     Piwik_OptimizeTables($logTables);
 }
Beispiel #2
0
 /**
  * Purges old report/metric data.
  * 
  * If $keepBasicMetrics is false, old numeric tables will be dropped, otherwise only
  * the metrics not in $metricsToKeep will be deleted.
  * 
  * If $reportPeriodsToKeep is an empty array, old blob tables will be dropped. Otherwise,
  * specific reports will be deleted, except reports for periods in $reportPeriodsToKeep.
  * 
  * @param bool $optimize If tables should be optimized after rows are deleted. Normally,
  *                       this is handled by a scheduled task.
  */
 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) {
             Piwik_DropTables($oldBlobTables);
         } else {
             foreach ($oldBlobTables as $table) {
                 $where = $this->getBlobTableWhereExpr($oldNumericTables, $table);
                 if (!empty($where)) {
                     $where = "WHERE {$where}";
                 }
                 Piwik_DeleteAllRows($table, $where, $this->maxRowsToDeletePerQuery);
             }
             if ($optimize) {
                 Piwik_OptimizeTables($oldBlobTables);
             }
         }
     }
     // deal with numeric tables
     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) {
                 Piwik_DeleteAllRows($table, $where, $this->maxRowsToDeletePerQuery);
             }
             if ($optimize) {
                 Piwik_OptimizeTables($oldNumericTables);
             }
         } else {
             Piwik_DropTables($oldNumericTables);
         }
     }
 }
Beispiel #3
0
 /**
  * Soft deletes a given Goal.
  * Stats data in the archives will still be recorded, but not displayed.
  * 
  * @param int $idSite
  * @param int $idGoal
  * @return void
  */
 public function deleteGoal($idSite, $idGoal)
 {
     Piwik::checkUserHasAdminAccess($idSite);
     Piwik_Query("UPDATE " . Piwik_Common::prefixTable('goal') . "\n\t\t\t\t\t\t\t\t\t\tSET deleted = 1\n\t\t\t\t\t\t\t\t\t\tWHERE idsite = ? \n\t\t\t\t\t\t\t\t\t\t\tAND idgoal = ?", array($idSite, $idGoal));
     Piwik_DeleteAllRows(Piwik_Common::prefixTable("log_conversion"), "WHERE idgoal = ?", 100000, array($idGoal));
     Piwik_Common::regenerateCacheWebsiteAttributes($idSite);
 }