diff options
-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 | ||||
-rw-r--r-- | plugins/CoreConsole/Commands/CoreArchiver.php | 6 |
5 files changed, 72 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)); + } } /** diff --git a/plugins/CoreConsole/Commands/CoreArchiver.php b/plugins/CoreConsole/Commands/CoreArchiver.php index e64202b001..e9b85d20e6 100644 --- a/plugins/CoreConsole/Commands/CoreArchiver.php +++ b/plugins/CoreConsole/Commands/CoreArchiver.php @@ -9,6 +9,7 @@ namespace Piwik\Plugins\CoreConsole\Commands; use Piwik\Common; use Piwik\CronArchive; +use Piwik\Log; use Piwik\Plugin\ConsoleCommand; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -34,6 +35,10 @@ class CoreArchiver extends ConsoleCommand throw new \InvalidArgumentException('No valid URL given. If you have specified a valid URL try --piwik-domain instead of --url'); } + if($input->getOption('verbose')) { + Log::getInstance()->setLogLevel(Log::VERBOSE); + } + include PIWIK_INCLUDE_PATH . '/misc/cron/archive.php'; } @@ -56,6 +61,7 @@ class CoreArchiver extends ConsoleCommand $command->addOption('force-date-last-n', null, InputOption::VALUE_REQUIRED, "This script calls the API with period=lastN. You can force the N in lastN by specifying this value."); $command->addOption('force-idsites', null, InputOption::VALUE_OPTIONAL, 'If specified, archiving will be processed only for these Sites Ids (comma separated)'); $command->addOption('force-periods', null, InputOption::VALUE_OPTIONAL, "If specified, archiving will be processed only for these Periods (comma separated eg. day,week,month)"); + $command->addOption('force-date-range', null, InputOption::VALUE_OPTIONAL, "If specified, archiving will be processed only for the periods included in this date range, eg. --force-date-range=YYYY-MM-DD,YYYY-MM-DD"); $command->addOption('skip-idsites', null, InputOption::VALUE_OPTIONAL, 'If specified, archiving will be skipped for these websites (in case these website ids would have been archived).'); $command->addOption('disable-scheduled-tasks', null, InputOption::VALUE_NONE, "Skips executing Scheduled tasks (sending scheduled reports, db optimization, etc.)."); $command->addOption('xhprof', null, InputOption::VALUE_NONE, "Enables XHProf profiler for this archive.php run. Requires XHPRof (see tests/README.xhprof.md)."); |