PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / CliMulti / RequestCommand.php
matomo / app / core / CliMulti Last commit date
CliPhp.php 1 year ago Output.php 2 years ago OutputInterface.php 2 years ago Process.php 1 year ago ProcessSymfony.php 1 year ago RequestCommand.php 1 year ago StaticOutput.php 1 year ago
RequestCommand.php
104 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 */
9 namespace Piwik\CliMulti;
10
11 use Piwik\Application\Environment;
12 use Piwik\Access;
13 use Piwik\Container\StaticContainer;
14 use Piwik\Db;
15 use Piwik\Log;
16 use Piwik\Option;
17 use Piwik\Plugin\ConsoleCommand;
18 use Piwik\Url;
19 use Piwik\UrlHelper;
20 /**
21 * RequestCommand
22 */
23 class RequestCommand extends ConsoleCommand
24 {
25 /**
26 * @var Environment
27 */
28 private $environment;
29 protected function configure()
30 {
31 $this->setName('climulti:request');
32 $this->setDescription('Parses and executes the given query. See Piwik\\CliMulti. Intended only for system usage.');
33 $this->addRequiredArgument('url-query', 'Matomo URL query string, for instance: "module=API&method=API.getPiwikVersion&token_auth=123456789"');
34 $this->addNoValueOption('superuser', null, 'If supplied, runs the code as superuser.');
35 }
36 protected function doExecute() : int
37 {
38 $this->recreateContainerWithWebEnvironment();
39 $this->initHostAndQueryString();
40 if ($this->isTestModeEnabled()) {
41 $indexFile = '/tests/PHPUnit/proxy/';
42 $this->resetDatabase();
43 } else {
44 $indexFile = '/';
45 }
46 $indexFile .= 'index.php';
47 if (!empty($_GET['pid'])) {
48 $process = new \Piwik\CliMulti\Process($_GET['pid']);
49 if ($process->hasFinished()) {
50 return self::SUCCESS;
51 }
52 $process->startProcess();
53 }
54 if ($this->getInput()->getOption('superuser')) {
55 StaticContainer::addDefinitions(array('observers.global' => \Piwik\DI::add(array(array('Environment.bootstrapped', \Piwik\DI::value(function () {
56 Access::getInstance()->setSuperUserAccess(\true);
57 }))))));
58 }
59 require_once PIWIK_INCLUDE_PATH . $indexFile;
60 while (ob_get_level()) {
61 echo ob_get_clean();
62 }
63 if (!empty($process)) {
64 $process->finishProcess();
65 }
66 return self::SUCCESS;
67 }
68 private function isTestModeEnabled()
69 {
70 return !empty($_GET['testmode']);
71 }
72 protected function initHostAndQueryString()
73 {
74 $_GET = array();
75 $hostname = $this->getInput()->getOption('matomo-domain');
76 Url::setHost($hostname);
77 $query = $this->getInput()->getArgument('url-query');
78 $_SERVER['QUERY_STRING'] = $query;
79 $query = UrlHelper::getArrayFromQueryString($query);
80 // NOTE: this method can create the StaticContainer now
81 foreach ($query as $name => $value) {
82 $_GET[$name] = urldecode($value);
83 }
84 }
85 /**
86 * We will be simulating an HTTP request here (by including index.php).
87 *
88 * To avoid weird side-effects (e.g. the logging output messing up the HTTP response on the CLI output)
89 * we need to recreate the container with the default environment instead of the CLI environment.
90 */
91 private function recreateContainerWithWebEnvironment()
92 {
93 StaticContainer::clearContainer();
94 Log::unsetInstance();
95 $this->environment = new Environment(null);
96 $this->environment->init();
97 }
98 private function resetDatabase()
99 {
100 Option::clearCache();
101 Db::destroyDatabaseObject();
102 }
103 }
104