diff --git a/core/CliMulti.php b/core/CliMulti.php index 32390616618d6d887a1dc6e98daa77a5edd36183..42285fd028c9edd08d12dfa6707fb13e2f43ceec 100644 --- a/core/CliMulti.php +++ b/core/CliMulti.php @@ -90,12 +90,12 @@ class CliMulti { } } - private function buildCommand($query, $outputFile) + private function buildCommand($hostname, $query, $outputFile) { $bin = $this->findPhpBinary(); - return sprintf('%s -q %s/console climulti:request %s > %s 2>&1 &', - $bin, PIWIK_INCLUDE_PATH, escapeshellarg($query), $outputFile); + return sprintf('%s -q %s/console climulti:request --piwik-domain=%s %s > %s 2>&1 &', + $bin, PIWIK_INCLUDE_PATH, escapeshellarg($hostname), escapeshellarg($query), $outputFile); } private function getResponse() @@ -223,8 +223,10 @@ class CliMulti { $url = $this->appendTestmodeParamToUrlIfNeeded($url); $query = Url::getQueryFromUrl($url, array('pid' => $cmdId)); - $command = $this->buildCommand($query, $output->getPathToFile()); + $hostname = parse_url($url, PHP_URL_HOST); + $command = $this->buildCommand($hostname, $query, $output->getPathToFile()); + Log::debug($command); shell_exec($command); } diff --git a/core/CliMulti/RequestCommand.php b/core/CliMulti/RequestCommand.php index 2a5a567bf42832e6c591c0bb340000b2b6e51be7..a9ddd51a3cd9c0b06260632e068990a97ed0ac1b 100644 --- a/core/CliMulti/RequestCommand.php +++ b/core/CliMulti/RequestCommand.php @@ -9,6 +9,7 @@ namespace Piwik\CliMulti; use Piwik\Plugin\ConsoleCommand; +use Piwik\Url; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -26,13 +27,19 @@ class RequestCommand extends ConsoleCommand { $this->setName('climulti:request'); $this->setDescription('Parses and executes the given query. See Piwik\CliMulti. Intended only for system usage.'); - $this->addArgument('url', InputArgument::OPTIONAL, 'Piwik URL, for instance "module=API&method=API.getPiwikVersion&token_auth=123456789"', ''); + $this->addArgument('url', null, InputOption::VALUE_REQUIRED, 'Piwik URL query string, for instance: "module=API&method=API.getPiwikVersion&token_auth=123456789"'); } protected function execute(InputInterface $input, OutputInterface $output) { $_GET = array(); - FrontController::assignCliParametersToRequest(); + + $hostname = $input->getOption('piwik-domain'); + Url::setHost($hostname); + + $url = $input->getArgument('url'); + $query = Url::getQueryStringFromUrl($url); + parse_str($query, $_GET); if ($this->isTestModeEnabled()) { Config::getInstance()->setTestEnvironment(); diff --git a/core/Console.php b/core/Console.php index af0a62bc9bd9fcf9d58ef51721f19572e6d3416f..54bfcc093886babac67c0803944505d0e02d9366 100644 --- a/core/Console.php +++ b/core/Console.php @@ -9,12 +9,17 @@ namespace Piwik; use Symfony\Component\Console\Application; +use Symfony\Component\Console\Input\InputOption; class Console { public function run() { $console = new Application(); + $option = new InputOption('piwik-domain', null, InputOption::VALUE_OPTIONAL, 'Piwik URL (protocol and domain) eg. "http://piwik.example.org"'); + + $console->getDefinition()->addOption($option); + $commands = $this->getAvailableCommands(); foreach ($commands as $command) { diff --git a/core/Url.php b/core/Url.php index a5f90140ce4a2515f925d90fc63bcef79994c020..0aa5e885904a53922cf870b91d794bd0bfd26746 100644 --- a/core/Url.php +++ b/core/Url.php @@ -434,18 +434,28 @@ class Url return $query; } + static public function getQueryStringFromUrl($url) + { + return parse_url($url, PHP_URL_QUERY); + } + + static public function getHostFromUrl($url) + { + return parse_url($url, PHP_URL_HOST); + } + /** * Returns the query part from any valid url and adds additional parameters to the query part if needed. * - * @param string $aUrl Any url eg `"http://example.com/piwik/?foo=bar"` + * @param string $url Any url eg `"http://example.com/piwik/?foo=bar"` * @param array $additionalParamsToAdd If not empty the given parameters will be added to the query. * * @return string eg. `"foo=bar&foo2=bar2"` * @api */ - static public function getQueryFromUrl($aUrl, array $additionalParamsToAdd) + static public function getQueryFromUrl($url, array $additionalParamsToAdd) { - $url = @parse_url($aUrl); + $url = @parse_url($url); $query = ''; if (!empty($url['query'])) { diff --git a/misc/cron/archive.php b/misc/cron/archive.php index fab800af3956178c8eba9070cbf0cefdf3147f2c..dcc5fdaa4dc60e1ebe88f064127c35f6405eff1a 100644 --- a/misc/cron/archive.php +++ b/misc/cron/archive.php @@ -13,15 +13,6 @@ namespace Piwik; use Exception; -/* -Ideas for improvements: - - Known limitation: when adding new segments to preprocess, script will assume that data was processed for this segment in the past - Workaround: run --force-all-websites --force-all-periods=10000000 to archive everything. - - Possible performance improvement - - Run first websites which are faster to process (weighted by visits and/or time to generate the last daily report) - This would make sure that huge websites do not 'block' processing of smaller websites' reports. -*/ - if (!defined('PIWIK_INCLUDE_PATH')) { define('PIWIK_INCLUDE_PATH', realpath(dirname(__FILE__) . "/../..")); }