PageRenderTime 55ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/core/CliMulti/RequestCommand.php

https://github.com/CodeYellowBV/piwik
PHP | 82 lines | 55 code | 15 blank | 12 comment | 5 complexity | db4306ebfb31d79f7fbca9564b584907 MD5 | raw file
Possible License(s): LGPL-3.0, JSON, MIT, GPL-3.0, LGPL-2.1, GPL-2.0, AGPL-1.0, BSD-2-Clause, BSD-3-Clause
  1. <?php
  2. /**
  3. * Piwik - free/libre analytics platform
  4. *
  5. * @link http://piwik.org
  6. * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  7. */
  8. namespace Piwik\CliMulti;
  9. use Piwik\Config;
  10. use Piwik\Plugin\ConsoleCommand;
  11. use Piwik\Url;
  12. use Piwik\UrlHelper;
  13. use Symfony\Component\Console\Input\InputArgument;
  14. use Symfony\Component\Console\Input\InputInterface;
  15. use Symfony\Component\Console\Input\InputOption;
  16. use Symfony\Component\Console\Output\OutputInterface;
  17. /**
  18. * RequestCommand
  19. */
  20. class RequestCommand extends ConsoleCommand
  21. {
  22. protected function configure()
  23. {
  24. $this->setName('climulti:request');
  25. $this->setDescription('Parses and executes the given query. See Piwik\CliMulti. Intended only for system usage.');
  26. $this->addArgument('url-query', null, InputOption::VALUE_REQUIRED, 'Piwik URL query string, for instance: "module=API&method=API.getPiwikVersion&token_auth=123456789"');
  27. }
  28. protected function execute(InputInterface $input, OutputInterface $output)
  29. {
  30. $this->initHostAndQueryString($input);
  31. if ($this->isTestModeEnabled()) {
  32. Config::getInstance()->setTestEnvironment();
  33. $indexFile = '/tests/PHPUnit/proxy/index.php';
  34. } else {
  35. $indexFile = '/index.php';
  36. }
  37. if (!empty($_GET['pid'])) {
  38. $process = new Process($_GET['pid']);
  39. if ($process->hasFinished()) {
  40. return;
  41. }
  42. $process->startProcess();
  43. }
  44. require_once PIWIK_INCLUDE_PATH . $indexFile;
  45. if (!empty($process)) {
  46. $process->finishProcess();
  47. }
  48. }
  49. private function isTestModeEnabled()
  50. {
  51. return !empty($_GET['testmode']);
  52. }
  53. /**
  54. * @param InputInterface $input
  55. */
  56. protected function initHostAndQueryString(InputInterface $input)
  57. {
  58. $_GET = array();
  59. $hostname = $input->getOption('piwik-domain');
  60. Url::setHost($hostname);
  61. $query = $input->getArgument('url-query');
  62. $query = UrlHelper::getArrayFromQueryString($query);
  63. foreach ($query as $name => $value) {
  64. $_GET[$name] = $value;
  65. }
  66. }
  67. }