Beispiel #1
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;
 }
Beispiel #2
0
 public function getDateStart()
 {
     $dateStart = parent::getDateStart();
     if (empty($dateStart)) {
         throw new Exception("Specified date range is invalid.");
     }
     return $dateStart;
 }
Beispiel #3
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
  */
 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();
 }
 /**
  * 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();
         }
     }
 }
Beispiel #7
0
 /**
  * Generate advisory lock name
  *
  * @param int $idsite
  * @param Piwik_Period $period
  * @return string
  */
 public static function getArchiveProcessingLockName($idsite, $period, Piwik_Segment $segment)
 {
     $config = Zend_Registry::get('config');
     $lockName = 'piwik.' . $config->database->dbname . '.' . $config->database->tables_prefix . '/' . $idsite . '/' . (!$segment->isEmpty() ? $segment->getHash() . '/' : '') . $period->getId() . '/' . $period->getDateStart()->toString('Y-m-d') . ',' . $period->getDateEnd()->toString('Y-m-d');
     return $lockName . '/' . md5($lockName . $config->superuser->salt);
 }
 /**
  * Returns the idArchive if the archive is available in the database.
  * Returns false if the archive needs to be computed.
  * 
  * An archive is available if
  * - for today, the archive was computed less than minDatetimeArchiveProcessedUTC seconds ago
  * - for any other day, if the archive was computed once this day was finished
  * - for other periods, if the archive was computed once the period was finished
  *
  * @return int|false
  */
 protected function isArchived()
 {
     $bindSQL = array($this->idsite, $this->period->getDateStart()->toString('Y-m-d'), $this->period->getDateEnd()->toString('Y-m-d'), $this->periodId);
     $timeStampWhere = '';
     if ($this->minDatetimeArchiveProcessedUTC) {
         $timeStampWhere = " AND ts_archived >= ? ";
         $bindSQL[] = Piwik_Date::factory($this->minDatetimeArchiveProcessedUTC)->getDatetime();
     }
     // When a Segment is specified, we try and only process the requested report in the archive
     // As a limitation, we don't know all the time which plugin should process which report
     // There is a catch all flag 'all' appended to archives containing all reports already
     // We look for this 'done.ABCDEFG.all', or for an archive that contains only our plugin data 'done.ABDCDEFG.Referers'
     $done = $this->getDoneStringFlag();
     $doneAllPluginsProcessed = $this->getDoneStringFlag($flagArchiveAsAllPlugins = true);
     $sqlSegmentsFindArchiveAllPlugins = '';
     if ($done != $doneAllPluginsProcessed) {
         $sqlSegmentsFindArchiveAllPlugins = "OR (name = '" . $doneAllPluginsProcessed . "' AND value = " . Piwik_ArchiveProcessing::DONE_OK . ")\n\t\t\t\t\tOR (name = '" . $doneAllPluginsProcessed . "' AND value = " . Piwik_ArchiveProcessing::DONE_OK_TEMPORARY . ")";
     }
     $sqlQuery = "\tSELECT idarchive, value, name, date1 as startDate\n\t\t\t\t\t\tFROM " . $this->tableArchiveNumeric->getTableName() . "\n\t\t\t\t\t\tWHERE idsite = ?\n\t\t\t\t\t\t\tAND date1 = ?\n\t\t\t\t\t\t\tAND date2 = ?\n\t\t\t\t\t\t\tAND period = ?\n\t\t\t\t\t\t\tAND ( (name = '" . $done . "' AND value = " . Piwik_ArchiveProcessing::DONE_OK . ")\n\t\t\t\t\t\t\t\t\tOR (name = '" . $done . "' AND value = " . Piwik_ArchiveProcessing::DONE_OK_TEMPORARY . ")\n\t\t\t\t\t\t\t\t\t{$sqlSegmentsFindArchiveAllPlugins}\n\t\t\t\t\t\t\t\t\tOR name = 'nb_visits')\n\t\t\t\t\t\t\t{$timeStampWhere}\n\t\t\t\t\t\tORDER BY ts_archived DESC";
     $results = Piwik_FetchAll($sqlQuery, $bindSQL);
     if (empty($results)) {
         return false;
     }
     $idarchive = false;
     // we look for the more recent idarchive
     foreach ($results as $result) {
         if ($result['name'] == $done || $result['name'] == $doneAllPluginsProcessed) {
             $idarchive = $result['idarchive'];
             $this->timestampDateStart = Piwik_Date::factory($result['startDate'])->getTimestamp();
             break;
         }
     }
     // case when we have a nb_visits entry in the archive, but the process is not finished yet or failed to finish
     // therefore we don't have the done=OK
     if ($idarchive === false) {
         return false;
     }
     if ($this->getPluginBeingProcessed($this->getRequestedReport()) == 'VisitsSummary') {
         $this->isThereSomeVisits = false;
     }
     // we look for the nb_visits result for this most recent archive
     foreach ($results as $result) {
         if ($result['name'] == 'nb_visits' && $result['idarchive'] == $idarchive) {
             $this->isThereSomeVisits = $result['value'] > 0;
             $this->setNumberOfVisits($result['value']);
             break;
         }
     }
     return $idarchive;
 }
	/**
	 * 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();
	}
Beispiel #10
0
 /**
  * Generate advisory lock name
  *
  * @param int            $idsite
  * @param Piwik_Period   $period
  * @param Piwik_Segment  $segment
  * @return string
  */
 protected function getProcessingLockName($idsite, $period, $segment)
 {
     $config = Config::getInstance();
     $lockName = 'piwik.' . $config->database['dbname'] . '.' . $config->database['tables_prefix'] . '/' . $idsite . '/' . (!$segment->isEmpty() ? $segment->getHash() . '/' : '') . $period->getId() . '/' . $period->getDateStart()->toString('Y-m-d') . ',' . $period->getDateEnd()->toString('Y-m-d');
     $return = $lockName . '/' . md5($lockName . SettingsPiwik::getSalt());
     return $return;
 }
 /**
  * Generate advisory lock name
  *
  * @param int $idsite
  * @param Piwik_Period $period
  * @return string
  */
 public static function getArchiveProcessingLockName($idsite, $period, Piwik_Segment $segment)
 {
     $config = Piwik_Config::getInstance();
     $lockName = 'piwik.' . $config->database['dbname'] . '.' . $config->database['tables_prefix'] . '/' . $idsite . '/' . (!$segment->isEmpty() ? $segment->getHash() . '/' : '') . $period->getId() . '/' . $period->getDateStart()->toString('Y-m-d') . ',' . $period->getDateEnd()->toString('Y-m-d');
     return $lockName . '/' . md5($lockName . $config->superuser['salt']);
 }