Example #1
0
 public function getReportByUniqueId($idSite, $reportUniqueId)
 {
     $processedReport = new ProcessedReport();
     $report = $processedReport->getReportMetadataByUniqueId($idSite, $reportUniqueId);
     return $report;
 }
Example #2
0
 public static function getPrettyValue($idSite, $columnName, $value, $isHtml)
 {
     return ProcessedReport::getPrettyValue(self::getFormatter($isHtml), $idSite, $columnName, $value);
 }
Example #3
0
 public function getProcessedReport($idSite, $period, $date, $apiModule, $apiAction, $segment = false, $apiParameters = false, $idGoal = false, $language = false, $showTimer = true, $hideMetricsDoc = false, $idSubtable = false, $showRawMetrics = false, $format_metrics = null, $idDimension = false)
 {
     Piwik::checkUserHasViewAccess($idSite);
     $reporter = new ProcessedReport();
     $processed = $reporter->getProcessedReport($idSite, $period, $date, $apiModule, $apiAction, $segment, $apiParameters, $idGoal, $language, $showTimer, $hideMetricsDoc, $idSubtable, $showRawMetrics, $format_metrics, $idDimension);
     return $processed;
 }
 protected function enrichTriggeredAlerts($triggeredAlerts)
 {
     $processedReport = new ProcessedReport();
     $cached = array();
     foreach ($triggeredAlerts as &$alert) {
         $idSite = $alert['idsite'];
         $metric = $alert['metric'];
         $report = $alert['report'];
         if (!array_key_exists($idSite, $cached)) {
             $cached[$idSite] = array('report' => array(), 'metric' => array(), 'siteName' => '', 'siteTimezone' => null);
         }
         if (empty($cached[$idSite]['siteName'])) {
             $cached[$idSite]['siteName'] = $this->findSiteName($alert);
         }
         if (empty($cached[$idSite]['siteTimezone']) && !empty($cached[$idSite]['siteName'])) {
             $cached[$idSite]['siteTimezone'] = Site::getTimezoneFor($idSite);
         }
         if (!array_key_exists($report, $cached[$idSite]['report'])) {
             $cached[$idSite]['report'][$report] = $this->findReportMetadata($alert);
             $cached[$idSite]['metric'][$report] = array();
         }
         if (is_array($cached[$idSite]['metric'][$report]) && !array_key_exists($metric, $cached[$idSite]['metric'][$report])) {
             $cached[$idSite]['metric'][$report][$metric] = $processedReport->translateMetric($metric, $idSite, $alert['report']);
         }
     }
     foreach ($triggeredAlerts as &$alert) {
         $idSite = $alert['idsite'];
         $metric = $alert['metric'];
         $report = $alert['report'];
         $cachedSite = $cached[$idSite];
         $alert['value_old'] = (int) $alert['value_old'] == $alert['value_old'] ? (int) $alert['value_old'] : $alert['value_old'];
         $alert['value_new'] = (int) $alert['value_new'] == $alert['value_new'] ? (int) $alert['value_new'] : $alert['value_new'];
         $alert['reportName'] = null;
         $alert['dimension'] = null;
         $alert['reportMetric'] = !empty($cachedSite['metric'][$report][$metric]) ? $cachedSite['metric'][$report][$metric] : null;
         $alert['reportConditionName'] = null;
         $alert['siteName'] = $cached[$idSite]['siteName'];
         $alert['ts_triggered'] = $this->getPrettyDateForSite($alert['ts_triggered'], $alert['period'], $cachedSite['siteTimezone']);
         if (!empty($cachedSite['report'][$report])) {
             $reportMetadata = $cachedSite['report'][$report];
             $alert['reportName'] = $reportMetadata['name'];
             $alert['dimension'] = !empty($reportMetadata['dimension']) ? $reportMetadata['dimension'] : null;
             $conditionTranslation = array_search($alert['report_condition'], Processor::getGroupConditions(), true);
             $alert['reportConditionName'] = $conditionTranslation ? Piwik::translate($conditionTranslation) : null;
         }
     }
     return $triggeredAlerts;
 }
Example #5
0
 public function getProcessedReport($idSite, $period, $date, $apiModule, $apiAction, $segment = false, $apiParameters = false, $idGoal = false, $language = false, $showTimer = true, $hideMetricsDoc = false, $idSubtable = false, $showRawMetrics = false)
 {
     $reporter = new ProcessedReport();
     $processed = $reporter->getProcessedReport($idSite, $period, $date, $apiModule, $apiAction, $segment, $apiParameters, $idGoal, $language, $showTimer, $hideMetricsDoc, $idSubtable, $showRawMetrics);
     return $processed;
 }
 /**
  * Checks whether a report + metric exists for
  * the given idSites and if the a dimension is
  * given (requires report_condition, report_matched)
  *
  * @param int $idSite
  * @param string $apiMethodUniqueId for example MultiSites.getAll
  * @param string $metric
  * @throws \Exception
  * @return boolean
  */
 public function checkApiMethodAndMetric($idSite, $apiMethodUniqueId, $metric)
 {
     if (empty($apiMethodUniqueId) || false === strpos($apiMethodUniqueId, '_')) {
         throw new Exception(Piwik::translate('CustomAlerts_InvalidReport'));
     }
     $processedReport = new ProcessedReport();
     if (!$processedReport->isValidReportForSite($idSite, $apiMethodUniqueId)) {
         throw new Exception(Piwik::translate('CustomAlerts_InvalidReport'));
     }
     if (!$processedReport->isValidMetricForReport($metric, $idSite, $apiMethodUniqueId)) {
         throw new Exception(Piwik::translate('CustomAlerts_InvalidMetric'));
     }
 }
Example #7
0
 public function getReportByUniqueId($idSite, $reportUniqueId)
 {
     $report = $this->processedReport->getReportMetadataByUniqueId($idSite, $reportUniqueId);
     return $report;
 }
Example #8
0
 public function performSetUp($setupEnvironmentOnly = false)
 {
     // TODO: don't use static var, use test env var for this
     TestingEnvironmentManipulator::$extraPluginsToLoad = $this->extraPluginsToLoad;
     $this->dbName = $this->getDbName();
     if ($this->persistFixtureData) {
         $this->dropDatabaseInSetUp = false;
         $this->dropDatabaseInTearDown = false;
         $this->overwriteExisting = false;
         $this->removeExistingSuperUser = false;
     }
     $testEnv = $this->getTestEnvironment();
     $testEnv->delete();
     $testEnv->testCaseClass = $this->testCaseClass;
     $testEnv->fixtureClass = get_class($this);
     $testEnv->dbName = $this->dbName;
     $testEnv->extraDiEnvironments = $this->extraDiEnvironments;
     foreach ($this->extraTestEnvVars as $name => $value) {
         $testEnv->{$name} = $value;
     }
     $testEnv->save();
     $this->createEnvironmentInstance();
     if ($this->dbName === false) {
         // must be after test config is created
         $this->dbName = self::getConfig()->database['dbname'];
     }
     try {
         static::connectWithoutDatabase();
         if ($this->dropDatabaseInSetUp || $this->resetPersistedFixture) {
             $this->dropDatabase();
         }
         DbHelper::createDatabase($this->dbName);
         DbHelper::disconnectDatabase();
         Tracker::disconnectCachedDbConnection();
         // reconnect once we're sure the database exists
         self::getConfig()->database['dbname'] = $this->dbName;
         Db::createDatabaseObject();
         Db::get()->query("SET wait_timeout=28800;");
         DbHelper::createTables();
         self::getPluginManager()->unloadPlugins();
     } catch (Exception $e) {
         static::fail("TEST INITIALIZATION FAILED: " . $e->getMessage() . "\n" . $e->getTraceAsString());
     }
     include "DataFiles/Providers.php";
     if (!$this->isFixtureSetUp()) {
         DbHelper::truncateAllTables();
     }
     // We need to be SU to create websites for tests
     Access::getInstance()->setSuperUserAccess();
     Cache::deleteTrackerCache();
     ProcessedReport::reset();
     self::resetPluginsInstalledConfig();
     $testEnvironment = $this->getTestEnvironment();
     static::loadAllPlugins($testEnvironment, $this->testCaseClass, $this->extraPluginsToLoad);
     self::updateDatabase();
     self::installAndActivatePlugins($testEnvironment);
     $_GET = $_REQUEST = array();
     $_SERVER['HTTP_REFERER'] = '';
     FakeAccess::$superUserLogin = '******';
     File::$invalidateOpCacheBeforeRead = true;
     if ($this->configureComponents) {
         IPAnonymizer::deactivate();
         $dntChecker = new DoNotTrackHeaderChecker();
         $dntChecker->deactivate();
     }
     if ($this->createSuperUser) {
         self::createSuperUser($this->removeExistingSuperUser);
         if (!Access::getInstance() instanceof FakeAccess) {
             $this->loginAsSuperUser();
         }
         APILanguageManager::getInstance()->setLanguageForUser('superUserLogin', 'en');
     }
     SettingsPiwik::overwritePiwikUrl(self::getTestRootUrl());
     if ($setupEnvironmentOnly) {
         return;
     }
     PiwikCache::getTransientCache()->flushAll();
     if ($this->overwriteExisting || !$this->isFixtureSetUp()) {
         $this->setUp();
         $this->markFixtureSetUp();
         $this->log("Database {$this->dbName} marked as successfully set up.");
     } else {
         $this->log("Using existing database {$this->dbName}.");
     }
 }
 /**
  * @param  array  $alert
  * @param  int    $idSite
  * @param  int    $subPeriodN
  *
  * @return array
  */
 public function getValueForAlertInPast($alert, $idSite, $subPeriodN)
 {
     $processedReport = new ProcessedReport();
     $report = $processedReport->getReportMetadataByUniqueId($idSite, $alert['report']);
     $dateInPast = $this->getDateForAlertInPast($idSite, $alert['period'], $subPeriodN);
     $params = array('method' => $report['module'] . '.' . $report['action'], 'format' => 'original', 'idSite' => $idSite, 'period' => $alert['period'], 'date' => $dateInPast, 'flat' => 1, 'disable_queued_filters' => 1, 'filter_limit' => -1);
     if (!empty($report['parameters'])) {
         $params = array_merge($params, $report['parameters']);
     }
     $subtableId = DataTable\Manager::getInstance()->getMostRecentTableId();
     $request = new ApiRequest($params);
     $table = $request->process();
     $value = $this->aggregateToOneValue($table, $alert['metric'], $alert['report_condition'], $alert['report_matched']);
     DataTable\Manager::getInstance()->deleteAll($subtableId);
     return $value;
 }