Skip to content

Commit 0b41085

Browse files
authored
Merge pull request #8464 from magento-gl/GL_PR_Arrows_August_07_2023
Arrows Team - Bugfix delivery
2 parents 14c1547 + 724d2ab commit 0b41085

File tree

3 files changed

+110
-7
lines changed

3 files changed

+110
-7
lines changed

dev/tests/api-functional/framework/Magento/TestFramework/WebApiApplication.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ public function install($cleanup)
5050
}
5151
$this->_shell->execute($installCmd, $installArgs);
5252
}
53+
/* Set Indexer mode as "Update on Save" & Reindex all the Indexers */
54+
$this->_shell->execute(
55+
'php -f ' . BP . '/bin/magento indexer:set-mode realtime -vvv'
56+
);
57+
$this->_shell->execute(
58+
'php -f ' . BP . '/bin/magento indexer:reindex -vvv'
59+
);
5360

5461
$this->runPostInstallCommands();
5562
}

setup/src/Magento/Setup/Model/Installer.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
use Magento\Framework\Exception\LocalizedException;
2828
use Magento\Framework\Exception\RuntimeException;
2929
use Magento\Framework\Filesystem;
30+
use Magento\Framework\Indexer\IndexerInterface;
31+
use Magento\Framework\Indexer\IndexerRegistry;
3032
use Magento\Framework\Model\ResourceModel\Db\Context;
3133
use Magento\Framework\Module\ModuleList\Loader as ModuleLoader;
3234
use Magento\Framework\Module\ModuleListInterface;
@@ -46,6 +48,7 @@
4648
use Magento\Framework\Setup\UpgradeDataInterface;
4749
use Magento\Framework\Setup\UpgradeSchemaInterface;
4850
use Magento\Framework\Validation\ValidationException;
51+
use Magento\Indexer\Model\Indexer\Collection;
4952
use Magento\PageCache\Model\Cache\Type as PageCache;
5053
use Magento\RemoteStorage\Driver\DriverException;
5154
use Magento\Setup\Console\Command\InstallCommand;
@@ -337,6 +340,8 @@ public function __construct(
337340
* @throws FileSystemException
338341
* @throws LocalizedException
339342
* @throws RuntimeException
343+
* @SuppressWarnings(PHPMD.NPathComplexity)
344+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
340345
*/
341346
public function install($request)
342347
{
@@ -374,6 +379,9 @@ public function install($request)
374379
$script[] = ['Disabling Maintenance Mode:', 'setMaintenanceMode', [0]];
375380
$script[] = ['Post installation file permissions check...', 'checkApplicationFilePermissions', []];
376381
$script[] = ['Write installation date...', 'writeInstallationDate', []];
382+
if (empty($request['magento-init-params'])) {
383+
$script[] = ['Enabling Update by Schedule Indexer Mode...', 'setIndexerModeSchedule', []];
384+
}
377385
$estimatedModules = $this->createModulesConfig($request, true);
378386
$total = count($script) + 4 * count(array_filter($estimatedModules));
379387
$this->progress = new Installer\Progress($total, 0);
@@ -1838,4 +1846,32 @@ private function revertRemoteStorageConfiguration()
18381846
$configData = [$remoteStorageData->getFileKey() => $remoteStorageData->getData()];
18391847
$this->deploymentConfigWriter->saveConfig($configData, true);
18401848
}
1849+
1850+
/**
1851+
* Set Index mode as 'Update by Schedule'
1852+
*
1853+
* @return void
1854+
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) Called by install() via callback.
1855+
* @throws LocalizedException
1856+
* @throws \Exception
1857+
*/
1858+
private function setIndexerModeSchedule(): void
1859+
{
1860+
/** @var Collection $indexCollection */
1861+
$indexCollection = $this->objectManagerProvider->get()->get(Collection::class);
1862+
$indexerIds = $indexCollection->getAllIds();
1863+
try {
1864+
foreach ($indexerIds as $indexerId) {
1865+
/** @var IndexerInterface $model */
1866+
$model = $this->objectManagerProvider->get()->get(IndexerRegistry::class)
1867+
->get($indexerId);
1868+
$model->setScheduled(true);
1869+
}
1870+
$this->log->log(__('%1 indexer(s) are in "Update by Schedule" mode.', count($indexerIds)));
1871+
} catch (LocalizedException $e) {
1872+
$this->log->log($e->getMessage());
1873+
} catch (\Exception $e) {
1874+
$this->log->log(__("We couldn't change indexer(s)' mode because of an error: ".$e->getMessage()));
1875+
}
1876+
}
18411877
}

setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
use Magento\Framework\Filesystem;
3030
use Magento\Framework\Filesystem\Directory\WriteInterface;
3131
use Magento\Framework\Filesystem\DriverPool;
32+
use Magento\Framework\Indexer\IndexerInterface;
33+
use Magento\Framework\Indexer\IndexerRegistry;
3234
use Magento\Framework\Model\ResourceModel\Db\Context;
3335
use Magento\Framework\Module\ModuleList\Loader;
3436
use Magento\Framework\Module\ModuleListInterface;
@@ -42,6 +44,7 @@
4244
use Magento\Framework\Setup\SampleData\State;
4345
use Magento\Framework\Setup\SchemaListener;
4446
use Magento\Framework\Validation\ValidationException;
47+
use Magento\Indexer\Model\Indexer\Collection;
4548
use Magento\RemoteStorage\Driver\DriverException;
4649
use Magento\RemoteStorage\Setup\ConfigOptionsList as RemoteStorageValidator;
4750
use Magento\Setup\Console\Command\InstallCommand;
@@ -224,6 +227,19 @@ class InstallerTest extends TestCase
224227
*/
225228
private $patchApplierFactoryMock;
226229

230+
/**
231+
* @var Collection|MockObject
232+
*/
233+
private $indexerMock;
234+
/**
235+
* @var IndexerRegistry|MockObject
236+
*/
237+
private $indexerRegistryMock;
238+
/**
239+
* @var IndexerInterface|MockObject
240+
*/
241+
private $indexerInterfaceMock;
242+
227243
/**
228244
* @inheritdoc
229245
*/
@@ -263,6 +279,10 @@ protected function setUp(): void
263279
$this->patchApplierFactoryMock->expects($this->any())->method('create')->willReturn(
264280
$this->patchApplierMock
265281
);
282+
$this->indexerMock = $this->createMock(Collection::class);
283+
$this->indexerRegistryMock = $this->createMock(IndexerRegistry::class);
284+
$this->indexerInterfaceMock = $this->getMockForAbstractClass(IndexerInterface::class);
285+
266286
$this->object = $this->createObject();
267287
}
268288

@@ -429,7 +449,9 @@ public function testInstall(array $request, array $logMessages)
429449
[DeclarationInstaller::class, $this->declarationInstallerMock],
430450
[Registry::class, $registry],
431451
[SearchConfig::class, $searchConfigMock],
432-
[RemoteStorageValidator::class, $remoteStorageValidatorMock]
452+
[RemoteStorageValidator::class, $remoteStorageValidatorMock],
453+
[Collection::class, $this->indexerMock],
454+
[IndexerRegistry::class, $this->indexerRegistryMock]
433455
]
434456
);
435457
$this->adminFactory->expects($this->any())->method('create')->willReturn(
@@ -445,6 +467,15 @@ public function testInstall(array $request, array $logMessages)
445467
$this->filePermissions->expects($this->once())
446468
->method('getMissingWritableDirectoriesForDbUpgrade')
447469
->willReturn([]);
470+
$this->indexerMock->expects($this->once())->method('getAllIds')->willReturn(
471+
[
472+
'catalog_category_product',
473+
'catalog_product_category',
474+
]
475+
);
476+
$this->indexerRegistryMock->expects($this->exactly(2))->method('get')->willReturn(
477+
$this->indexerInterfaceMock
478+
);
448479
call_user_func_array(
449480
[
450481
$this->logger->expects($this->exactly(count($logMessages)))->method('log'),
@@ -507,6 +538,8 @@ public function installDataProvider()
507538
['Disabling Maintenance Mode:'],
508539
['Post installation file permissions check...'],
509540
['Write installation date...'],
541+
['Enabling Update by Schedule Indexer Mode...'],
542+
['2 indexer(s) are in "Update by Schedule" mode.'],
510543
['Sample Data is installed with errors. See log file for details']
511544
],
512545
],
@@ -560,6 +593,8 @@ public function installDataProvider()
560593
['Disabling Maintenance Mode:'],
561594
['Post installation file permissions check...'],
562595
['Write installation date...'],
596+
['Enabling Update by Schedule Indexer Mode...'],
597+
['2 indexer(s) are in "Update by Schedule" mode.'],
563598
['Sample Data is installed with errors. See log file for details']
564599
],
565600
],
@@ -698,9 +733,20 @@ public function testInstallWithOrderIncrementPrefix(array $request, array $logMe
698733
[DeclarationInstaller::class, $this->declarationInstallerMock],
699734
[Registry::class, $registry],
700735
[SearchConfig::class, $searchConfigMock],
701-
[RemoteStorageValidator::class, $remoteStorageValidatorMock]
736+
[RemoteStorageValidator::class, $remoteStorageValidatorMock],
737+
[Collection::class, $this->indexerMock],
738+
[IndexerRegistry::class, $this->indexerRegistryMock]
702739
]
703740
);
741+
$this->indexerMock->expects($this->once())->method('getAllIds')->willReturn(
742+
[
743+
'catalog_category_product',
744+
'catalog_product_category',
745+
]
746+
);
747+
$this->indexerRegistryMock->expects($this->exactly(2))->method('get')->willReturn(
748+
$this->indexerInterfaceMock
749+
);
704750
$this->adminFactory->expects($this->any())->method('create')->willReturn(
705751
$this->createMock(AdminAccount::class)
706752
);
@@ -784,6 +830,8 @@ public function installWithOrderIncrementPrefixDataProvider(): array
784830
['Disabling Maintenance Mode:'],
785831
['Post installation file permissions check...'],
786832
['Write installation date...'],
833+
['Enabling Update by Schedule Indexer Mode...'],
834+
['2 indexer(s) are in "Update by Schedule" mode.'],
787835
['Sample Data is installed with errors. See log file for details']
788836
],
789837
],
@@ -1103,14 +1151,17 @@ public function testInstallWithUnresolvableRemoteStorageValidator()
11031151
$objectManagerReturnMapSequence = [
11041152
0 => [Registry::class, $registry],
11051153
1 => [DeclarationInstaller::class, $this->declarationInstallerMock],
1106-
3 => [SearchConfig::class, $searchConfigMock],
1107-
4 => [
1154+
2 => [SearchConfig::class, $searchConfigMock],
1155+
3 => [
11081156
RemoteStorageValidator::class,
11091157
new ReflectionException('Class ' . RemoteStorageValidator::class . ' does not exist')
11101158
],
1111-
5 => [\Magento\Framework\App\State::class, $appState],
1112-
7 => [Registry::class, $registry],
1113-
11 => [Manager::class, $cacheManager]
1159+
4 => [\Magento\Framework\App\State::class, $appState],
1160+
5 => [Registry::class, $registry],
1161+
6 => [Manager::class, $cacheManager],
1162+
7 => [Collection::class, $this->indexerMock],
1163+
8 => [IndexerRegistry::class, $this->indexerRegistryMock],
1164+
9 => [IndexerRegistry::class, $this->indexerRegistryMock]
11141165
];
11151166
$withArgs = $willReturnArgs = [];
11161167

@@ -1130,6 +1181,15 @@ public function testInstallWithUnresolvableRemoteStorageValidator()
11301181
->withConsecutive(...$withArgs)
11311182
->willReturnOnConsecutiveCalls(...$willReturnArgs);
11321183

1184+
$this->indexerMock->expects($this->once())->method('getAllIds')->willReturn(
1185+
[
1186+
'catalog_category_product',
1187+
'catalog_product_category',
1188+
]
1189+
);
1190+
$this->indexerRegistryMock->expects($this->exactly(2))->method('get')->willReturn(
1191+
$this->indexerInterfaceMock
1192+
);
11331193
$this->adminFactory->expects(static::any())->method('create')->willReturn(
11341194
$this->createMock(AdminAccount::class)
11351195
);

0 commit comments

Comments
 (0)