/** * Builds an Archive object or returns the same archive if previously built. * * @param string|int idSite integer, or comma separated list of integer * @param string|Piwik_Date $date 'YYYY-MM-DD' or magic keywords 'today' @see Piwik_Date::factory() * @param string $period 'week' 'day' etc. * @param string Segment definition - defaults to false for Backward Compatibility * * @return Piwik_Archive */ public static function build($idSite, $period, $strDate, $segment = false) { if ($idSite === 'all') { $sites = Piwik_SitesManager_API::getInstance()->getSitesIdWithAtLeastViewAccess(); } else { $sites = Piwik_Site::getIdSitesFromIdSitesString($idSite); } if (!$segment instanceof Piwik_Segment) { $segment = new Piwik_Segment($segment, $idSite); } // idSite=1,3 or idSite=all if (count($sites) > 1 || $idSite === 'all') { $archive = new Piwik_Archive_Array_IndexedBySite($sites, $period, $strDate, $segment); } elseif (is_string($strDate) && self::isMultiplePeriod($strDate, $period)) { $oSite = new Piwik_Site($idSite); $archive = new Piwik_Archive_Array_IndexedByDate($oSite, $period, $strDate, $segment); } else { $oSite = new Piwik_Site($idSite); if ($period == 'range') { $oPeriod = new Piwik_Period_Range('range', $strDate, $oSite->getTimezone(), Piwik_Date::factory('today', $oSite->getTimezone())); } else { if (is_string($strDate)) { if ($strDate == 'now' || $strDate == 'today') { $strDate = date('Y-m-d', Piwik_Date::factory('now', $oSite->getTimezone())->getTimestamp()); } elseif ($strDate == 'yesterday' || $strDate == 'yesterdaySameTime') { $strDate = date('Y-m-d', Piwik_Date::factory('now', $oSite->getTimezone())->subDay(1)->getTimestamp()); } $oDate = Piwik_Date::factory($strDate); } else { $oDate = $strDate; } $date = $oDate->toString(); $oPeriod = Piwik_Period::factory($period, $oDate); } $archive = new Piwik_Archive_Single(); $archive->setPeriod($oPeriod); $archive->setSite($oSite); $archive->setSegment($segment); } return $archive; }
/** * * @see Piwik_ArchiveProcessing_Day::isThereSomeVisits() * @return bool|null */ public function isThereSomeVisits() { if (!is_null($this->isThereSomeVisits)) { return $this->isThereSomeVisits; } $this->loadSubPeriods(); if (self::getPluginBeingProcessed($this->getRequestedReport()) == 'VisitsSummary' || $this->shouldProcessReportsAllPlugins($this->getSegment(), $this->period)) { $toSum = self::getCoreMetrics(); $record = $this->archiveNumericValuesSum($toSum); $this->archiveNumericValuesMax('max_actions'); $nbVisitsConverted = $record['nb_visits_converted']; $nbVisits = $record['nb_visits']; } else { $archive = new Piwik_Archive_Single(); $archive->setSite($this->site); $archive->setPeriod($this->period); $archive->setSegment($this->getSegment()); $nbVisits = $archive->getNumeric('nb_visits'); $nbVisitsConverted = 0; if ($nbVisits > 0) { $nbVisitsConverted = $archive->getNumeric('nb_visits_converted'); } } $this->setNumberOfVisits($nbVisits); $this->setNumberOfVisitsConverted($nbVisitsConverted); $this->isThereSomeVisits = $nbVisits > 0; return $this->isThereSomeVisits; }
/** * Builds an Archive object or returns the same archive if previously built. * * @param string|int idSite integer, or comma separated list of integer * @param string|Piwik_Date $date 'YYYY-MM-DD' or magic keywords 'today' @see Piwik_Date::factory() * @param string $period 'week' 'day' etc. * * @return Piwik_Archive */ static public function build($idSite, $period, $strDate ) { if($idSite === 'all') { $sites = Piwik_SitesManager_API::getSitesIdWithAtLeastViewAccess(); } else { $sites = Piwik_Site::getIdSitesFromIdSitesString($idSite); } // idSite=1,3 or idSite=all if( count($sites) > 1 || $idSite === 'all' ) { $archive = new Piwik_Archive_Array_IndexedBySite($sites, $period, $strDate); } // if a period date string is detected: either 'last30', 'previous10' or 'YYYY-MM-DD,YYYY-MM-DD' elseif(is_string($strDate) && ( preg_match('/^(last|previous){1}([0-9]*)$/', $strDate, $regs) || preg_match('/^([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}),([0-9]{4}-[0-9]{1,2}-[0-9]{1,2})$/', $strDate, $regs) ) ) { $oSite = new Piwik_Site($idSite); $archive = new Piwik_Archive_Array_IndexedByDate($oSite, $period, $strDate); } // case we request a single archive else { if(is_string($strDate)) { $oDate = Piwik_Date::factory($strDate); } else { $oDate = $strDate; } $date = $oDate->toString(); if(isset(self::$alreadyBuilt[$idSite][$date][$period])) { return self::$alreadyBuilt[$idSite][$date][$period]; } $oPeriod = Piwik_Period::factory($period, $oDate); $archive = new Piwik_Archive_Single(); $archive->setPeriod($oPeriod); $archive->setSite(new Piwik_Site($idSite)); $archiveJustProcessed = $archive->prepareArchive(); //we don't cache the archives just processed, the datatable were freed from memory if(!$archiveJustProcessed) { self::$alreadyBuilt[$idSite][$date][$period] = $archive; } } return $archive; }
/** * Builds an Archive object or returns the same archive if previously built. * * @param int $idSite * @param string|Piwik_Date $date 'YYYY-MM-DD' or magic keywords 'today' @see Piwik_Date::factory() * @param string $period 'week' 'day' etc. * * @return Piwik_Archive */ public static function build($idSite, $period, $strDate) { $oSite = new Piwik_Site($idSite); // if a period date string is detected: either 'last30', 'previous10' or 'YYYY-MM-DD,YYYY-MM-DD' if (is_string($strDate) && (ereg('^(last|previous){1}([0-9]*)$', $strDate, $regs) || ereg('^([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}),([0-9]{4}-[0-9]{1,2}-[0-9]{1,2})$', $strDate, $regs))) { require_once 'Archive/Array.php'; $archive = new Piwik_Archive_Array($oSite, $period, $strDate); } else { if (is_string($strDate)) { $oDate = Piwik_Date::factory($strDate); } else { $oDate = $strDate; } $date = $oDate->toString(); if (isset(self::$alreadyBuilt[$idSite][$date][$period])) { return self::$alreadyBuilt[$idSite][$date][$period]; } $oPeriod = Piwik_Period::factory($period, $oDate); $archive = new Piwik_Archive_Single(); $archive->setPeriod($oPeriod); $archive->setSite($oSite); self::$alreadyBuilt[$idSite][$date][$period] = $archive; } return $archive; }
/** * If a segment is specified but a plugin other than 'VisitsSummary' is being requested, * we create an archive for processing VisitsSummary Core Metrics, which will in turn * execute the query above (in isThereSomeVisits) * * @return bool|null */ private function redirectRequestToVisitsSummary() { $archive = new Piwik_Archive_Single(); $archive->setSite($this->site); $archive->setPeriod($this->period); $archive->setSegment($this->getSegment()); $archive->setRequestedReport('VisitsSummary'); $nbVisits = $archive->getNumeric('nb_visits'); $this->isThereSomeVisits = $nbVisits > 0; if ($this->isThereSomeVisits) { $nbVisitsConverted = $archive->getNumeric('nb_visits_converted'); $this->setNumberOfVisits($nbVisits); $this->setNumberOfVisitsConverted($nbVisitsConverted); } return $this->isThereSomeVisits; }
/** * Builds an Archive object or returns the same archive if previously built. * * @param string|int idSite integer, or comma separated list of integer * @param string|Piwik_Date $date 'YYYY-MM-DD' or magic keywords 'today' @see Piwik_Date::factory() * @param string $period 'week' 'day' etc. * * @return Piwik_Archive */ public static function build($idSite, $period, $strDate) { if ($idSite === 'all') { $sites = Piwik_SitesManager_API::getSitesIdWithAtLeastViewAccess(); } else { $sites = Piwik_Site::getIdSitesFromIdSitesString($idSite); } // idSite=1,3 or idSite=all if (count($sites) > 1 || $idSite === 'all') { require_once 'Archive/Array/IndexedBySite.php'; $archive = new Piwik_Archive_Array_IndexedBySite($sites, $period, $strDate); } elseif (is_string($strDate) && (ereg('^(last|previous){1}([0-9]*)$', $strDate, $regs) || ereg('^([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}),([0-9]{4}-[0-9]{1,2}-[0-9]{1,2})$', $strDate, $regs))) { $oSite = new Piwik_Site($idSite); require_once 'Archive/Array/IndexedByDate.php'; $archive = new Piwik_Archive_Array_IndexedByDate($oSite, $period, $strDate); } else { if (is_string($strDate)) { $oDate = Piwik_Date::factory($strDate); } else { $oDate = $strDate; } $date = $oDate->toString(); if (isset(self::$alreadyBuilt[$idSite][$date][$period])) { return self::$alreadyBuilt[$idSite][$date][$period]; } $oPeriod = Piwik_Period::factory($period, $oDate); $archive = new Piwik_Archive_Single(); $archive->setPeriod($oPeriod); $archive->setSite(new Piwik_Site($idSite)); $archiveJustProcessed = $archive->prepareArchive(); //we don't cache the archives just processed, the datatable were freed from memory if (!$archiveJustProcessed) { self::$alreadyBuilt[$idSite][$date][$period] = $archive; } } return $archive; }
/** * Returns the ID of the archived subperiods. * * @return array Array of the idArchive of the subperiods */ protected function loadSubperiodsArchive() { $periods = array(); // we first compute every subperiod of the archive foreach ($this->period->getSubperiods() as $period) { $archivePeriod = new Piwik_Archive_Single(); $archivePeriod->setSite($this->site); $archivePeriod->setPeriod($period); $archivePeriod->prepareArchive(); $periods[] = $archivePeriod; } return $periods; }
/** * Returns true if there are logs for the current archive. * * If the current archive is for a specific plugin (for example, Referers), * (for example when a Segment is defined and the Keywords report is requested) * Then the function will create the Archive for the Core metrics 'VisitsSummary' which will in turn process the number of visits * * If there is no specified segment, the SQL query will always run. */ public function isThereSomeVisits() { if(!is_null($this->isThereSomeVisits)) { if($this->isThereSomeVisits && is_null($this->nb_visits)) { debug_print_backtrace(); exit; } return $this->isThereSomeVisits; } // Handling Custom Segment $segmentSql = $this->getSegment()->getSql(); $sqlSegmentBind = $segmentSql['bind']; $sqlSegment = $segmentSql['sql']; if(!empty($sqlSegment)) $sqlSegment = ' AND '.$sqlSegment; // We check if there is visits for the requested date / site / segment // If no specified Segment // Or if a segment is passed and we specifically process VisitsSummary // Then we check the logs. This is to ensure that this query is ran only once for this day/site/segment (rather than running it for every plugin) if(empty($sqlSegment) || self::getPluginBeingProcessed($this->getRequestedReport()) == 'VisitsSummary') { $query = "SELECT count(distinct idvisitor) as nb_uniq_visitors, count(*) as nb_visits, sum(visit_total_actions) as nb_actions, max(visit_total_actions) as max_actions, sum(visit_total_time) as sum_visit_length, sum(case visit_total_actions when 1 then 1 else 0 end) as bounce_count, sum(case visit_goal_converted when 1 then 1 else 0 end) as nb_visits_converted FROM ".Piwik_Common::prefixTable('log_visit')." AS log_visit WHERE visit_last_action_time >= ? AND visit_last_action_time <= ? AND idsite = ? $sqlSegment ORDER BY NULL"; $bind = array_merge(array($this->getStartDatetimeUTC(), $this->getEndDatetimeUTC(), $this->idsite ) , $sqlSegmentBind); // echo "Querying logs..."; // var_dump($query);var_dump($bind); $row = $this->db->fetchRow($query, $bind ); if($row === false || $row === null || $row['nb_visits'] == 0) { $this->isThereSomeVisits = false; return $this->isThereSomeVisits; } foreach($row as $name => $value) { $this->insertNumericRecord($name, $value); } $this->setNumberOfVisits($row['nb_visits']); $this->setNumberOfVisitsConverted($row['nb_visits_converted']); $this->isThereSomeVisits = true; return $this->isThereSomeVisits; } // If a segment is specified but a plugin other than 'VisitsSummary' is being requested // Then we create an archive for processing VisitsSummary Core Metrics, which will in turn execute the $query above $archive = new Piwik_Archive_Single(); $archive->setSite( $this->site ); $archive->setPeriod( $this->period ); $archive->setSegment( $this->getSegment() ); $archive->setRequestedReport( 'VisitsSummary' ); $nbVisits = $archive->getNumeric('nb_visits'); $isThereSomeVisits = $nbVisits > 0; if($isThereSomeVisits) { $nbVisitsConverted = $archive->getNumeric('nb_visits_converted'); $this->setNumberOfVisits($nbVisits); $this->setNumberOfVisitsConverted($nbVisitsConverted); } $this->isThereSomeVisits = $isThereSomeVisits; return $this->isThereSomeVisits; }
/** * Builds an Archive object or returns the same archive if previously built. * * @param int|string $idSite integer, or comma separated list of integer * @param string $period 'week' 'day' etc. * @param Piwik_Date|string $strDate 'YYYY-MM-DD' or magic keywords 'today' @see Piwik_Date::factory() * @param bool|string $segment Segment definition - defaults to false for Backward Compatibility * @param bool|string $_restrictSitesToLogin Used only when running as a scheduled task * @return Piwik_Archive */ public static function build($idSite, $period, $strDate, $segment = false, $_restrictSitesToLogin = false) { if ($idSite === 'all') { $sites = Piwik_SitesManager_API::getInstance()->getSitesIdWithAtLeastViewAccess($_restrictSitesToLogin); } else { $sites = Piwik_Site::getIdSitesFromIdSitesString($idSite); } if (!$segment instanceof Piwik_Segment) { $segment = new Piwik_Segment($segment, $idSite); } // idSite=1,3 or idSite=all if (count($sites) > 1 || $idSite === 'all') { $archive = new Piwik_Archive_Array_IndexedBySite($sites, $period, $strDate, $segment, $_restrictSitesToLogin); } elseif (is_string($strDate) && self::isMultiplePeriod($strDate, $period)) { $oSite = new Piwik_Site($idSite); $archive = new Piwik_Archive_Array_IndexedByDate($oSite, $period, $strDate, $segment); } else { $oSite = new Piwik_Site($idSite); $oPeriod = Piwik_Archive::makePeriodFromQueryParams($oSite, $period, $strDate); $archive = new Piwik_Archive_Single(); $archive->setPeriod($oPeriod); $archive->setSite($oSite); $archive->setSegment($segment); } return $archive; }