protected static function getTable(Date $date, $type) { $tableNamePrefix = "archive_" . $type; $tableName = $tableNamePrefix . "_" . $date->toString('Y_m'); $tableName = Common::prefixTable($tableName); self::createArchiveTablesIfAbsent($tableName, $tableNamePrefix); return $tableName; }
private function setDateMonthAndYear($dateString, Date $archiveDate) { return $archiveDate->toString('Y-m') . '-' . Date::factory($dateString)->toString('d'); }
/** * Sets the last date available in the period selector's calendar. Usually this is just the "today" date * for a site (which varies based on the timezone of a site). * * @param Date $maxDate The max date. * @param View $view The view that contains the period selector. * @api */ protected function setMaxDateView(Date $maxDate, $view) { $view->maxDateYear = $maxDate->toString('Y'); $view->maxDateMonth = $maxDate->toString('m'); $view->maxDateDay = $maxDate->toString('d'); }
/** * Given a monthly archive table, will delete all reports that are now outdated, * or reports that ended with an error * * @param \Piwik\Date $date * @return int|bool False, or timestamp indicating which archives to delete */ public static function shouldPurgeOutdatedArchives(Date $date) { if (self::$purgeOutdatedArchivesIsDisabled) { return false; } $key = self::FLAG_TABLE_PURGED . "blob_" . $date->toString('Y_m'); $timestamp = Option::get($key); // we shall purge temporary archives after their timeout is finished, plus an extra 6 hours // in case archiving is disabled or run once a day, we give it this extra time to run // and re-process more recent records... $temporaryArchivingTimeout = self::getTodayArchiveTimeToLive(); $hoursBetweenPurge = 6; $purgeEveryNSeconds = max($temporaryArchivingTimeout, $hoursBetweenPurge * 3600); // we only delete archives if we are able to process them, otherwise, the browser might process reports // when &segment= is specified (or custom date range) and would below, delete temporary archives that the // browser is not able to process until next cron run (which could be more than 1 hour away) if (self::isRequestAuthorizedToArchive() && (!$timestamp || $timestamp < time() - $purgeEveryNSeconds)) { Option::set($key, time()); if (self::isBrowserTriggerEnabled()) { // If Browser Archiving is enabled, it is likely there are many more temporary archives // We delete more often which is safe, since reports are re-processed on demand $purgeArchivesOlderThan = Date::factory(time() - 2 * $temporaryArchivingTimeout)->getDateTime(); } else { // If cron core:archive command is building the reports, we should keep all temporary reports from today $purgeArchivesOlderThan = Date::factory('today')->getDateTime(); } return $purgeArchivesOlderThan; } Log::info("Purging temporary archives: skipped."); return false; }
/** * The constructor * Initialize some local variables from the request * @param int $idSite * @param Date $date ($this->date from controller) * @param null|string $graphType * @throws Exception */ public function __construct($idSite, $date, $graphType = 'graphEvolution') { $this->apiMethod = Common::getRequestVar('apiMethod', '', 'string'); if (empty($this->apiMethod)) { throw new Exception("Parameter apiMethod not set."); } $this->label = DataTablePostProcessor::getLabelFromRequest($_GET); if (!is_array($this->label)) { throw new Exception("Expected label to be an array, got instead: " . $this->label); } $this->label = $this->label[0]; if ($this->label === '') { throw new Exception("Parameter label not set."); } $this->period = Common::getRequestVar('period', '', 'string'); PeriodFactory::checkPeriodIsEnabled($this->period); $this->idSite = $idSite; $this->graphType = $graphType; if ($this->period != 'range') { // handle day, week, month and year: display last X periods $end = $date->toString(); list($this->date, $lastN) = EvolutionViz::getDateRangeAndLastN($this->period, $end); } $this->segment = \Piwik\API\Request::getRawSegmentFromRequest(); $this->loadEvolutionReport(); }
/** * @internal */ public function forgetRememberedArchivedReportsToInvalidate($idSite, Date $date) { $id = $this->buildRememberArchivedReportId($idSite, $date->toString()); Option::delete($id); }
/** * Returns true if a report with the given year & month should be purged or not. * * @param int $reportDateYear The year of the report in question. * @param int $reportDateMonth The month of the report in question. * @param Date $toRemoveDate The date a report must be older than in order to be purged. * @return bool */ public static function shouldReportBePurged($reportDateYear, $reportDateMonth, $toRemoveDate) { $toRemoveYear = (int) $toRemoveDate->toString('Y'); $toRemoveMonth = (int) $toRemoveDate->toString('m'); return $reportDateYear < $toRemoveYear || $reportDateYear == $toRemoveYear && $reportDateMonth <= $toRemoveMonth; }
private function getAllOverlappingChildPeriodsInRange(Date $dateStart, Date $dateEnd) { $result = array(); $childPeriodType = $this->getImmediateChildPeriodLabel(); if (empty($childPeriodType)) { return $result; } $childPeriods = Factory::build($childPeriodType, $dateStart->toString() . ',' . $dateEnd->toString()); return array_merge($childPeriods->getSubperiods(), $childPeriods->getAllOverlappingChildPeriodsInRange($dateStart, $dateEnd)); }
public static function getTableMonthFromDate(Date $date) { return $date->toString('Y_m'); }
/** * The constructor * Initialize some local variables from the request * @param int $idSite * @param Date $date ($this->date from controller) * @param null|string $graphType * @throws Exception */ public function __construct($idSite, $date, $graphType = null) { $this->apiMethod = Common::getRequestVar('apiMethod', '', 'string'); if (empty($this->apiMethod)) { throw new Exception("Parameter apiMethod not set."); } $this->label = ResponseBuilder::getLabelFromRequest($_GET); $this->label = $this->label[0]; if ($this->label === '') { throw new Exception("Parameter label not set."); } $this->period = Common::getRequestVar('period', '', 'string'); if (empty($this->period)) { throw new Exception("Parameter period not set."); } $this->idSite = $idSite; $this->graphType = $graphType; if ($this->period != 'range') { // handle day, week, month and year: display last X periods $end = $date->toString(); list($this->date, $lastN) = EvolutionViz::getDateRangeAndLastN($this->period, $end); } $this->segment = \Piwik\API\Request::getRawSegmentFromRequest(); $this->loadEvolutionReport(); }
public function removeDate(Date $date) { $yearMonth = $date->toString('Y_m'); $this->remove($yearMonth); }