diff options
author | diosmosis <benaka@piwik.pro> | 2015-05-11 14:16:19 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-06-11 09:42:04 +0300 |
commit | 97abd79c07c8fcf86b27f244dbb042f64c01afe6 (patch) | |
tree | f4f8f1d415ee97256ba68c16f4a870b8f802c369 /plugins/UserCountry | |
parent | d822c3c4b6065a4ee68affa9998fb405b9ab5382 (diff) |
Move usercountry:attribute iteration logic to VisitorGeolocator plugin.
Diffstat (limited to 'plugins/UserCountry')
-rw-r--r-- | plugins/UserCountry/Commands/AttributeHistoricalDataWithLocations.php | 22 | ||||
-rw-r--r-- | plugins/UserCountry/VisitorGeolocator.php | 32 |
2 files changed, 34 insertions, 20 deletions
diff --git a/plugins/UserCountry/Commands/AttributeHistoricalDataWithLocations.php b/plugins/UserCountry/Commands/AttributeHistoricalDataWithLocations.php index a3c85174ba..5e617f53e6 100644 --- a/plugins/UserCountry/Commands/AttributeHistoricalDataWithLocations.php +++ b/plugins/UserCountry/Commands/AttributeHistoricalDataWithLocations.php @@ -115,30 +115,12 @@ class AttributeHistoricalDataWithLocations extends ConsoleCommand protected function processSpecifiedLogsInChunks(OutputInterface $output, $from, $to, $segmentLimit) { - $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) - ); - $self = $this; - $this->dao->forAllLogs('log_visit', $visitFieldsToSelect, $conditions, $segmentLimit, function ($logs) use ($self, $output) { - if (!empty($logs)) { - $self->reattributeVisitLogs($output, $logs); - } + $this->visitorGeolocator->reattributeVisitLogs($from, $to, $idSite = null, $segmentLimit, function () use ($output, $self) { + $self->onVisitProcessed($output); }); } - protected function reattributeVisitLogs(OutputInterface $output, $logRows) - { - foreach ($logRows as $row) { - $this->visitorGeolocator->attributeExistingVisit($row); - - $this->onVisitProcessed($output); - } - } - /** * @param InputInterface $input * @return int diff --git a/plugins/UserCountry/VisitorGeolocator.php b/plugins/UserCountry/VisitorGeolocator.php index be960c02f9..a12cbb5118 100644 --- a/plugins/UserCountry/VisitorGeolocator.php +++ b/plugins/UserCountry/VisitorGeolocator.php @@ -274,4 +274,36 @@ class VisitorGeolocator } return self::$defaultLocationCache; } + + /** + * @param $from + * @param $to + * @param null $idSite + * @param int $segmentLimit + * @param callable $onLogProcessed + */ + public function reattributeVisitLogs($from, $to, $idSite = null, $segmentLimit = 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, $segmentLimit, function ($logs) use ($self, $onLogProcessed) { + foreach ($logs as $row) { + $self->attributeExistingVisit($row); + + if (!empty($onLogProcessed)) { + $onLogProcessed($row); + } + } + }); + } }
\ No newline at end of file |