Skip to content

Commit

Permalink
Refs #2981 Fix display of visits in archive.php output
Browse files Browse the repository at this point in the history
  • Loading branch information
mattab committed Mar 17, 2014
1 parent 971263c commit 1fd459b
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions core/CronArchive.php
Expand Up @@ -297,12 +297,7 @@ public function run()
$skipped++;
continue;
}
$metricsToday = end($response);
if(empty($metricsToday)) {
$visitsToday = 0;
} else {
$visitsToday = $metricsToday['nb_visits'];
}
$visitsToday = $this->getVisitsFromApiResponse($response);

$this->requests++;
$processed++;
Expand Down Expand Up @@ -543,7 +538,7 @@ private function archiveVisitsAndSegments($idsite, $period, $lastTimestampWebsit
$url .= $this->getVisitsRequestUrl($idsite, $period, $lastTimestampWebsiteProcessed);
$url .= self::APPEND_TO_API_REQUEST;

$visitsAllDaysInPeriod = false;
$visitsInLastPeriod = 0;
$noSegmentUrl = '';
$success = true;

Expand All @@ -552,7 +547,7 @@ private function archiveVisitsAndSegments($idsite, $period, $lastTimestampWebsit
// already processed above for "day"
if ($period != "day") {
$noSegmentUrl = $url;
$urls [] = $url;
$urls[] = $url;
$this->requests++;
}

Expand All @@ -576,12 +571,13 @@ private function archiveVisitsAndSegments($idsite, $period, $lastTimestampWebsit
if (!is_array($stats)) {
$this->logError("Error unserializing the following response from $url: " . $content);
}
$visitsAllDaysInPeriod = @array_sum($stats);

$visitsInLastPeriod = $this->getVisitsFromApiResponse($stats);
}
}

$this->log("Archived website id = $idsite, period = $period, "
. ($period != "day" ? (int)$visitsAllDaysInPeriod . " visits, " : "")
. ($period != "day" ? (int)$visitsInLastPeriod . " visits, " : "")
. (!empty($timerWebsite) ? $timerWebsite->__toString() : $timer->__toString()));

return $success;
Expand Down Expand Up @@ -1102,5 +1098,16 @@ private function logFatalErrorUrlExpected()
. "\n--help for more information", $backtrace = false);
}

private function getVisitsFromApiResponse($stats)
{
$metricsToday = end($stats);
if (empty($metricsToday)) {
$visitsToday = 0;
} else {
$visitsToday = $metricsToday['nb_visits'];
}
return $visitsToday;
}

}

0 comments on commit 1fd459b

Please sign in to comment.