Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2014-02-18 04:30:41 +0400
committermattab <matthieu.aubry@gmail.com>2014-02-18 04:30:41 +0400
commit58449a825aaddf2f9bd223cdb89fd6c74775440f (patch)
tree52fcb4935bbcfef21ffcd73f96f66ddc804a7f39 /core
parent06946af25eb5785e85a01e4c3117b2bb718497b8 (diff)
Finishing clearing the console command to allow piwik domain
Diffstat (limited to 'core')
-rw-r--r--core/CliMulti.php8
-rw-r--r--core/CliMulti/RequestCommand.php29
-rw-r--r--core/Url.php37
-rw-r--r--core/UrlHelper.php37
4 files changed, 61 insertions, 50 deletions
diff --git a/core/CliMulti.php b/core/CliMulti.php
index 42285fd028..ccd0cbf935 100644
--- a/core/CliMulti.php
+++ b/core/CliMulti.php
@@ -7,8 +7,8 @@
*/
namespace Piwik;
-use Piwik\CliMulti\Process;
use Piwik\CliMulti\Output;
+use Piwik\CliMulti\Process;
/**
* Class CliMulti.
@@ -221,9 +221,9 @@ class CliMulti {
{
$this->processes[] = new Process($cmdId);
- $url = $this->appendTestmodeParamToUrlIfNeeded($url);
- $query = Url::getQueryFromUrl($url, array('pid' => $cmdId));
- $hostname = parse_url($url, PHP_URL_HOST);
+ $url = $this->appendTestmodeParamToUrlIfNeeded($url);
+ $query = UrlHelper::getQueryFromUrl($url, array('pid' => $cmdId));
+ $hostname = UrlHelper::getHostFromUrl($url);
$command = $this->buildCommand($hostname, $query, $output->getPathToFile());
Log::debug($command);
diff --git a/core/CliMulti/RequestCommand.php b/core/CliMulti/RequestCommand.php
index a9ddd51a3c..8a1df0db19 100644
--- a/core/CliMulti/RequestCommand.php
+++ b/core/CliMulti/RequestCommand.php
@@ -10,6 +10,7 @@ namespace Piwik\CliMulti;
use Piwik\Plugin\ConsoleCommand;
use Piwik\Url;
+use Piwik\UrlHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -27,19 +28,12 @@ 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', null, InputOption::VALUE_REQUIRED, 'Piwik URL query string, for instance: "module=API&method=API.getPiwikVersion&token_auth=123456789"');
+ $this->addArgument('url-query', 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();
-
- $hostname = $input->getOption('piwik-domain');
- Url::setHost($hostname);
-
- $url = $input->getArgument('url');
- $query = Url::getQueryStringFromUrl($url);
- parse_str($query, $_GET);
+ $this->initHostAndQueryString($input);
if ($this->isTestModeEnabled()) {
Config::getInstance()->setTestEnvironment();
@@ -72,4 +66,21 @@ class RequestCommand extends ConsoleCommand
return !empty($_GET['testmode']);
}
+ /**
+ * @param InputInterface $input
+ */
+ protected function initHostAndQueryString(InputInterface $input)
+ {
+ $_GET = array();
+
+ $hostname = $input->getOption('piwik-domain');
+ Url::setHost($hostname);
+
+ $query = $input->getArgument('url-query');
+ $query = UrlHelper::getArrayFromQueryString($query);
+ foreach ($query as $name => $value) {
+ $_GET[$name] = $value;
+ }
+ }
+
} \ No newline at end of file
diff --git a/core/Url.php b/core/Url.php
index 34b1175dfc..c023228fac 100644
--- a/core/Url.php
+++ b/core/Url.php
@@ -439,43 +439,6 @@ class Url
return parse_url($url, PHP_URL_QUERY);
}
- static public function getHostFromUrl($url)
- {
- if(!UrlHelper::isLookLikeUrl($url)) {
- $url = "http://" . $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 $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($url, array $additionalParamsToAdd)
- {
- $url = @parse_url($url);
- $query = '';
-
- if (!empty($url['query'])) {
- $query .= $url['query'];
- }
-
- if (!empty($additionalParamsToAdd)) {
- if (!empty($query)) {
- $query .= '&';
- }
-
- $query .= self::getQueryStringFromParameters($additionalParamsToAdd);
- }
-
- return $query;
- }
-
/**
* Redirects the user to the referrer. If no referrer exists, the user is redirected
* to the current URL without query string.
diff --git a/core/UrlHelper.php b/core/UrlHelper.php
index dbdb04dfd2..2ce26ba165 100644
--- a/core/UrlHelper.php
+++ b/core/UrlHelper.php
@@ -456,4 +456,41 @@ class UrlHelper
'keywords' => $key,
);
}
+
+ /**
+ * Returns the query part from any valid url and adds additional parameters to the query part if needed.
+ *
+ * @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
+ */
+ public static function getQueryFromUrl($url, array $additionalParamsToAdd = array())
+ {
+ $url = @parse_url($url);
+ $query = '';
+
+ if (!empty($url['query'])) {
+ $query .= $url['query'];
+ }
+
+ if (!empty($additionalParamsToAdd)) {
+ if (!empty($query)) {
+ $query .= '&';
+ }
+
+ $query .= Url::getQueryStringFromParameters($additionalParamsToAdd);
+ }
+
+ return $query;
+ }
+
+ public static function getHostFromUrl($url)
+ {
+ if (!UrlHelper::isLookLikeUrl($url)) {
+ $url = "http://" . $url;
+ }
+ return parse_url($url, PHP_URL_HOST);
+ }
}