public static function getArchiveIdAndVisits(Site $site, Period $period, Segment $segment, $minDatetimeArchiveProcessedUTC, $requestedPlugin)
 {
     $dateStart = $period->getDateStart();
     $bindSQL = array($site->getId(), $dateStart->toString('Y-m-d'), $period->getDateEnd()->toString('Y-m-d'), $period->getId());
     $timeStampWhere = '';
     if ($minDatetimeArchiveProcessedUTC) {
         $timeStampWhere = " AND ts_archived >= ? ";
         $bindSQL[] = Date::factory($minDatetimeArchiveProcessedUTC)->getDatetime();
     }
     $pluginOrVisitsSummary = array("VisitsSummary", $requestedPlugin);
     $pluginOrVisitsSummary = array_unique($pluginOrVisitsSummary);
     $sqlWhereArchiveName = self::getNameCondition($pluginOrVisitsSummary, $segment);
     $sqlQuery = "\tSELECT idarchive, value, name, date1 as startDate\n\t\t\t\t\t\tFROM " . ArchiveTableCreator::getNumericTable($dateStart) . "``\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 ( ({$sqlWhereArchiveName})\n\t\t\t\t\t\t\t\t  OR name = '" . self::NB_VISITS_RECORD_LOOKED_UP . "'\n\t\t\t\t\t\t\t\t  OR name = '" . self::NB_VISITS_CONVERTED_RECORD_LOOKED_UP . "')\n\t\t\t\t\t\t\t{$timeStampWhere}\n\t\t\t\t\t\tORDER BY idarchive DESC";
     $results = Db::fetchAll($sqlQuery, $bindSQL);
     if (empty($results)) {
         return false;
     }
     $idArchive = self::getMostRecentIdArchiveFromResults($segment, $requestedPlugin, $results);
     $idArchiveVisitsSummary = self::getMostRecentIdArchiveFromResults($segment, "VisitsSummary", $results);
     list($visits, $visitsConverted) = self::getVisitsMetricsFromResults($idArchive, $idArchiveVisitsSummary, $results);
     if ($visits === false && $idArchive === false) {
         return false;
     }
     return array($idArchive, $visits, $visitsConverted);
 }
Пример #2
0
 protected static function makeLockName($idsite, Period $period, Segment $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());
 }
Пример #3
0
 public function getArchiveIdAndVisits($table, \Piwik\Site $site, \Piwik\Period $period, $minDatetime, $sqlWhereArchiveName)
 {
     $bind = array($site->getId(), $period->getDateStart()->toString('Y-m-d'), $period->getDateEnd()->toString('Y-m-d'), $period->getId());
     if ($minDatetime) {
         $timestampWhere = ' AND ts_archived >= ?';
         $bind[] = Date::factory($minDatetime)->getDatetime();
     } else {
         $timestampWhere = '';
     }
     $startDate = $this->db->quoteIdentifier('startDate');
     $sql = "SELECT idarchive, value, name, date1 AS {$startDate}\n                FROM {$table}\n                WHERE idsite = ?\n                  AND date1 = ?\n                  AND date2 = ?\n                  AND period = ?\n                  AND ( ({$sqlWhereArchiveName})\n                        OR name = '" . ArchiveSelector::NB_VISITS_RECORD_LOOKED_UP . "'\n                        OR name = '" . ArchiveSelector::NB_VISITS_CONVERTED_RECORD_LOOKED_UP . "'\n                     )\n                  {$timestampWhere}\n                ORDER BY idarchive DESC";
     return $this->db->fetchAll($sql, $bind);
 }