/** * @param $matchType * @param $actionType * @return string * @throws \Exception */ private static function getSelectQueryWhereNameContains($matchType, $actionType) { // now, we handle the cases =@ (contains) and !@ (does not contain) // build the expression based on the match type $LogAction = Factory::getDAO('log_action'); $sql = $LogAction->sqlIdactionFromSegment($matchType, $actionType); return $sql; }
protected function loadSettings() { $SiteSetting = Factory::getDAO('site_setting'); $settings = $SiteSetting->getByIdsite($this->idSite); $flat = array(); foreach ($settings as $setting) { $flat[$setting['setting_name']] = unserialize($setting['setting_value']); } return $flat; }
/** * Performs a batch insert into a specific table by iterating through the data * * NOTE: you should use tableInsertBatch() which will fallback to this function if LOAD DATA INFILE not available * * @param string $tableName PREFIXED table name! you must call Common::prefixTable() before passing the table name * @param array $fields array of unquoted field names * @param array $values array of data to be inserted * @param bool $ignoreWhenDuplicate Ignore new rows that contain unique key values that duplicate old rows */ public static function tableInsertBatchIterate($tableName, $fields, $values, $ignoreWhenDuplicate = true) { $isArchive = strpos($tableName, 'archive'); if ($isArchive === false) { $Generic = Factory::getGeneric(); $Generic->insertIgnoreBatch($tableName, $fields, $values, $ignoreWhenDuplicate); } else { // archive_blob_* tables need special handling for the "value" column $Archive = Factory::getDAO('archive'); $Archive->insertIgnoreBatch($tableName, $fields, $values, $ignoreWhenDuplicate); } }
public function __construct(ArchiveProcessor\Parameters $params, $isArchiveTemporary) { $this->idArchive = false; $this->idSite = $params->getSite()->getId(); $this->segment = $params->getSegment(); $this->period = $params->getPeriod(); $idSites = array($this->idSite); $this->doneFlag = Rules::getDoneStringFlagFor($idSites, $this->segment, $this->period->getLabel(), $params->getRequestedPlugin()); $this->isArchiveTemporary = $isArchiveTemporary; $this->dateStart = $this->period->getDateStart(); $this->Archive = \Piwik\Db\Factory::getDAO('archive'); }
public function insertRecord($tableName, $fields, $record, $name, $value) { $Generic = Factory::getGeneric(); $Archive = Factory::getDAO('archive'); // duplicate idarchives are Ignored, see https://github.com/piwik/piwik/issues/987 $query = "INSERT INTO " . $tableName . " (" . implode(", ", $fields) . ")\n VALUES (?,?,?,?,?,?,?,?)"; $bindSql = $record; $bindSql[] = $name; if ($Archive->isBlob($tableName)) { $value = $Generic->bin2db($value); $value = $Archive->namespaceToUnderscore($value); $bindSql[] = $value; } else { $bindSql[] = $value; } $Generic->insertIgnore($query, $bindSql); return true; }
/** * Removes a list of actions from the log_action table by ID. * * @param int[] $idActions */ public function delete($idActions) { $LogAction = Factory::getDAO('log_action'); $LogAction->deleteByIdactions($idActions); }
/** * Print profiling report for the tracker * * @param \Piwik\Db $db Tracker database object (or null) */ public static function displayDbTrackerProfile($db = null) { if (is_null($db)) { $db = Tracker::getDatabase(); } $LogProfiling = Factory::getDAO('log_profiling', $db); $all = $LogProfiling->getAll(); if ($all === false) { return; } uasort($all, 'self::maxSumMsFirst'); $infoIndexedByQuery = array(); foreach ($all as $infoQuery) { $query = $infoQuery['query']; $count = $infoQuery['count']; $sum_time_ms = $infoQuery['sum_time_ms']; $infoIndexedByQuery[$query] = array('count' => $count, 'sumTimeMs' => $sum_time_ms); } self::getSqlProfilingQueryBreakdownOutput($infoIndexedByQuery); }
public function getRawSitesWithSomeViewAccess($login) { $Access = Factory::getDAO('access'); return $Access->getAccessSiteByLogin($login); }
private static function getMaxGoalId() { return Factory::getDAO('goal')->getMaxIdgoal(); }
/** * Initialize cache with autoload settings. * * @return void */ protected function autoload() { if ($this->loaded) { return; } $dao = Factory::getDAO('option'); $all = $dao->getAllAutoload(); foreach ($all as $option) { $this->all[$option['option_name']] = $option['option_value']; } $this->loaded = true; }
public function allocateNewArchiveId($numericTable) { $sequence = Factory::getDAO('sequence'); $sequence->setName($numericTable); try { $idarchive = $sequence->getNextId(); } catch (Exception $e) { // edge case: sequence was not found, create it now $sequence->create(); $idarchive = $sequence->getNextId(); } return $idarchive; }
public function getIdsiteByUrlForUser($url, $urlBis, $login) { $Access = Factory::getDAO('access'); $sql = 'SELECT idsite ' . 'FROM ' . $this->table . ' ' . 'WHERE (main_url = ? OR main_url = ?) ' . 'AND idsite IN ( ' . $Access->sqlAccessSiteByLogin(' idsite ') . ' ) ' . 'UNION ' . 'SELECT idsite ' . 'FROM ' . Common::prefixTable('site_url') . ' ' . 'WHERE (url = ? OR url = ?) ' . ' AND idsite IN ( ' . $Access->sqlAccessSiteByLogin(' idsite ') . ' ) '; return $this->db->fetchAll($sql, array($url, $urlBis, $login, $url, $urlBis, $login)); }
private function getIdVisit($idVisit) { $LogVisit = Factory::getDAO('log_visit', Tracker::getDatabase()); return $LogVisit->getByIdvisit($idVisit); }
private function getExistingSequence() { #$sequence = new Sequence('mySequence0815'); $sequence = Factory::getDAO('sequence'); $sequence->setName('notCreatedSequence'); $sequence->create(); return $sequence; }
public function uninstall() { // add column hostname / hostname ext in the visit table $LogVisit = Factory::getDAO('log_visit'); $LogVisit->removeColLocationProvider(); }
/** * Returns the list of reports matching the passed parameters * * @param bool|int $idSite If specified, will filter reports that belong to a specific idsite * @param bool|string $period If specified, will filter reports that are scheduled for this period (day,week,month) * @param bool|int $idReport If specified, will filter the report that has the given idReport * @param bool $ifSuperUserReturnOnlySuperUserReports * @param bool|int $idSegment If specified, will filter the report that has the given idSegment * @throws Exception * @return array */ public function getReports($idSite = false, $period = false, $idReport = false, $ifSuperUserReturnOnlySuperUserReports = false, $idSegment = false) { Piwik::checkUserHasSomeViewAccess(); $cacheKey = (int) $idSite . '.' . (string) $period . '.' . (int) $idReport . '.' . (int) $ifSuperUserReturnOnlySuperUserReports; if (isset(self::$cache[$cacheKey])) { return self::$cache[$cacheKey]; } $sqlWhere = ''; $bind = array(); // Super user gets all reports back, other users only their own if (!Piwik::hasUserSuperUserAccess() || $ifSuperUserReturnOnlySuperUserReports) { $sqlWhere .= "AND login = ?"; $bind[] = Piwik::getCurrentUserLogin(); } if (!empty($period)) { $this->validateReportPeriod($period); } if (!empty($idSite)) { Piwik::checkUserHasViewAccess($idSite); } $dao = Factory::getDAO('report'); $reports = $dao->getAllActive($idSite, $period, $idReport, $idSegment, $ifSuperUserReturnOnlySuperUserReports); // When a specific report was requested and not found, throw an error if ($idReport !== false && empty($reports)) { throw new Exception("Requested report couldn't be found."); } foreach ($reports as &$report) { // decode report parameters $report['parameters'] = json_decode($report['parameters'], true); // decode report list $report['reports'] = json_decode($report['reports'], true); if (!empty($report['parameters']['additionalEmails']) && is_array($report['parameters']['additionalEmails'])) { $report['parameters']['additionalEmails'] = array_values($report['parameters']['additionalEmails']); } } // static cache self::$cache[$cacheKey] = $reports; return $reports; }
/** * Queries and returns archive data using a set of archive IDs. * * @param array $archiveIds The IDs of the archives to get data from. * @param array $recordNames The names of the data to retrieve (ie, nb_visits, nb_actions, etc.). * Note: You CANNOT pass multiple recordnames if $loadAllSubtables=true. * @param string $archiveDataType The archive data type (either, 'blob' or 'numeric'). * @param int|null|string $idSubtable null if the root blob should be loaded, an integer if a subtable should be * loaded and 'all' if all subtables should be loaded. * @throws Exception * @return array */ public static function getArchiveData($archiveIds, $recordNames, $archiveDataType, $idSubtable) { $Archive = Factory::getDAO('archive'); $rows = $Archive->getArchiveData($archiveIds, $recordNames, $archiveDataType, $idSubtable); return $rows; }
/** * get highest idVisit to delete rows from * @return string */ private function getDeleteIdVisitOffset($deleteLogsOlderThan) { $logVisit = Common::prefixTable("log_visit"); $LogVisit = Factory::getDAO('log_visit'); // get max idvisit $maxIdVisit = $LogVisit->getMaxIdvisit(); if (empty($maxIdVisit)) { return false; } // select highest idvisit to delete from $dateStart = Date::factory("today")->subDay($deleteLogsOlderThan); return $LogVisit->getDeleteIdVisitOffset($dateStart->toString('Y-m-d H:i:s'), $maxIdVisit, -self::$selectSegmentSize); }
/** * Returns the list of the website IDs that received some visits between the specified timestamp. * * @param string $fromDateTime * @param string $toDateTime * @return bool true if there are visits for this site between the given timeframe, false if not */ public function hasSiteVisitsBetweenTimeframe($fromDateTime, $toDateTime, $idSite) { $LogVisit = Factory::getDAO('log_visit'); return $LogVisit->hasSiteVisitsBetweenTimeframe($fromDateTime, $toDateTime, $idSite); }