diff --git a/lib/internal/Magento/Framework/Setup/Queue/UpToDateQueue.php b/lib/internal/Magento/Framework/Setup/Queue/UpToDateQueue.php new file mode 100644 index 0000000000000..6573160149d62 --- /dev/null +++ b/lib/internal/Magento/Framework/Setup/Queue/UpToDateQueue.php @@ -0,0 +1,119 @@ +getQueueFromDatabase(); + $queueFromXml = $this->getQueueFromXml(); + + return $this->queuesMatch($existingQueues, $queueFromXml); + } + + private function queuesMatch(array $existingQueues, array $queueFromXml): bool + { + if (count($existingQueues) !== count($queueFromXml)) { + return false; + } + + sort($existingQueues); + sort($queueFromXml); + + return $existingQueues === $queueFromXml; + } + + private function getQueueFromDatabase(): array + { + $connection = $this->resourceConnection->getConnection(); + $tableName = $connection->getTableName('queue'); + $select = $connection->select()->distinct()->from($tableName, ['name']); + return $connection->fetchCol($select); + } + + private function getQueueFromXml(): array + { + $queues = []; + + foreach ($this->moduleList->getAll() as $moduleName) { + $modulePath = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName['name']); + + if (!$modulePath) { + continue; + } + + $queueFile = $modulePath . '/etc/queue_consumer.xml'; + + if (!$this->fileDriver->isExists($queueFile)) { + continue; + } + + try { + $xmlContent = $this->fileDriver->fileGetContents($queueFile); + $parsedXml = $this->xmlParser->loadXML($xmlContent)->xmlToArray(); + + if (isset($parsedXml['config']['_value']['consumer'])) { + $consumers = $parsedXml['config']['_value']['consumer']; + + foreach ($consumers as $item) { + if (isset($item['_attribute']['queue'])) { + $queues[] = $item['_attribute']['queue']; + } else { + if (isset($item['queue'])) { + $queues[] = $item['queue']; + } + } + } + } + } catch (\Exception $e) { + $this->logger->error($e->getMessage()); + continue; + } + } + return array_unique($queues); + } +} diff --git a/setup/src/Magento/Setup/Console/Command/DbStatusCommand.php b/setup/src/Magento/Setup/Console/Command/DbStatusCommand.php index f5b9055dcfead..605b4f82f2fe1 100644 --- a/setup/src/Magento/Setup/Console/Command/DbStatusCommand.php +++ b/setup/src/Magento/Setup/Console/Command/DbStatusCommand.php @@ -11,6 +11,7 @@ use Magento\Framework\Setup\OldDbValidator; use Magento\Framework\Setup\Patch\UpToDateData; use Magento\Framework\Setup\Patch\UpToDateSchema; +use Magento\Framework\Setup\Queue\UpToDateQueue; use Magento\Framework\Setup\UpToDateValidatorInterface; use Magento\Setup\Model\ObjectManagerProvider; use Symfony\Component\Console\Input\InputInterface; @@ -63,6 +64,7 @@ public function __construct(ObjectManagerProvider $objectManagerProvider, Deploy $this->objectManagerProvider->get()->get(UpToDateSchema::class), $this->objectManagerProvider->get()->get(UpToDateData::class), $this->objectManagerProvider->get()->get(OldDbValidator::class), + $this->objectManagerProvider->get()->get(UpToDateQueue::class), ]; parent::__construct(); } diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/DbStatusCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/DbStatusCommandTest.php index 9031714e08b43..c41c008344b42 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/DbStatusCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/DbStatusCommandTest.php @@ -69,18 +69,21 @@ protected function setUp(): void ->getMock(), 'old_validator' => $this->getMockBuilder(UpToDateValidatorInterface::class) ->getMock(), + 'up_to_date_queue' => $this->getMockBuilder(UpToDateValidatorInterface::class) + ->getMock(), ]; $objectManagerProvider->expects($this->any()) ->method('get') ->willReturn($objectManager); - $objectManager->expects(self::exactly(4)) + $objectManager->expects(self::exactly(5)) ->method('get') ->willReturnOnConsecutiveCalls( $this->validators['declarative_schema'], $this->validators['up_to_date_schema'], $this->validators['up_to_date_data'], - $this->validators['old_validator'] + $this->validators['old_validator'], + $this->validators['up_to_date_queue'] ); $this->command = new DbStatusCommand($objectManagerProvider, $this->deploymentConfig); } @@ -99,6 +102,9 @@ public function testExecute() $this->validators['declarative_schema']->expects(self::once()) ->method('isUpToDate') ->willReturn(true); + $this->validators['up_to_date_queue']->expects(self::once()) + ->method('isUpToDate') + ->willReturn(true); $this->deploymentConfig->expects($this->once()) ->method('isAvailable') ->willReturn(true);