diff --git a/core/CliMulti/RequestParser.php b/core/CliMulti/RequestParser.php deleted file mode 100644 index a6d748745a4..00000000000 --- a/core/CliMulti/RequestParser.php +++ /dev/null @@ -1,113 +0,0 @@ -supportsAsync = $supportsAsync; - } - - public function getInProgressCommands() - { - $psOutput = $this->getPsOutput(); - - $climultiRequestCommands = $this->getPsLinesWithCliMulti($psOutput); - $climultiRequestCommands = $this->parseQueries($climultiRequestCommands); - - return $climultiRequestCommands; - } - - public function getInProgressArchivingCommands() - { - $commands = $this->getInProgressCommands(); - $commands = $this->filterNonArchivingJobs($commands); - return $commands; - } - - private function getPsOutput() // protected for tests - { - if (!$this->supportsAsync) { - // we cannot detect if web archive is still running - return ''; - } - - return $this->invokePs(); - } - - private function filterNonArchivingJobs($commands) - { - $result = array_filter($commands, function ($command) { - if ( - empty($command['trigger']) - || $command['trigger'] != 'archivephp' - ) { - return false; - } - - return true; - }); - $result = array_values($result); - return $result; - } - - private function getPsLinesWithCliMulti(string $psOutput) - { - $instanceId = SettingsPiwik::getPiwikInstanceId(); - $lines = explode("\n", $psOutput); - $lines = array_map('trim', $lines); - $lines = array_filter($lines, function ($line) use ($instanceId) { - if (!empty($instanceId) && strpos($line, 'matomo-domain=' . $instanceId) === false) { - return false; - } - return strpos($line, 'climulti:request') !== false - && ( - strpos($line, 'console') !== false || strpos($line, 'php') !== false - ); - }); - return $lines; - } - - private function parseQueries(array $climultiRequestCommands) - { - $commandName = 'climulti:request'; - - $result = []; - foreach ($climultiRequestCommands as $command) { - $pos = strpos($command, $commandName); - - $commandParts = substr($command, $pos + strlen($commandName)); - $commandParts = explode(" ", $commandParts); - $commandParts = array_filter($commandParts, function ($p) { - return strlen($p) && substr($p, 0, 1) != '-'; - }); - - $query = reset($commandParts); - parse_str($query, $parsed); - - $result[] = $parsed; - } - return $result; - } - - protected function invokePs() - { - if (defined('PIWIK_TEST_MODE')) { - return ''; // skip check in tests as it might result in random failures - } - - return `ps aux`; - } -} diff --git a/core/CronArchive.php b/core/CronArchive.php index 71f00dae36a..744f7b339a5 100644 --- a/core/CronArchive.php +++ b/core/CronArchive.php @@ -19,7 +19,6 @@ use Piwik\CronArchive\FixedSiteIds; use Piwik\CronArchive\Performance\Logger; use Piwik\Archive\ArchiveInvalidator; -use Piwik\CliMulti\RequestParser; use Piwik\CronArchive\QueueConsumer; use Piwik\CronArchive\SharedSiteIds; use Piwik\CronArchive\StopArchiverException; @@ -221,11 +220,6 @@ class CronArchive */ private $archiveFilter; - /** - * @var RequestParser - */ - private $cliMultiRequestParser; - /** * @var bool|mixed */ @@ -250,7 +244,6 @@ public function __construct(LoggerInterface $logger = null) $this->periodIdsToLabels = array_flip(Piwik::$idPeriods); $this->supportsAsync = $this->makeCliMulti()->supportsAsync(); - $this->cliMultiRequestParser = new RequestParser($this->supportsAsync); $this->archiveFilter = new ArchiveFilter(); } @@ -380,7 +373,6 @@ public function run() $this->model, $this->segmentArchiving, $this, - $this->cliMultiRequestParser, $this->archiveFilter ); diff --git a/core/CronArchive/QueueConsumer.php b/core/CronArchive/QueueConsumer.php index 0ba0c107b4b..914344b2a20 100644 --- a/core/CronArchive/QueueConsumer.php +++ b/core/CronArchive/QueueConsumer.php @@ -12,7 +12,6 @@ use Piwik\ArchiveProcessor\Loader; use Piwik\ArchiveProcessor\Parameters; use Piwik\ArchiveProcessor\Rules; -use Piwik\CliMulti\RequestParser; use Piwik\CronArchive; use Piwik\DataAccess\ArchiveSelector; use Piwik\DataAccess\Model; @@ -78,11 +77,6 @@ class QueueConsumer */ private $periodIdsToLabels; - /** - * @var RequestParser - */ - private $cliMultiRequestParser; - /** * @var int */ @@ -118,7 +112,6 @@ public function __construct( Model $model, SegmentArchiving $segmentArchiving, CronArchive $cronArchive, - RequestParser $cliMultiRequestParser, ArchiveFilter $archiveFilter = null ) { $this->logger = $logger; @@ -128,7 +121,6 @@ public function __construct( $this->model = $model; $this->segmentArchiving = $segmentArchiving; $this->cronArchive = $cronArchive; - $this->cliMultiRequestParser = $cliMultiRequestParser; $this->archiveFilter = $archiveFilter; // if we skip or can't process an idarchive, we want to ignore it the next time we look for an invalidated diff --git a/tests/PHPUnit/Integration/CronArchive/QueueConsumerTest.php b/tests/PHPUnit/Integration/CronArchive/QueueConsumerTest.php index 8cb0719ca5b..179900c372d 100644 --- a/tests/PHPUnit/Integration/CronArchive/QueueConsumerTest.php +++ b/tests/PHPUnit/Integration/CronArchive/QueueConsumerTest.php @@ -10,7 +10,6 @@ namespace Piwik\Tests\Integration\CronArchive; use Piwik\ArchiveProcessor\Rules; -use Piwik\CliMulti\RequestParser; use Piwik\Common; use Piwik\Config; use Piwik\Period\Day; @@ -67,7 +66,6 @@ public function testConsumerIgnoresPeriodsThatHaveBeenDisabledInApi() new Model(), new SegmentArchiving(), $cronArchive, - new RequestParser(true), $archiveFilter ); @@ -166,13 +164,12 @@ public function testInvalidateConsumeOrder() $queueConsumer = new QueueConsumer( StaticContainer::get(LoggerInterface::class), - new FixedSiteIds([1,2,3]), + new FixedSiteIds([1, 2, 3]), 3, 24, new Model(), new SegmentArchiving(), $cronArchive, - new RequestParser(true), $archiveFilter ); @@ -354,13 +351,12 @@ public function testInvalidateConsumeOrder() $queueConsumer = new QueueConsumer( StaticContainer::get(LoggerInterface::class), - new FixedSiteIds([1,2,3]), + new FixedSiteIds([1, 2, 3]), 3, 24, new Model(), new SegmentArchiving(), $cronArchive, - new RequestParser(true), $archiveFilter ); @@ -482,7 +478,6 @@ public function testPluginInvalidationDeletedIfUsableArchiveExists() new Model(), new SegmentArchiving(), $cronArchive, - new RequestParser(true), $archiveFilter ); @@ -563,7 +558,6 @@ public function testSkipSegmentsToday() new Model(), new SegmentArchiving(), $cronArchive, - new RequestParser(true), $archiveFilter ); @@ -679,7 +673,6 @@ public function testMaxWebsitesToProcess() new Model(), new SegmentArchiving(), $cronArchive, - new RequestParser(true), $archiveFilter ); $this->assertNull($queueConsumer->setMaxSitesToProcess()); @@ -822,7 +815,6 @@ public function testCanSkipArchiveBecauseNoPointReturnsTrueIfDateRangeHasNoVisit new Model(), new SegmentArchiving(), $cronArchive, - new RequestParser(true), $archiveFilter ); @@ -851,7 +843,6 @@ public function testCanSkipArchiveBecauseNoPointReturnsFalseIfDateRangeHasVisits new Model(), new SegmentArchiving(), new CronArchive(), - new RequestParser(true), $this->makeTestArchiveFilter() ); @@ -880,7 +871,6 @@ public function testUsableArchiveExistsReturnsTrueIfDateRangeHasVisitsAndPeriodI new Model(), new SegmentArchiving(), new CronArchive(), - new RequestParser(true), $this->makeTestArchiveFilter() ); @@ -916,7 +906,6 @@ public function testUsableArchiveExistsReturnsTrueIfDateRangeHasVisitsAndPeriodI new Model(), new SegmentArchiving(), new CronArchive(), - new RequestParser(true), $this->makeTestArchiveFilter() ); @@ -955,7 +944,6 @@ public function testCanSkipArchiveBecauseNoPointReturnsFalseIfDateRangeHasVisits new Model(), new SegmentArchiving(), new CronArchive(), - new RequestParser(true), $this->makeTestArchiveFilter() ); @@ -991,7 +979,6 @@ public function testCanSkipArchiveBecauseNoPointReturnsTrueSegmentArchivingForPl new Model(), new SegmentArchiving(), new CronArchive(), - new RequestParser(true), $this->makeTestArchiveFilter() ); @@ -1115,10 +1102,9 @@ public function testShouldSkipArchiveBecauseLowerPeriodOrSegmentIsInProgress($ex Rules::setBrowserTriggerArchiving(true); $this->insertInvalidations($existingInvalidations); - $cliRequestProcessor = $this->getMockRequestParser([]); /** @var QueueConsumer $queueConsumer */ - $queueConsumer = $this->getQueueConsumerWithMocks($cliRequestProcessor); + $queueConsumer = $this->getQueueConsumerWithMocks(); $periods = array_flip(Piwik::$idPeriods); @@ -1394,23 +1380,13 @@ private function getMockCronArchive() ->getMock(); } - private function getMockRequestParser($cliMultiProcesses) - { - $mock = $this->getMockBuilder(RequestParser::class) - ->disableOriginalConstructor() - ->onlyMethods(['getInProgressArchivingCommands']) - ->getMock(); - $mock->method('getInProgressArchivingCommands')->willReturn($cliMultiProcesses); - return $mock; - } - - private function getQueueConsumerWithMocks($cliRequestProcessor) + private function getQueueConsumerWithMocks() { $mockCronArchive = $this->getMockBuilder(CronArchive::class) ->disableOriginalConstructor() ->getMock(); - return new QueueConsumer(new NullLogger(), null, null, null, new Model(), new SegmentArchiving(), $mockCronArchive, $cliRequestProcessor); + return new QueueConsumer(new NullLogger(), null, null, null, new Model(), new SegmentArchiving(), $mockCronArchive); } protected static function configureFixture($fixture) diff --git a/tests/PHPUnit/Unit/CliMulti/RequestParserTest.php b/tests/PHPUnit/Unit/CliMulti/RequestParserTest.php deleted file mode 100644 index 7118698f688..00000000000 --- a/tests/PHPUnit/Unit/CliMulti/RequestParserTest.php +++ /dev/null @@ -1,160 +0,0 @@ -getMockRequestParser(true, $psOutput); - - $actual = $requestParser->getInProgressCommands(); - $expected = [ - [ - 'module' => 'API', - 'trigger' => 'archivephp', - 'idSite' => '1', - 'date' => '2015-02-03', - 'period' => 'day', - ], - [ - 'module' => 'API', - 'trigger' => 'archivephp', - 'idSite' => '2', - 'date' => '2015-02-03', - 'period' => 'week', - ], - [ - 'module' => 'Actions', - 'action' => 'doSomething', - ], - [ - 'module' => 'API', - 'trigger' => 'archivephp', - 'idSite' => '2', - 'date' => '2015-03-03', - 'period' => 'week', - ], - [ - 'module' => 'Funnels', - 'trigger' => 'archivephp', - 'idSite' => '2', - 'date' => '2015-02-03', - 'period' => 'week', - ], - ]; - - $this->assertEquals($expected, $actual); - } - - public function testGetInProgressCommandsReturnsNothingIfNotSupportingAsync() - { - $psOutput = <<getMockRequestParser(false, $psOutput); - - $actual = $requestParser->getInProgressCommands(); - $expected = []; - - $this->assertEquals($expected, $actual); - } - - public function testGetInProgressArchivingCommandsReturnsOnlyArchivingJobs() - { - $psOutput = <<getMockRequestParser(true, $psOutput); - - $actual = $requestParser->getInProgressArchivingCommands(); - $expected = [ - [ - 'module' => 'API', - 'trigger' => 'archivephp', - 'idSite' => '1', - 'date' => '2015-02-03', - 'period' => 'day', - ], - [ - 'module' => 'API', - 'trigger' => 'archivephp', - 'idSite' => '2', - 'date' => '2015-02-03', - 'period' => 'week', - ], - [ - 'module' => 'API', - 'trigger' => 'archivephp', - 'idSite' => '2', - 'date' => '2015-03-03', - 'period' => 'week', - ], - ]; - - $this->assertEquals($expected, $actual); - } - - private function getMockRequestParser($supportsAsync, $psOutput) - { - $mock = new class ($supportsAsync, $psOutput) extends RequestParser { - public $psOutput; - - public function __construct($supportsAsync, $psOutput) - { - parent::__construct($supportsAsync); - $this->psOutput = $psOutput; - } - - protected function invokePs() - { - return $this->psOutput; - } - }; - return $mock; - } -}