Skip to content

Commit c2ea86f

Browse files
authored
Merge branch '2.4-develop' into comm_78764_32435
2 parents c684fb9 + ed0acf9 commit c2ea86f

File tree

6 files changed

+385
-1
lines changed

6 files changed

+385
-1
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ protected function _prepareMultiselectIndex($entityIds = null, $attributeId = nu
343343
$this->_addAttributeToSelect($select, 'status', "pvd.{$productIdField}", 'cs.store_id', $statusCond);
344344

345345
if ($entityIds !== null) {
346-
$select->where('cpe.entity_id IN(?)', $entityIds);
346+
$select->where('cpe.entity_id IN(?)', $entityIds, \Zend_Db::INT_TYPE);
347347
}
348348
/**
349349
* Add additional external limitation
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MessageQueue\Console;
9+
10+
use Magento\Framework\Console\Cli;
11+
use Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface;
12+
use Symfony\Component\Console\Command\Command;
13+
use Symfony\Component\Console\Input\InputInterface;
14+
use Symfony\Component\Console\Output\OutputInterface;
15+
16+
/**
17+
* Command for put poison pill for MessageQueue consumers.
18+
*/
19+
class RestartConsumerCommand extends Command
20+
{
21+
private const COMMAND_QUEUE_CONSUMERS_RESTART = 'queue:consumers:restart';
22+
23+
/**
24+
* @var PoisonPillPutInterface
25+
*/
26+
private $poisonPillPut;
27+
28+
/**
29+
* @param PoisonPillPutInterface $poisonPillPut
30+
* @param string|null $name
31+
*/
32+
public function __construct(PoisonPillPutInterface $poisonPillPut, $name = null)
33+
{
34+
parent::__construct($name);
35+
$this->poisonPillPut = $poisonPillPut;
36+
}
37+
38+
/**
39+
* @inheritdoc
40+
*/
41+
protected function execute(InputInterface $input, OutputInterface $output)
42+
{
43+
$this->poisonPillPut->put();
44+
return Cli::RETURN_SUCCESS;
45+
}
46+
47+
/**
48+
* @inheritdoc
49+
*/
50+
protected function configure()
51+
{
52+
$this->setName(self::COMMAND_QUEUE_CONSUMERS_RESTART);
53+
$this->setDescription('Restart MessageQueue consumers');
54+
$this->setHelp(
55+
<<<HELP
56+
Command put poison pill for MessageQueue consumers and force to restart them after next status check.
57+
HELP
58+
);
59+
parent::configure();
60+
}
61+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MessageQueue\Setup;
9+
10+
use Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface;
11+
use Magento\Framework\Setup\InstallSchemaInterface;
12+
use Magento\Framework\Setup\ModuleContextInterface;
13+
use Magento\Framework\Setup\SchemaSetupInterface;
14+
15+
/**
16+
* Put the poison pill after each potential deployment.
17+
*/
18+
class Recurring implements InstallSchemaInterface
19+
{
20+
/**
21+
* @var PoisonPillPutInterface
22+
*/
23+
private $poisonPillPut;
24+
25+
/**
26+
* @param PoisonPillPutInterface $poisonPillPut
27+
*/
28+
public function __construct(PoisonPillPutInterface $poisonPillPut)
29+
{
30+
$this->poisonPillPut = $poisonPillPut;
31+
}
32+
33+
/**
34+
* Put the Poison Pill after each 'setup:upgrade' command run.
35+
*
36+
* @param SchemaSetupInterface $setup
37+
* @param ModuleContextInterface $context
38+
*
39+
* @throws \Exception
40+
*
41+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
42+
*/
43+
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
44+
{
45+
$this->poisonPillPut->put();
46+
}
47+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MessageQueue\Test\Integration;
9+
10+
use Magento\Framework\MessageQueue\PoisonPill\PoisonPillCompareInterface;
11+
use Magento\Framework\MessageQueue\PoisonPill\PoisonPillReadInterface;
12+
use Magento\MessageQueue\Console\RestartConsumerCommand;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Console\Tester\CommandTester;
16+
17+
class PoisonPillApplyAfterCommandRunTest extends TestCase
18+
{
19+
/**
20+
* @var PoisonPillReadInterface
21+
*/
22+
private $poisonPillRead;
23+
24+
/**
25+
* @var PoisonPillCompareInterface
26+
*/
27+
private $poisonPillCompare;
28+
29+
/**
30+
* @var RestartConsumerCommand
31+
*/
32+
private $restartConsumerCommand;
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
protected function setUp(): void
38+
{
39+
$objectManager = Bootstrap::getObjectManager();
40+
$this->poisonPillRead = $objectManager->get(PoisonPillReadInterface::class);
41+
$this->poisonPillCompare = $objectManager->get(PoisonPillCompareInterface::class);
42+
$this->restartConsumerCommand = $objectManager->create(RestartConsumerCommand::class);
43+
}
44+
45+
/**
46+
* @covers \Magento\MessageQueue\Setup\Recurring
47+
*
48+
* @magentoDbIsolation enabled
49+
*/
50+
public function testChangeVersion(): void
51+
{
52+
$version = $this->poisonPillRead->getLatestVersion();
53+
$this->runTestRestartConsumerCommand();
54+
$this->assertEquals(false, $this->poisonPillCompare->isLatestVersion($version));
55+
}
56+
57+
/**
58+
* @return void
59+
*/
60+
private function runTestRestartConsumerCommand(): void
61+
{
62+
$commandTester = new CommandTester($this->restartConsumerCommand);
63+
$commandTester->execute([]);
64+
}
65+
}
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MessageQueue\Test\Unit\Console;
9+
10+
use Magento\Framework\App\DeploymentConfig;
11+
use Magento\Framework\DB\Adapter\AdapterInterface;
12+
use Magento\Framework\MessageQueue\PoisonPill\PoisonPillPutInterface;
13+
use Magento\Framework\Module\ModuleListInterface;
14+
use Magento\Framework\Mview\TriggerCleaner;
15+
use Magento\Framework\Registry;
16+
use Magento\Framework\Setup\ModuleContextInterface;
17+
use Magento\Framework\Setup\Patch\PatchApplier;
18+
use Magento\Framework\Setup\Patch\PatchApplierFactory;
19+
use Magento\Framework\Setup\SchemaListener;
20+
use Magento\Framework\Setup\SchemaPersistor;
21+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
22+
use Magento\MessageQueue\Setup\Recurring;
23+
use Magento\Setup\Model\DeclarationInstaller;
24+
use Magento\Setup\Model\Installer;
25+
use Magento\Setup\Model\ObjectManagerProvider;
26+
use Magento\Setup\Module\SetupFactory;
27+
use PHPUnit\Framework\MockObject\MockObject;
28+
use PHPUnit\Framework\TestCase;
29+
30+
/**
31+
* @SuppressWarnings(PHPMD.TooManyFields)
32+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
33+
*/
34+
class PoisonPillApplyDuringSetupUpgradeTest extends TestCase
35+
{
36+
/**
37+
* @var Installer
38+
*/
39+
private $installer;
40+
/**
41+
* @var object
42+
*/
43+
private $objectManagerProvider;
44+
/**
45+
* @var \Magento\Framework\ObjectManager\ObjectManager|MockObject
46+
*/
47+
private $objectManagerMock;
48+
/**
49+
* @var object
50+
*/
51+
private $registry;
52+
/**
53+
* @var MockObject
54+
*/
55+
private $deploymentConfig;
56+
/**
57+
* @var ModuleContextInterface|mixed|MockObject
58+
*/
59+
private $schemaSetupInterface;
60+
/**
61+
* @var SetupFactory|mixed|MockObject
62+
*/
63+
private $setupFactory;
64+
/**
65+
* @var AdapterInterface|mixed|MockObject
66+
*/
67+
private $adapterInterface;
68+
/**
69+
* @var object
70+
*/
71+
private $resourceConnection;
72+
/**
73+
* @var object
74+
*/
75+
private $declarationInstaller;
76+
/**
77+
* @var object
78+
*/
79+
private $schemaPersistor;
80+
/**
81+
* @var object
82+
*/
83+
private $triggerCleaner;
84+
/**
85+
* @var object
86+
*/
87+
private $moduleListInterface;
88+
/**
89+
* @var object
90+
*/
91+
private $schemaListener;
92+
/**
93+
* @var object
94+
*/
95+
private $patchApplierFactory;
96+
/**
97+
* @var object
98+
*/
99+
private $patchApplier;
100+
/**
101+
* @var object
102+
*/
103+
private $recurring;
104+
/**
105+
* @var PoisonPillPutInterface|MockObject
106+
*/
107+
private $poisonPillPut;
108+
109+
/**
110+
* @inheritdoc
111+
*/
112+
protected function setUp(): void
113+
{
114+
$objectManager = new ObjectManager($this);
115+
$this->registry = $objectManager->getObject(Registry::class);
116+
$this->moduleListInterface = $this->createMock(ModuleListInterface::class);
117+
$this->moduleListInterface->method('getNames')->willReturn(['Magento_MessageQueue']);
118+
$this->moduleListInterface->method('getOne')->with('Magento_MessageQueue')->willReturn(['setup_version'=>'']);
119+
$this->declarationInstaller = $this->createMock(DeclarationInstaller::class);
120+
$this->declarationInstaller->method('installSchema')->willReturn(true);
121+
$this->schemaListener = $this->createMock(SchemaListener::class);
122+
$this->schemaPersistor = $objectManager->getObject(SchemaPersistor::class);
123+
$this->triggerCleaner = $objectManager->getObject(TriggerCleaner::class);
124+
$this->patchApplierFactory = $this->createMock(PatchApplierFactory::class);
125+
$this->patchApplier = $this->createMock(PatchApplier::class);
126+
$this->patchApplier->method('applySchemaPatch')->willReturn(true);
127+
$this->patchApplierFactory->method('create')->willReturn($this->patchApplier);
128+
$this->objectManagerProvider = $this->createMock(ObjectManagerProvider::class);
129+
$this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManager\ObjectManager::class);
130+
$this->deploymentConfig = $this->createMock(DeploymentConfig::class);
131+
$this->deploymentConfig->method('get')->willReturn(['host'=>'localhost', 'dbname' => 'magento']);
132+
$this->objectManagerMock->method('get')->withConsecutive(
133+
[SchemaPersistor::class],
134+
[TriggerCleaner::class],
135+
[Registry::class],
136+
[DeclarationInstaller::class],
137+
)->willReturnOnConsecutiveCalls(
138+
$this->schemaPersistor,
139+
$this->triggerCleaner,
140+
$this->registry,
141+
$this->declarationInstaller,
142+
);
143+
$this->poisonPillPut = $this->createMock(\Magento\MessageQueue\Model\ResourceModel\PoisonPill::class);
144+
$this->recurring = new Recurring($this->poisonPillPut);
145+
146+
$this->objectManagerMock->method('create')->withConsecutive(
147+
[PatchApplierFactory::class],
148+
[Recurring::class],
149+
)->willReturnOnConsecutiveCalls(
150+
$this->patchApplierFactory,
151+
$this->recurring,
152+
);
153+
$this->objectManagerProvider->method('get')->willReturn($this->objectManagerMock);
154+
$this->adapterInterface = $this->createMock(\Magento\Framework\DB\Adapter\Pdo\Mysql::class);
155+
$this->adapterInterface->method('isTableExists')->willReturn(true);
156+
$this->adapterInterface->method('getTables')->willReturn([]);
157+
$this->adapterInterface->method('getSchemaListener')->willReturn($this->schemaListener);
158+
$this->adapterInterface->method('describeTable')->willReturn(['flag_data'=>['DATA_TYPE'=>'mediumtext']]);
159+
$this->resourceConnection = $objectManager->getObject(\Magento\Framework\App\ResourceConnection::class);
160+
$this->schemaSetupInterface = $this->createMock(\Magento\Framework\Setup\SchemaSetupInterface::class);
161+
$this->schemaSetupInterface->method('getConnection')->willReturn($this->adapterInterface);
162+
$this->schemaSetupInterface
163+
->method('getTable')
164+
->withConsecutive(
165+
['setup_module'],
166+
['session'],
167+
['cache'],
168+
['cache_tag'],
169+
['flag']
170+
)->willReturnOnConsecutiveCalls(
171+
'setup_module',
172+
'session',
173+
'cache',
174+
'cache_tag',
175+
'flag'
176+
);
177+
$this->setupFactory = $this->createMock(SetupFactory::class);
178+
$this->setupFactory->method('create')->willReturn($this->schemaSetupInterface);
179+
$this->installer = $objectManager->getObject(
180+
Installer::class,
181+
[
182+
'objectManagerProvider' => $this->objectManagerProvider,
183+
'deploymentConfig'=>$this->deploymentConfig,
184+
'setupFactory'=>$this->setupFactory,
185+
'moduleList'=>$this->moduleListInterface,
186+
]
187+
);
188+
}
189+
190+
/**
191+
* @covers \Magento\MessageQueue\Setup\Recurring
192+
*/
193+
public function testChangeVersion(): void
194+
{
195+
$this->poisonPillPut->expects(self::once())->method('put');
196+
$this->installer->installSchema(
197+
[
198+
'keep-generated'=>false,
199+
'convert-old-scripts'=>false,
200+
'help'=>false,
201+
'quiet'=>false,
202+
'verbose'=>false,
203+
'version'=>false,
204+
'ansi'=>false,
205+
'no-ansi'=>false,
206+
'no-interaction'=>false,
207+
]
208+
);
209+
}
210+
}

0 commit comments

Comments
 (0)