diff options
author | mattab <matthieu.aubry@gmail.com> | 2014-07-01 10:49:19 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2014-07-01 10:49:19 +0400 |
commit | 3e2260913657b051cb73f9fdf1d4378ccc6c0b88 (patch) | |
tree | 7a61bc2871e84a07203802d410a914002903a069 /core | |
parent | 771220c82eaf372166886d372830a3a5c5495dd4 (diff) |
Add support for --force-date-range parameter + also enable Verbose logging via -v
refs https://github.com/piwik/piwik/pull/319
refs #5396
Diffstat (limited to 'core')
-rw-r--r-- | core/CronArchive.php | 87 | ||||
-rw-r--r-- | core/FrontController.php | 1 | ||||
-rw-r--r-- | core/Log.php | 5 | ||||
-rw-r--r-- | core/Profiler.php | 7 |
4 files changed, 66 insertions, 34 deletions
diff --git a/core/CronArchive.php b/core/CronArchive.php index d13de52a50..5b8dc75811 100644 --- a/core/CronArchive.php +++ b/core/CronArchive.php @@ -133,7 +133,7 @@ class CronArchive $this->allWebsites = APISitesManager::getInstance()->getAllSitesId(); if(!empty($this->shouldArchiveOnlySpecificPeriods)) { - $this->log("- Will only process the following periods: " . implode(", ", $this->shouldArchiveOnlySpecificPeriods) . " (--force-periods)"); + $this->log("- Will process the following periods: " . implode(", ", $this->shouldArchiveOnlySpecificPeriods) . " (--force-periods)"); } $websitesIds = $this->initWebsiteIds(); @@ -455,9 +455,9 @@ class CronArchive /** * Returns base URL to process reports for the $idSite on a given $period */ - private function getVisitsRequestUrl($idSite, $period, $dateLast) + private function getVisitsRequestUrl($idSite, $period, $date) { - return "?module=API&method=API.get&idSite=$idSite&period=$period&date=last" . $dateLast . "&format=php&token_auth=" . $this->token_auth; + return "?module=API&method=API.get&idSite=$idSite&period=$period&date=" . $date . "&format=php&token_auth=" . $this->token_auth; } private function initSegmentsToArchive() @@ -505,7 +505,7 @@ class CronArchive $processDaysSince = false; } - $dateLast = $this->getApiDateLastParameter($idSite, "day", $processDaysSince); + $dateLast = $this->getApiDateParameter($idSite, "day", $processDaysSince); $url = $this->getVisitsRequestUrl($idSite, "day", $dateLast); $content = $this->request($url); $daysResponse = @unserialize($content); @@ -581,7 +581,7 @@ class CronArchive $url = $this->piwikUrl; - $dateLast = $this->getApiDateLastParameter($idSite, $period, $lastTimestampWebsiteProcessed); + $dateLast = $this->getApiDateParameter($idSite, $period, $lastTimestampWebsiteProcessed); $url .= $this->getVisitsRequestUrl($idSite, $period, $dateLast); @@ -742,11 +742,10 @@ class CronArchive } // Make sure we log at least INFO (if logger is set to DEBUG then keep it) - $logLevel = @$log[\Piwik\Log::LOG_LEVEL_CONFIG_OPTION]; - if ($logLevel != 'VERBOSE' - && $logLevel != 'DEBUG' + $logLevel = Log::getInstance()->getLogLevel(); + if ($logLevel != Log::VERBOSE + && $logLevel != Log::DEBUG ) { - $log[\Piwik\Log::LOG_LEVEL_CONFIG_OPTION] = 'INFO'; Log::getInstance()->setLogLevel(Log::INFO); } @@ -1202,30 +1201,13 @@ class CronArchive * @param $lastTimestampWebsiteProcessed * @return float|int|true */ - private function getApiDateLastParameter($idSite, $period, $lastTimestampWebsiteProcessed = false) + private function getApiDateParameter($idSite, $period, $lastTimestampWebsiteProcessed = false) { - $dateLastMax = self::DEFAULT_DATE_LAST; - if ($period == 'year') { - $dateLastMax = self::DEFAULT_DATE_LAST_YEARS; - } elseif ($period == 'week') { - $dateLastMax = self::DEFAULT_DATE_LAST_WEEKS; - } - if (empty($lastTimestampWebsiteProcessed)) { - $lastTimestampWebsiteProcessed = strtotime(\Piwik\Site::getCreationDateFor($idSite)); - } - - // Enforcing last2 at minimum to work around timing issues and ensure we make most archives available - $dateLast = floor((time() - $lastTimestampWebsiteProcessed) / 86400) + 2; - if ($dateLast > $dateLastMax) { - $dateLast = $dateLastMax; + $dateRangeForced = $this->getDateRangeToProcess(); + if(!empty($dateRangeForced)) { + return $dateRangeForced; } - - $dateLastForced = $this->getParameterFromCli('--force-date-last-n', true); - if (!empty($dateLastForced)) { - $dateLast = $dateLastForced; - return $dateLast; - } - return $dateLast; + return $this->getDateLastN($idSite, $period, $lastTimestampWebsiteProcessed); } /** @@ -1245,6 +1227,18 @@ class CronArchive . $timer->__toString()); } + private function getDateRangeToProcess() + { + $restrictToDateRange = $this->getParameterFromCli("force-date-range", true); + if(empty($restrictToDateRange)) { + return false; + } + if(strpos($restrictToDateRange, ',') === false) { + throw new Exception("--force-date-range expects a date range ie. YYYY-MM-DD,YYYY-MM-DD"); + } + return $restrictToDateRange; + } + /** * @return array */ @@ -1281,4 +1275,35 @@ class CronArchive } return in_array($period, $this->shouldArchiveOnlySpecificPeriods); } + + /** + * @param $idSite + * @param $period + * @param $lastTimestampWebsiteProcessed + * @return string + */ + private function getDateLastN($idSite, $period, $lastTimestampWebsiteProcessed) + { + $dateLastMax = self::DEFAULT_DATE_LAST; + if ($period == 'year') { + $dateLastMax = self::DEFAULT_DATE_LAST_YEARS; + } elseif ($period == 'week') { + $dateLastMax = self::DEFAULT_DATE_LAST_WEEKS; + } + if (empty($lastTimestampWebsiteProcessed)) { + $lastTimestampWebsiteProcessed = strtotime(\Piwik\Site::getCreationDateFor($idSite)); + } + + // Enforcing last2 at minimum to work around timing issues and ensure we make most archives available + $dateLast = floor((time() - $lastTimestampWebsiteProcessed) / 86400) + 2; + if ($dateLast > $dateLastMax) { + $dateLast = $dateLastMax; + } + + $dateLastForced = $this->getParameterFromCli('--force-date-last-n', true); + if (!empty($dateLastForced)) { + $dateLast = $dateLastForced; + } + return "last" . $dateLast; + } } diff --git a/core/FrontController.php b/core/FrontController.php index 7be6beda9d..fb4f27de5c 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -172,7 +172,6 @@ class FrontController extends Singleton // in tracker mode Piwik\Tracker\Db\Pdo\Mysql does currently not implement profiling Profiler::displayDbProfileReport(); Profiler::printQueryCount(); - Log::debug(Registry::get('timer')); } } catch (Exception $e) { Log::verbose($e); diff --git a/core/Log.php b/core/Log.php index c568bdb0a2..2c67207b71 100644 --- a/core/Log.php +++ b/core/Log.php @@ -373,6 +373,11 @@ class Log extends Singleton $this->currentLogLevel = $logLevel; } + public function getLogLevel() + { + return $this->currentLogLevel; + } + private function logToFile($level, $tag, $datetime, $message) { $message = $this->getMessageFormattedFile($level, $tag, $datetime, $message); diff --git a/core/Profiler.php b/core/Profiler.php index bcbf67019c..e3a62f7049 100644 --- a/core/Profiler.php +++ b/core/Profiler.php @@ -52,7 +52,8 @@ class Profiler $profiler = Db::get()->getProfiler(); if (!$profiler->getEnabled()) { - throw new \Exception("To display the profiler you should enable enable_sql_profiler on your config/config.ini.php file"); + // To display the profiler you should enable enable_sql_profiler on your config/config.ini.php file + return; } $infoIndexedByQuery = array(); @@ -133,7 +134,9 @@ class Profiler { $totalTime = self::getDbElapsedSecs(); $queryCount = Profiler::getQueryCount(); - Log::debug(sprintf("Total queries = %d (total sql time = %.2fs)", $queryCount, $totalTime)); + if($queryCount > 0) { + Log::debug(sprintf("Total queries = %d (total sql time = %.2fs)", $queryCount, $totalTime)); + } } /** |