/** * * @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. * @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; }
/** * 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; }
/** * 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 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; }