From ddfa42e16f6648a1f54d2912fcc897e0ae07b75e Mon Sep 17 00:00:00 2001 From: diosmosis Date: Wed, 23 Dec 2020 15:42:15 -0800 Subject: Better fix for climulti segment encoding bug (#17004) * Segment should not be double encoded when async climulti is unsupported. * better fix for original bug, make sure request command sets query_string since it is used to get the segment * remove use * Use curl requests for core:archive in test. * fix test --- core/CliMulti/Process.php | 16 ++++++++++++++++ core/CliMulti/RequestCommand.php | 2 ++ core/CronArchive.php | 12 +++++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/CliMulti/Process.php b/core/CliMulti/Process.php index ad1d30cd56..8133da8878 100644 --- a/core/CliMulti/Process.php +++ b/core/CliMulti/Process.php @@ -8,6 +8,7 @@ namespace Piwik\CliMulti; use Piwik\CliMulti; +use Piwik\Container\StaticContainer; use Piwik\Filesystem; use Piwik\SettingsServer; @@ -45,6 +46,15 @@ class Process $this->markAsNotStarted(); } + private static function isForcingAsyncProcessMode() + { + try { + return (bool) StaticContainer::get('test.vars.forceCliMultiViaCurl'); + } catch (\Exception $ex) { + return false; + } + } + public function getPid() { return $this->pid; @@ -178,6 +188,12 @@ class Process public static function isSupported() { + if (defined('PIWIK_TEST_MODE') + && self::isForcingAsyncProcessMode() + ) { + return false; + } + if (SettingsServer::isWindows()) { return false; } diff --git a/core/CliMulti/RequestCommand.php b/core/CliMulti/RequestCommand.php index f2e07dcb94..8dbd8d9ed0 100644 --- a/core/CliMulti/RequestCommand.php +++ b/core/CliMulti/RequestCommand.php @@ -103,6 +103,8 @@ class RequestCommand extends ConsoleCommand Url::setHost($hostname); $query = $input->getArgument('url-query'); + $_SERVER['QUERY_STRING'] = $query; + $query = UrlHelper::getArrayFromQueryString($query); // NOTE: this method can create the StaticContainer now foreach ($query as $name => $value) { $_GET[$name] = urldecode($value); diff --git a/core/CronArchive.php b/core/CronArchive.php index da8236b355..57e6ea259d 100644 --- a/core/CronArchive.php +++ b/core/CronArchive.php @@ -211,6 +211,11 @@ class CronArchive */ private $cliMultiRequestParser; + /** + * @var bool|mixed + */ + private $supportsAsync; + /** * Constructor. * @@ -235,7 +240,8 @@ class CronArchive $this->rawLogDao = new RawLogDao(); - $this->cliMultiRequestParser = new RequestParser($this->makeCliMulti()->supportsAsync()); + $this->supportsAsync = $this->makeCliMulti()->supportsAsync(); + $this->cliMultiRequestParser = new RequestParser($this->supportsAsync); $this->archiveFilter = new ArchiveFilter(); } @@ -654,7 +660,7 @@ class CronArchive { $request = "?module=API&method=CoreAdminHome.archiveReports&idSite=$idSite&period=$period&date=" . $date . "&format=json"; if ($segment) { - $request .= '&segment=' . urlencode(urlencode($segment)); + $request .= '&segment=' . urlencode($segment); } if (!empty($plugin)) { $request .= "&plugin=" . $plugin; @@ -696,7 +702,7 @@ class CronArchive if (empty($response)) { $message .= "The response was empty. This usually means a server error. A solution to this error is generally to increase the value of 'memory_limit' in your php.ini file. "; - if($this->makeCliMulti()->supportsAsync()) { + if($this->supportsAsync) { $message .= " For more information and the error message please check in your PHP CLI error log file. As this core:archive command triggers PHP processes over the CLI, you can find where PHP CLI logs are stored by running this command: php -i | grep error_log"; } else { $message .= " For more information and the error message please check your web server's error Log file. As this core:archive command triggers PHP processes over HTTP, you can find the error message in your Matomo's web server error logs. "; -- cgit v1.2.3