Esempio n. 1
0
 /**
  * Deletes visits within the specified date range and belonging to the specified site (if any). Visits are
  * deleted in chunks, so only `$iterationStep` visits are deleted at a time.
  *
  * @param string|null $startDatetime A datetime string. Visits that occur at this time or after are deleted. If not supplied,
  *                                   visits from the beginning of time are deleted.
  * @param string|null $endDatetime A datetime string. Visits that occur before this time are deleted. If not supplied,
  *                                 visits from the end of time are deleted.
  * @param int|null $idSite The site to delete visits from.
  * @param int $iterationStep The number of visits to delete at a single time.
  * @param callable $afterChunkDeleted Callback executed after every chunk of visits are deleted.
  * @return int The number of visits deleted.
  */
 public function deleteVisitsFor($startDatetime, $endDatetime, $idSite = null, $iterationStep = 1000, $afterChunkDeleted = null)
 {
     $fields = array('idvisit');
     $conditions = array();
     if (!empty($startDatetime)) {
         $conditions[] = array('visit_last_action_time', '>=', $startDatetime);
     }
     if (!empty($endDatetime)) {
         $conditions[] = array('visit_last_action_time', '<', $endDatetime);
     }
     if (!empty($idSite)) {
         $conditions[] = array('idsite', '=', $idSite);
     }
     $logsDeleted = 0;
     $logPurger = $this;
     $this->rawLogDao->forAllLogs('log_visit', $fields, $conditions, $iterationStep, function ($logs) use($logPurger, &$logsDeleted, $afterChunkDeleted) {
         $ids = array_map(function ($row) {
             return reset($row);
         }, $logs);
         $logsDeleted += $logPurger->deleteVisits($ids);
         if (!empty($afterChunkDeleted)) {
             $afterChunkDeleted($logsDeleted);
         }
     });
     return $logsDeleted;
 }
 /**
  * Re-geolocate visits within a date range for a specified site (if any).
  *
  * @param string $from A datetime string to treat as the lower bound. Visits newer than this date are processed.
  * @param string $to A datetime string to treat as the upper bound. Visits older than this date are processed.
  * @param int|null $idSite If supplied, only visits for this site are re-attributed.
  * @param int $iterationStep The number of visits to re-attribute at the same time.
  * @param callable|null $onLogProcessed If supplied, this callback is called after every row is processed.
  *                                      The processed visit and the updated values are passed to the callback.
  */
 public function reattributeVisitLogs($from, $to, $idSite = null, $iterationStep = 1000, $onLogProcessed = null)
 {
     $visitFieldsToSelect = array_merge(array('idvisit', 'location_ip'), array_keys(VisitorGeolocator::$logVisitFieldsToUpdate));
     $conditions = array(array('visit_last_action_time', '>=', $from), array('visit_last_action_time', '<', $to));
     if (!empty($idSite)) {
         $conditions[] = array('idsite', '=', $idSite);
     }
     $self = $this;
     $this->dao->forAllLogs('log_visit', $visitFieldsToSelect, $conditions, $iterationStep, function ($logs) use($self, $onLogProcessed) {
         foreach ($logs as $row) {
             $updatedValues = $self->attributeExistingVisit($row);
             if (!empty($onLogProcessed)) {
                 $onLogProcessed($row, $updatedValues);
             }
         }
     });
 }