Ejemplo n.º 1
0
 /**
  * @dataProvider getVisitsInTimeFrameData
  */
 public function test_hasSiteVisitsInTimeframe_shouldDetectWhetherThereAreVisitsInCertainTimeframe($from, $to, $idSite, $expectedHasVisits)
 {
     Fixture::getTracker($this->idSite, '2015-01-25 05:35:27')->doTrackPageView('/test');
     $hasVisits = $this->dao->hasSiteVisitsBetweenTimeframe($from, $to, $idSite);
     $this->assertSame($expectedHasVisits, $hasVisits);
 }
Ejemplo n.º 2
0
 /**
  * Detects whether a site had visits since midnight in the websites timezone
  *
  * @return bool
  */
 private function hadWebsiteTrafficSinceMidnightInTimezone($idSite)
 {
     $timezone = Site::getTimezoneFor($idSite);
     $nowInTimezone = Date::factory('now', $timezone);
     $midnightInTimezone = $nowInTimezone->setTime('00:00:00');
     $secondsSinceMidnight = $nowInTimezone->getTimestamp() - $midnightInTimezone->getTimestamp();
     $secondsSinceLastArchive = $this->getSecondsSinceLastArchive();
     if ($secondsSinceLastArchive < $secondsSinceMidnight) {
         $secondsSinceMidnight = $secondsSinceLastArchive;
     }
     $from = Date::now()->subSeconds($secondsSinceMidnight)->getDatetime();
     $to = Date::now()->addHour(1)->getDatetime();
     $dao = new RawLogDao();
     $hasVisits = $dao->hasSiteVisitsBetweenTimeframe($from, $to, $idSite);
     if ($hasVisits) {
         $this->logger->info("{$idSite} has visits between {$from} and {$to}");
     } else {
         $this->logger->info("{$idSite} has no visits between {$from} and {$to}");
     }
     return $hasVisits;
 }
Ejemplo n.º 3
0
 /**
  * Detects whether a site had visits since midnight in the websites timezone
  *
  * @param $idSite
  * @return bool
  */
 private function hadWebsiteTrafficSinceMidnightInTimezone($idSite)
 {
     $timezone = Site::getTimezoneFor($idSite);
     $nowInTimezone = Date::factory('now', $timezone);
     $midnightInTimezone = $nowInTimezone->setTime('00:00:00');
     $secondsSinceMidnight = $nowInTimezone->getTimestamp() - $midnightInTimezone->getTimestamp();
     $secondsSinceLastArchive = $this->getSecondsSinceLastArchive();
     if ($secondsSinceLastArchive < $secondsSinceMidnight) {
         $secondsBackToLookForVisits = $secondsSinceLastArchive;
         $sinceInfo = "(since the last successful archiving)";
     } else {
         $secondsBackToLookForVisits = $secondsSinceMidnight;
         $sinceInfo = "(since midnight)";
     }
     $from = Date::now()->subSeconds($secondsBackToLookForVisits)->getDatetime();
     $to = Date::now()->addHour(1)->getDatetime();
     $dao = new RawLogDao();
     $hasVisits = $dao->hasSiteVisitsBetweenTimeframe($from, $to, $idSite);
     if ($hasVisits) {
         $this->logger->info("- tracking data found for website id {$idSite} since {$from} UTC {$sinceInfo}");
     } else {
         $this->logger->info("- no new tracking data for website id {$idSite} since {$from} UTC {$sinceInfo}");
     }
     return $hasVisits;
 }