diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-03-26 07:35:10 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-03-26 07:35:10 +0400 |
commit | c2b6c25713d7e5c1037075af288447a275dc22b1 (patch) | |
tree | 97d137f9b6ffb6266f544036e14d389c14389908 | |
parent | 2af200d173464c18d393a9f7b0e562873f54664b (diff) |
refs #4903 forward archive.php to new console command
-rwxr-xr-x | console | 20 | ||||
-rw-r--r-- | core/CronArchive.php | 60 | ||||
-rw-r--r-- | misc/cron/archive.php | 44 | ||||
-rw-r--r-- | plugins/CoreConsole/Commands/CoreArchiver.php | 24 |
4 files changed, 57 insertions, 91 deletions
@@ -1,9 +1,14 @@ #!/usr/bin/env php <?php -namespace Piwik; -define('PIWIK_DOCUMENT_ROOT', dirname(__FILE__) == '/' ? '' : dirname(__FILE__)); -define('PIWIK_INCLUDE_PATH', PIWIK_DOCUMENT_ROOT); -define('PIWIK_USER_PATH', PIWIK_DOCUMENT_ROOT); +if (!defined('PIWIK_DOCUMENT_ROOT')) { + define('PIWIK_DOCUMENT_ROOT', dirname(__FILE__) == '/' ? '' : dirname(__FILE__)); +} +if (!defined('PIWIK_INCLUDE_PATH')) { + define('PIWIK_INCLUDE_PATH', PIWIK_DOCUMENT_ROOT); +} +if (!defined('PIWIK_USER_PATH')) { + define('PIWIK_USER_PATH', PIWIK_DOCUMENT_ROOT); +} require_once PIWIK_INCLUDE_PATH . '/core/testMinimumPhpVersion.php'; require_once file_exists(PIWIK_INCLUDE_PATH . '/vendor/autoload.php') @@ -12,11 +17,12 @@ require_once file_exists(PIWIK_INCLUDE_PATH . '/vendor/autoload.php') require_once PIWIK_INCLUDE_PATH . '/core/Loader.php'; require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php'; -Translate::loadEnglishTranslation(); +Piwik\Translate::loadEnglishTranslation(); -if (!Common::isPhpCliMode()) { +if (!Piwik\Common::isPhpCliMode()) { exit; } -$console = new Console(); + +$console = new Piwik\Console(); $console->init(); $console->run();
\ No newline at end of file diff --git a/core/CronArchive.php b/core/CronArchive.php index 8a6fceb60f..89433c8539 100644 --- a/core/CronArchive.php +++ b/core/CronArchive.php @@ -21,52 +21,6 @@ use Piwik\Plugins\SitesManager\API as APISitesManager; */ class CronArchive { - static public function getUsage() - { - return "Usage: - /path/to/cli/php \"" . @$_SERVER['argv'][0] . "\" --url=http://your-website.org/path/to/piwik/ [arguments] - -Arguments: - --url=[piwik-server-url] - Mandatory argument. Must be set to the Piwik base URL. - For example: --url=http://analytics.example.org/ or --url=https://example.org/piwik/ - --force-all-websites - If specified, the script will trigger archiving on all websites and all past dates. - You may use --force-all-periods=[seconds] to trigger archiving on those websites that had visits in the last [seconds] seconds. - --force-all-periods[=seconds] - Limits archiving to websites with some traffic in the last [seconds] seconds. - For example --force-all-periods=86400 will archive websites that had visits in the last 24 hours. - If [seconds] is not specified, all websites with visits in the last ". CronArchive::ARCHIVE_SITES_WITH_TRAFFIC_SINCE - . " seconds (" . round( CronArchive::ARCHIVE_SITES_WITH_TRAFFIC_SINCE/86400 ) ." days) will be archived. - --force-timeout-for-periods=[seconds] - The current week/ current month/ current year will be processed at most every [seconds]. - If not specified, defaults to ". CronArchive::SECONDS_DELAY_BETWEEN_PERIOD_ARCHIVES.". - --force-date-last-n=M - This script calls the API with period=lastN. You can force the N in lastN by specifying this value. - --force-idsites=1,2,n - Restricts archiving to the specified website IDs, comma separated list. - --skip-idsites=1,2,n - If the specified websites IDs were to be archived, skip them instead. - --disable-scheduled-tasks - Skips executing Scheduled tasks (sending scheduled reports, db optimization, etc.). - --xhprof - Enables XHProf profiler for this archive.php run. Requires XHPRof (see tests/README.xhprof.md). - --accept-invalid-ssl-certificate - It is _NOT_ recommended to use this argument. Instead, you should use a valid SSL certificate! - It can be useful if you specified --url=https://... or if you are using Piwik with force_ssl=1 - --help - Displays usage - -Notes: - * It is recommended to run the script with the argument --url=[piwik-server-url] only. Other arguments are not required. - * This script should be executed every hour via crontab, or as a deamon. - * You can also run it via http:// by specifying the Super User &token_auth=XYZ as a parameter ('Web Cron'), - but it is recommended to run it via command line/CLI instead. - * If you have any suggestion about this script, please let the team know at hello@piwik.org - * Enjoy! -"; - } - // the url can be set here before the init, and it will be used instead of --url= static public $url = false; @@ -141,7 +95,6 @@ Notes: public function init() { // Note: the order of methods call matters here. - $this->displayHelp(); $this->initPiwikHost(); $this->initLog(); $this->initCore(); @@ -725,7 +678,6 @@ Notes: if (!function_exists("curl_multi_init")) { $this->log("ERROR: this script requires curl extension php_curl enabled in your CLI php.ini"); - $this->usage(); exit; } } @@ -763,16 +715,6 @@ Notes: } } - private function displayHelp() - { - $displayHelp = $this->getParameterFromCli('help') || $this->getParameterFromCli('h'); - - if ($displayHelp) { - $this->usage(); - exit; - } - } - /** * Initializes the various parameters to the script, based on input parameters. * @@ -1150,7 +1092,7 @@ Notes: private function logFatalErrorUrlExpected() { - $this->logFatalError("archive.php expects the argument 'url' to be set to your Piwik URL, for example: url=http://example.org/piwik/ " + $this->logFatalError("archive.php expects the argument 'url' to be set to your Piwik URL, for example: --url=http://example.org/piwik/ " . "\n--help for more information", $backtrace = false); } diff --git a/misc/cron/archive.php b/misc/cron/archive.php index ff2fd5c485..73c248bded 100644 --- a/misc/cron/archive.php +++ b/misc/cron/archive.php @@ -9,30 +9,30 @@ * @package Piwik */ -namespace Piwik; - -use Exception; - -if (!defined('PIWIK_INCLUDE_PATH')) { - define('PIWIK_INCLUDE_PATH', realpath(dirname(__FILE__) . "/../..")); +$callee = array_shift($_SERVER['argv']); +$args = array($callee); +$args[] = 'core:archive'; +foreach ($_SERVER['argv'] as $arg) { + if (0 === strpos($arg, '--')) { + $args[] = $arg; + } elseif (0 === strpos($arg, '-')) { + $args[] = '-' . $arg; + } else { + $args[] = '--' . $arg; + } } -if (!defined('PIWIK_USER_PATH')) { - define('PIWIK_USER_PATH', PIWIK_INCLUDE_PATH); -} +$_SERVER['argv'] = $args; -define('PIWIK_ENABLE_DISPATCH', false); -define('PIWIK_ENABLE_ERROR_HANDLER', false); -define('PIWIK_ENABLE_SESSION_START', false); +$piwikHome = realpath(dirname(__FILE__) . "/../.."); -require_once PIWIK_INCLUDE_PATH . "/index.php"; - -$archiving = new CronArchive(); -try { - $archiving->init(); - $archiving->run(); - $archiving->runScheduledTasks(); - $archiving->end(); -} catch (Exception $e) { - $archiving->logFatalError($e->getMessage()); +if (false !== strpos($callee, 'archive.php')) { +echo " +------------------------------------------------------- +Using this 'archive.php' script is no longer recommended. +Please use '/path/to/php $piwikHome/console core:archive " . implode(' ', array_slice($args, 2)) . "' instead. +------------------------------------------------------- +\n\n"; } + +include $piwikHome . '/console';
\ No newline at end of file diff --git a/plugins/CoreConsole/Commands/CoreArchiver.php b/plugins/CoreConsole/Commands/CoreArchiver.php index a60da70f3a..96f3485b52 100644 --- a/plugins/CoreConsole/Commands/CoreArchiver.php +++ b/plugins/CoreConsole/Commands/CoreArchiver.php @@ -7,7 +7,6 @@ */ namespace Piwik\Plugins\CoreConsole\Commands; -use Piwik\CliMulti; use Piwik\CronArchive; use Piwik\Plugin\ConsoleCommand; use Symfony\Component\Console\Input\InputArgument; @@ -20,12 +19,31 @@ class CoreArchiver extends ConsoleCommand protected function configure() { $this->setName('core:archive'); - $this->setDescription('Runs the CLI archiver'); - $this->addArgument('config', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Any parameters supported by the CronArchiver. Eg ./console core:archive url=http://example.org/piwik', array()); + $this->setDescription("Runs the CLI archiver. It usually runs as a cron and is a useful tool for general maintenance, and pre-process reports for a Fast dashboard rendering."); + $this->setHelp("* It is recommended to run the script with the option --piwik-domain=[piwik-server-url] only. Other options are not required. +* This script should be executed every hour via crontab, or as a daemon. +* You can also run it via http:// by specifying the Super User &token_auth=XYZ as a parameter ('Web Cron'), + but it is recommended to run it via command line/CLI instead. +* If you have any suggestion about this script, please let the team know at hello@piwik.org +* Enjoy!"); + $this->addOption('url', null, InputOption::VALUE_REQUIRED, "Mandatory option as an alternative to '--piwik-domain'. Must be set to the Piwik base URL.\nFor example: --url=http://analytics.example.org/ or --url=https://example.org/piwik/"); + $this->addOption('force-all-websites', null, InputOption::VALUE_NONE, "If specified, the script will trigger archiving on all websites and all past dates.\nYou may use --force-all-periods=[seconds] to trigger archiving on those websites\nthat had visits in the last [seconds] seconds."); + $this->addOption('force-all-periods', null, InputOption::VALUE_OPTIONAL, "Limits archiving to websites with some traffic in the last [seconds] seconds. \nFor example --force-all-periods=86400 will archive websites that had visits in the last 24 hours. \nIf [seconds] is not specified, all websites with visits in the last " . CronArchive::ARCHIVE_SITES_WITH_TRAFFIC_SINCE . "\n seconds (" . round( CronArchive::ARCHIVE_SITES_WITH_TRAFFIC_SINCE/86400 ) ." days) will be archived."); + $this->addOption('force-timeout-for-periods', null, InputOption::VALUE_OPTIONAL, "The current week/ current month/ current year will be processed at most every [seconds].\nIf not specified, defaults to ". CronArchive::SECONDS_DELAY_BETWEEN_PERIOD_ARCHIVES."."); + $this->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."); + $this->addOption('force-idsites', null,InputOption::VALUE_REQUIRED, "Restricts archiving to the specified website IDs, comma separated list."); + $this->addOption('skip-idsites', null, InputOption::VALUE_REQUIRED, "If the specified websites IDs were to be archived, skip them instead."); + $this->addOption('disable-scheduled-tasks', null, InputOption::VALUE_NONE, "Skips executing Scheduled tasks (sending scheduled reports, db optimization, etc.)."); + $this->addOption('xhprof', null, InputOption::VALUE_NONE, "Enables XHProf profiler for this archive.php run. Requires XHPRof (see tests/README.xhprof.md)."); + $this->addOption('accept-invalid-ssl-certificate', null, InputOption::VALUE_NONE, "It is _NOT_ recommended to use this argument. Instead, you should use a valid SSL certificate!\nIt can be useful if you specified --url=https://... or if you are using Piwik with force_ssl=1"); } protected function execute(InputInterface $input, OutputInterface $output) { + if ($input->getOption('piwik-domain') && !$input->getOption('url')) { + $_SERVER['argv'][] = '--url=' . $input->getOption('piwik-domain'); + } + $this->initEnv(); $archiving = new CronArchive(); |