forked from matomo-org/matomo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs matomo-org#4903 forward archive.php to new console command
- Loading branch information
Showing
4 changed files
with
57 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,52 +21,6 @@ | |
*/ | ||
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 [email protected] | ||
* 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 @@ static public function lastRunKey($idsite, $period) | |
public function init() | ||
{ | ||
// Note: the order of methods call matters here. | ||
$this->displayHelp(); | ||
$this->initPiwikHost(); | ||
$this->initLog(); | ||
$this->initCore(); | ||
|
@@ -725,7 +678,6 @@ private function initLog() | |
|
||
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 @@ private function initCore() | |
} | ||
} | ||
|
||
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 @@ protected function setSiteIsArchived($idsite) | |
|
||
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); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 [email protected] | ||
* 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(); | ||
|