Example #1
0
 /**
  * today is NOT finished
  * @group Core
  * @group Period
  * @group Period_Day
  */
 public function testDayIsFinishedToday()
 {
     $period = new Piwik_Period_Day(Piwik_Date::today());
     $this->assertEquals(date("Y-m-d"), $period->toString());
     $this->assertEquals(array(), $period->getSubperiods());
     $this->assertEquals(0, $period->getNumberOfSubperiods());
 }
Example #2
0
 public function isFinished()
 {
     $todayMidnight = Piwik_Date::today();
     if ($this->date->isEarlier($todayMidnight)) {
         return true;
     }
 }
Example #3
0
 /**
  * create today object check that timestamp is correct (midnight)
  * 
  * @group Core
  * @group Date
  */
 public function testToday()
 {
     $date = Piwik_Date::today();
     $this->assertEquals(strtotime(date("Y-m-d ") . " 00:00:00"), $date->getTimestamp());
     // test getDatetime()
     $this->assertEquals($date->getDatetime(), $date->getDateStartUTC());
     $date = $date->setTime('12:00:00');
     $this->assertEquals(date('Y-m-d') . ' 12:00:00', $date->getDatetime());
 }
Example #4
0
 /**
  * Inits the object
  */
 protected function loadArchiveProperties()
 {
     $this->idsite = $this->site->getId();
     $this->periodId = $this->period->getId();
     $this->dateStart = $this->period->getDateStart();
     $this->dateEnd = $this->period->getDateEnd();
     $this->tableArchiveNumeric = new Piwik_TablePartitioning_Monthly('archive_numeric');
     $this->tableArchiveNumeric->setIdSite($this->idsite);
     $this->tableArchiveNumeric->setTimestamp($this->dateStart->get());
     $this->tableArchiveBlob = new Piwik_TablePartitioning_Monthly('archive_blob');
     $this->tableArchiveBlob->setIdSite($this->idsite);
     $this->tableArchiveBlob->setTimestamp($this->dateStart->get());
     $this->strDateStart = $this->dateStart->toString();
     $this->strDateEnd = $this->dateEnd->toString();
     // if the current archive is a DAY and if it's today,
     // we set this maxTimestampArchive that defines the lifetime value of today's archive
     $this->maxTimestampArchive = 0;
     if ($this->period->getNumberOfSubperiods() == 0 && $this->period->toString() == date("Y-m-d")) {
         $this->maxTimestampArchive = time() - Zend_Registry::get('config')->General->time_before_today_archive_considered_outdated;
         $browserArchivingEnabled = Zend_Registry::get('config')->General->enable_browser_archiving_triggering;
         // see #1150; if new archives are not triggered from the browser,
         // we still want to try and return the latest archive available for today (rather than return nothing)
         if (!$browserArchivingEnabled) {
             $this->maxTimestampArchive = 0;
         }
     } else {
         if ($this->period->isFinished()) {
             $this->maxTimestampArchive = $this->period->getDateEnd()->setTime('00:00:00')->addDay(1)->getTimestamp();
         } else {
             $this->maxTimestampArchive = Piwik_Date::today()->getTimestamp();
         }
     }
     $db = Zend_Registry::get('db');
     $this->compressBlob = $db->hasBlobDataType();
 }
Example #5
0
 /**
  * Prepares the archive. Gets the idarchive from the ArchiveProcessing.
  *
  * This will possibly launch the archiving process if the archive was not available.
  * @return bool
  */
 public function prepareArchive()
 {
     $archiveJustProcessed = false;
     $periodString = $this->period->getLabel();
     $plugin = Piwik_ArchiveProcessing::getPluginBeingProcessed($this->getRequestedReport());
     $cacheKey = 'all';
     if ($periodString == 'range') {
         $cacheKey = $plugin;
     }
     if (!isset($this->alreadyChecked[$cacheKey])) {
         $this->isThereSomeVisits = false;
         $this->alreadyChecked[$cacheKey] = true;
         $dayString = $this->period->getPrettyString();
         $logMessage = sprintf("%s (%s), plugin %s", $periodString, $dayString, $plugin);
         // if the END of the period is BEFORE the website creation date
         // we already know there are no stats for this period
         // we add one day to make sure we don't miss the day of the website creation
         if ($this->period->getDateEnd()->addDay(2)->isEarlier($this->site->getCreationDate())) {
             Piwik::log(sprintf("Archive %s skipped, archive is before the website was created.", $logMessage));
             return;
         }
         // if the starting date is in the future we know there is no visit
         if ($this->period->getDateStart()->subDay(2)->isLater(Piwik_Date::today())) {
             Piwik::log(sprintf("Archive %s skipped, archive is after today.", $logMessage));
             return;
         }
         // we make sure the archive is available for the given date
         $periodLabel = $this->period->getLabel();
         $this->archiveProcessing = Piwik_ArchiveProcessing::factory($periodLabel);
         $this->archiveProcessing->setSite($this->site);
         $this->archiveProcessing->setPeriod($this->period);
         $this->archiveProcessing->setSegment($this->segment);
         $this->archiveProcessing->init();
         $this->archiveProcessing->setRequestedReport($this->getRequestedReport());
         $archivingDisabledArchiveNotProcessed = false;
         $idArchive = $this->archiveProcessing->loadArchive();
         if (empty($idArchive)) {
             if ($this->archiveProcessing->isArchivingDisabled()) {
                 $archivingDisabledArchiveNotProcessed = true;
                 $logMessage = sprintf("Archiving disabled, for %s", $logMessage);
             } else {
                 Piwik::log(sprintf("Processing %s, not archived yet...", $logMessage));
                 $archiveJustProcessed = true;
                 // Process the reports
                 $this->archiveProcessing->launchArchiving();
                 $idArchive = $this->archiveProcessing->getIdArchive();
                 $logMessage = sprintf("Processed %d, for %s", $idArchive, $logMessage);
             }
         } else {
             $logMessage = sprintf("Already processed, fetching idArchive = %d (idSite=%d), for %s", $idArchive, $this->site->getId(), $logMessage);
         }
         Piwik::log(sprintf("%s, Visits = %d", $logMessage, $this->archiveProcessing->getNumberOfVisits()));
         $this->isThereSomeVisits = !$archivingDisabledArchiveNotProcessed && $this->archiveProcessing->isThereSomeVisits();
         $this->idArchive = $idArchive;
     }
     return $archiveJustProcessed;
 }
 /**
  * Prepares the archive. Gets the idarchive from the ArchiveProcessing.
  * 
  * This will possibly launch the archiving process if the archive was not available.
  */
 public function prepareArchive()
 {
     $archiveJustProcessed = false;
     $periodString = $this->period->getLabel();
     $plugin = Piwik_ArchiveProcessing::getPluginBeingProcessed($this->getRequestedReport());
     $cacheKey = 'all';
     if ($periodString == 'range') {
         $cacheKey = $plugin;
     }
     if (!isset($this->alreadyChecked[$cacheKey])) {
         $this->isThereSomeVisits = false;
         $this->alreadyChecked[$cacheKey] = true;
         $dayString = $this->period->getPrettyString();
         $logMessage = "Preparing archive: " . $periodString . "(" . $dayString . "), plugin {$plugin} ";
         // if the END of the period is BEFORE the website creation date
         // we already know there are no stats for this period
         // we add one day to make sure we don't miss the day of the website creation
         if ($this->period->getDateEnd()->addDay(2)->isEarlier($this->site->getCreationDate())) {
             Piwik::log("{$logMessage} skipped, archive is before the website was created.");
             return;
         }
         // if the starting date is in the future we know there is no visit
         if ($this->period->getDateStart()->subDay(2)->isLater(Piwik_Date::today())) {
             Piwik::log("{$logMessage} skipped, archive is after today.");
             return;
         }
         // we make sure the archive is available for the given date
         $periodLabel = $this->period->getLabel();
         $this->archiveProcessing = Piwik_ArchiveProcessing::factory($periodLabel);
         $this->archiveProcessing->setSite($this->site);
         $this->archiveProcessing->setPeriod($this->period);
         $this->archiveProcessing->setSegment($this->segment);
         $this->archiveProcessing->init();
         $this->archiveProcessing->setRequestedReport($this->getRequestedReport());
         $archivingDisabledArchiveNotProcessed = false;
         $idArchive = $this->archiveProcessing->loadArchive();
         if (empty($idArchive)) {
             if ($this->archiveProcessing->isArchivingDisabled()) {
                 $archivingDisabledArchiveNotProcessed = true;
                 $logMessage = "* ARCHIVING DISABLED, for {$logMessage}";
             } else {
                 Piwik::log("* PROCESSING {$logMessage}, not archived yet...");
                 $archiveJustProcessed = true;
                 // Process the reports
                 $this->archiveProcessing->launchArchiving();
                 $idArchive = $this->archiveProcessing->getIdArchive();
                 $logMessage = "PROCESSED: idArchive = " . $idArchive . ", for {$logMessage}";
             }
         } else {
             $logMessage = "* ALREADY PROCESSED, Fetching idArchive = {$idArchive} (idSite=" . $this->site->getId() . "), for {$logMessage}";
         }
         Piwik::log("{$logMessage}, Visits = " . $this->archiveProcessing->getNumberOfVisits());
         $this->isThereSomeVisits = !$archivingDisabledArchiveNotProcessed && $this->archiveProcessing->isThereSomeVisits();
         $this->idArchive = $idArchive;
     }
     return $archiveJustProcessed;
 }
 /**
  * Inits the object
  * 
  * @return void
  */
 protected function loadArchiveProperties()
 {
     $this->idsite = $this->site->getId();
     $this->periodId = $this->period->getId();
     $this->dateStart = $this->period->getDateStart();
     $this->dateEnd = $this->period->getDateEnd();
     $this->tableArchiveNumeric = new Piwik_TablePartitioning_Monthly('archive_numeric');
     $this->tableArchiveNumeric->setIdSite($this->idsite);
     $this->tableArchiveNumeric->setTimestamp($this->dateStart->get());
     $this->tableArchiveBlob = new Piwik_TablePartitioning_Monthly('archive_blob');
     $this->tableArchiveBlob->setIdSite($this->idsite);
     $this->tableArchiveBlob->setTimestamp($this->dateStart->get());
     $this->strDateStart = $this->dateStart->toString();
     $this->strDateEnd = $this->dateEnd->toString();
     // if the current archive is a DAY and if it's today,
     // we set this maxTimestampArchive that defines the lifetime value of today's archive
     $this->maxTimestampArchive = 0;
     if ($this->period->getNumberOfSubperiods() == 0 && $this->period->toString() == date("Y-m-d")) {
         $this->maxTimestampArchive = time() - Zend_Registry::get('config')->General->time_before_today_archive_considered_outdated;
     } else {
         if ($this->period->isFinished()) {
             $this->maxTimestampArchive = $this->period->getDateEnd()->setTime('00:00:00')->addDay(1)->getTimestamp();
         } else {
             $this->maxTimestampArchive = Piwik_Date::today()->getTimestamp();
         }
     }
 }
Example #8
0
 protected function generate()
 {
     if ($this->subperiodsProcessed) {
         return;
     }
     parent::generate();
     if (preg_match('/(last|previous)([0-9]*)/', $this->strDate, $regs)) {
         $lastN = $regs[2];
         $lastOrPrevious = $regs[1];
         if (!is_null($this->defaultEndDate)) {
             $defaultEndDate = $this->defaultEndDate;
         } else {
             $defaultEndDate = Piwik_Date::today();
         }
         if ($lastOrPrevious == 'last') {
             $endDate = $defaultEndDate;
         } elseif ($lastOrPrevious == 'previous') {
             $endDate = $this->removePeriod($defaultEndDate, 1);
         }
         // last1 means only one result ; last2 means 2 results so we remove only 1 to the days/weeks/etc
         $lastN--;
         $lastN = abs($lastN);
         $lastN = $this->getMaxN($lastN);
         $startDate = $this->removePeriod($endDate, $lastN);
     } elseif (preg_match('/([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}),([0-9]{4}-[0-9]{1,2}-[0-9]{1,2})/', $this->strDate, $regs)) {
         $strDateStart = $regs[1];
         $strDateEnd = $regs[2];
         $startDate = Piwik_Date::factory($strDateStart);
         $endDate = Piwik_Date::factory($strDateEnd);
     } else {
         throw new Exception("The date '{$this->strDate}' is not a date range. Should have the following format: 'lastN' or 'previousN' or 'YYYY-MM-DD,YYYY-MM-DD'.");
     }
     $endSubperiod = Piwik_Period::factory($this->strPeriod, $endDate);
     $arrayPeriods = array();
     $arrayPeriods[] = $endSubperiod;
     while ($endDate->isLater($startDate)) {
         $endDate = $this->removePeriod($endDate, 1);
         $subPeriod = Piwik_Period::factory($this->strPeriod, $endDate);
         $arrayPeriods[] = $subPeriod;
     }
     $arrayPeriods = array_reverse($arrayPeriods);
     foreach ($arrayPeriods as $period) {
         $this->addSubperiod($period);
     }
 }
Example #9
0
 /**
  * @group Core
  * @group Period
  * @group Period_Range
  */
 public function testRangeYearLast1()
 {
     $range = new Piwik_Period_Range('year', 'last1');
     $currentYear = new Piwik_Period_Year(Piwik_Date::today());
     $this->assertEquals(1, $range->getNumberOfSubperiods());
     $this->assertEquals(array($currentYear->toString()), $range->toString());
 }
Example #10
0
 /**
  * Prepares the archive. Gets the idarchive from the ArchiveProcessing.
  * 
  * This will possibly launch the archiving process if the archive was not available.
  * 
  * @return void
  */
 public function prepareArchive()
 {
     $archiveJustProcessed = false;
     if (!$this->alreadyChecked) {
         $this->isThereSomeVisits = false;
         $this->alreadyChecked = true;
         // if the END of the period is BEFORE the website creation date
         // we already know there are no stats for this period
         // we add one day to make sure we don't miss the day of the website creation
         if ($this->period->getDateEnd()->addDay(2)->isEarlier($this->site->getCreationDate())) {
             return;
         }
         // if the starting date is in the future we know there is no visit
         if ($this->period->getDateStart()->subDay(1)->isLater(Piwik_Date::today())) {
             return;
         }
         // we make sure the archive is available for the given date
         $periodLabel = $this->period->getLabel();
         $archiveProcessing = Piwik_ArchiveProcessing::factory($periodLabel);
         $archiveProcessing->setSite($this->site);
         $archiveProcessing->setPeriod($this->period);
         $idArchive = $archiveProcessing->loadArchive();
         if ($idArchive === null) {
             $archiveJustProcessed = true;
             $archiveProcessing->launchArchiving();
             $idArchive = $archiveProcessing->getIdArchive();
         }
         $this->isThereSomeVisits = $archiveProcessing->isThereSomeVisits;
         $this->idArchive = $idArchive;
         $this->archiveProcessing = $archiveProcessing;
     }
     return $archiveJustProcessed;
 }
	/**
	 * Inits the object
	 */
	protected function loadArchiveProperties()
	{		
		$this->idsite = $this->site->getId();
		
		$this->periodId = $this->period->getId();
		
		$this->dateStart = $this->period->getDateStart();
		$this->dateEnd = $this->period->getDateEnd();
		
		$this->tableArchiveNumeric = new Piwik_TablePartitioning_Monthly('archive_numeric');
		$this->tableArchiveNumeric->setIdSite($this->idsite);
		$this->tableArchiveNumeric->setTimestamp($this->dateStart->get());
		$this->tableArchiveBlob = new Piwik_TablePartitioning_Monthly('archive_blob');
		$this->tableArchiveBlob->setIdSite($this->idsite);	
		$this->tableArchiveBlob->setTimestamp($this->dateStart->get());

		$this->strDateStart = $this->dateStart->toString();
		$this->strDateEnd = $this->dateEnd->toString();
		
		// if the current archive is a DAY and if it's today,
		// we set this maxTimestampArchive that defines the lifetime value of today's archive
		$this->maxTimestampArchive = 0;
		if( $this->period->getNumberOfSubperiods() == 0
			&& $this->period->toString() == date("Y-m-d")
			)
		{
			$this->maxTimestampArchive = time() - Zend_Registry::get('config')->General->time_before_today_archive_considered_outdated;
		}
		// either
		// - if the period we're looking for is finished, we look for a ts_archived that 
		//   is greater than the last day of the archive 
		// - if the period we're looking for is not finished, we look for a recent enough archive
		//   recent enough means maxTimestampArchive = 00:00:01 this morning
		else
		{
			if($this->period->isFinished())
			{
				$this->maxTimestampArchive = $this->period->getDateEnd()->setTime('00:00:00')->addDay(1)->getTimestamp();
			}
			else
			{
				$this->maxTimestampArchive = Piwik_Date::today()->getTimestamp();
			}
		}

		$db = Zend_Registry::get('db');
		$this->compressBlob = $db->hasBlobDataType();
	}
Example #12
0
 function test_range_year_last1()
 {
     $range = new Piwik_Period_Range('year', 'last1');
     $currentYear = new Piwik_Period_Year(Piwik_Date::today());
     $this->assertEqual($range->getNumberOfSubperiods(), 1);
     $this->assertEqual($range->toString(), array($currentYear->toString()));
 }
Example #13
0
 /**
  * @group Core
  * @group Period
  */
 public function testFactoryInvalid()
 {
     try {
         $period = Piwik_Period::factory('inValid', Piwik_Date::today());
     } catch (Exception $e) {
         return;
     }
     $this->fail('Expected Exception not raised');
 }
Example #14
0
 function test_today()
 {
     $date = Piwik_Date::today();
     $this->assertEqual(strtotime(date("Y-m-d ") . " 00:00:00"), $date->get());
 }