Skip to content

Commit 0eb623e

Browse files
committed
Merge remote-tracking branch '38123/no-cache-disable-enable' into bt_comm_pr_247beta3
2 parents d8b5392 + 9627fa1 commit 0eb623e

File tree

2 files changed

+25
-132
lines changed

2 files changed

+25
-132
lines changed

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

Lines changed: 14 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88

99
use Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList;
1010
use Magento\Framework\App\Cache\Manager;
11-
use Magento\Framework\App\Cache\Manager as CacheManager;
12-
use Magento\Framework\App\Cache\Type\Block as BlockCache;
1311
use Magento\Framework\App\Cache\Type\Config as ConfigCache;
14-
use Magento\Framework\App\Cache\Type\Layout as LayoutCache;
1512
use Magento\Framework\App\DeploymentConfig;
1613
use Magento\Framework\App\DeploymentConfig\Reader;
1714
use Magento\Framework\App\DeploymentConfig\Writer;
@@ -51,7 +48,6 @@
5148
use Magento\Framework\Setup\UpgradeSchemaInterface;
5249
use Magento\Framework\Validation\ValidationException;
5350
use Magento\Indexer\Model\Indexer\Collection;
54-
use Magento\PageCache\Model\Cache\Type as PageCache;
5551
use Magento\RemoteStorage\Driver\DriverException;
5652
use Magento\Setup\Console\Command\InstallCommand;
5753
use Magento\Setup\Controller\ResponseTypeInterface;
@@ -372,7 +368,7 @@ public function install($request)
372368
[$request]
373369
];
374370
$script[] = ['Installing user configuration...', 'installUserConfig', [$request]];
375-
$script[] = ['Enabling caches:', 'updateCaches', [true]];
371+
$script[] = ['Enabling caches:', 'enableCaches', [true]];
376372
$script[] = ['Installing data...', 'installDataFixtures', [$request]];
377373
if (!empty($request[InstallCommand::INPUT_KEY_SALES_ORDER_INCREMENT_PREFIX])) {
378374
$script[] = [
@@ -947,25 +943,14 @@ private function convertationOfOldScriptsIsAllowed(array $request)
947943
* Installs data fixtures
948944
*
949945
* @param array $request
950-
* @param boolean $keepCacheStatuses
946+
*
951947
* @return void
948+
*
952949
* @throws Exception
953950
* @throws \Magento\Framework\Setup\Exception
954951
*/
955-
public function installDataFixtures(array $request = [], $keepCacheStatuses = false)
952+
public function installDataFixtures(array $request = [])
956953
{
957-
$frontendCaches = [
958-
PageCache::TYPE_IDENTIFIER,
959-
BlockCache::TYPE_IDENTIFIER,
960-
LayoutCache::TYPE_IDENTIFIER,
961-
];
962-
963-
if ($keepCacheStatuses) {
964-
$disabledCaches = $this->getDisabledCacheTypes($frontendCaches);
965-
966-
$frontendCaches = array_diff($frontendCaches, $disabledCaches);
967-
}
968-
969954
/** @var \Magento\Framework\Registry $registry */
970955
$registry = $this->objectManagerProvider->get()->get(\Magento\Framework\Registry::class);
971956
//For backward compatibility in install and upgrade scripts with enabled parallelization.
@@ -977,19 +962,7 @@ public function installDataFixtures(array $request = [], $keepCacheStatuses = fa
977962
$this->checkFilePermissionsForDbUpgrade();
978963
$this->log->log('Data install/update:');
979964

980-
if ($frontendCaches) {
981-
$this->log->log('Disabling caches:');
982-
$this->updateCaches(false, $frontendCaches);
983-
}
984-
985-
try {
986-
$this->handleDBSchemaData($setup, 'data', $request);
987-
} finally {
988-
if ($frontendCaches) {
989-
$this->log->log('Enabling caches:');
990-
$this->updateCaches(true, $frontendCaches);
991-
}
992-
}
965+
$this->handleDBSchemaData($setup, 'data', $request);
993966

994967
$registry->unregister('setup-mode-enabled');
995968
}
@@ -1442,39 +1415,27 @@ public function uninstall()
14421415
}
14431416

14441417
/**
1445-
* Enable or disable caches for specific types that are available
1418+
* Enable caches for after installing application
14461419
*
1447-
* If no types are specified then it will enable or disable all available types
14481420
* Note this is called by install() via callback.
14491421
*
1450-
* @param bool $isEnabled
1451-
* @param array $types
1422+
* @SuppressWarnings(PHPMD.UnusedPrivateMethod)
1423+
*
14521424
* @return void
1425+
*
14531426
* @throws Exception
14541427
*/
1455-
private function updateCaches($isEnabled, $types = [])
1428+
private function enableCaches()
14561429
{
14571430
/** @var Manager $cacheManager */
14581431
$cacheManager = $this->objectManagerProvider->get()->create(Manager::class);
14591432

1460-
$availableTypes = $cacheManager->getAvailableTypes();
1461-
$types = empty($types) ? $availableTypes : array_intersect($availableTypes, $types);
1462-
$enabledTypes = $cacheManager->setEnabled($types, $isEnabled);
1463-
if ($isEnabled) {
1464-
$cacheManager->clean($enabledTypes);
1465-
}
1466-
1467-
// Only get statuses of specific cache types
1468-
$cacheStatus = array_filter(
1469-
$cacheManager->getStatus(),
1470-
function (string $key) use ($types) {
1471-
return in_array($key, $types);
1472-
},
1473-
ARRAY_FILTER_USE_KEY
1474-
);
1433+
$types = $cacheManager->getAvailableTypes();
1434+
$enabledTypes = $cacheManager->setEnabled($types, true);
1435+
$cacheManager->clean($enabledTypes);
14751436

14761437
$this->log->log('Current status:');
1477-
foreach ($cacheStatus as $cache => $status) {
1438+
foreach ($cacheManager->getStatus() as $cache => $status) {
14781439
$this->log->log(sprintf('%s: %d', $cache, $status));
14791440
}
14801441
}
@@ -1824,29 +1785,6 @@ public function removeUnusedTriggers(): void
18241785
$this->cleanCaches();
18251786
}
18261787

1827-
/**
1828-
* Returns list of disabled cache types
1829-
*
1830-
* @param array $cacheTypesToCheck
1831-
* @return array
1832-
*/
1833-
private function getDisabledCacheTypes(array $cacheTypesToCheck): array
1834-
{
1835-
$disabledCaches = [];
1836-
1837-
/** @var CacheManager $cacheManager */
1838-
$cacheManager = $this->objectManagerProvider->get()->create(CacheManager::class);
1839-
$cacheStatus = $cacheManager->getStatus();
1840-
1841-
foreach ($cacheTypesToCheck as $cacheType) {
1842-
if (isset($cacheStatus[$cacheType]) && $cacheStatus[$cacheType] === 0) {
1843-
$disabledCaches[] = $cacheType;
1844-
}
1845-
}
1846-
1847-
return $disabledCaches;
1848-
}
1849-
18501788
/**
18511789
* Revert remote storage configuration back to local file driver
18521790
*/

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

Lines changed: 11 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,9 @@ public function testInstall(array $request, array $logMessages)
394394
$dataSetup->expects($this->any())->method('getConnection')->willReturn($connection);
395395
$cacheManager = $this->createMock(Manager::class);
396396
$cacheManager->expects($this->any())->method('getAvailableTypes')->willReturn(['foo', 'bar']);
397-
$cacheManager->expects($this->exactly(3))->method('setEnabled')->willReturn(['foo', 'bar']);
398-
$cacheManager->expects($this->exactly(3))->method('clean');
399-
$cacheManager->expects($this->exactly(3))->method('getStatus')->willReturn(['foo' => 1, 'bar' => 1]);
397+
$cacheManager->expects($this->once())->method('setEnabled')->willReturn(['foo', 'bar']);
398+
$cacheManager->expects($this->exactly(2))->method('clean');
399+
$cacheManager->expects($this->once())->method('getStatus')->willReturn(['foo' => 1, 'bar' => 1]);
400400
$appState = $this->getMockBuilder(\Magento\Framework\App\State::class)
401401
->disableOriginalConstructor()
402402
->disableArgumentCloning()
@@ -524,15 +524,11 @@ public function installDataProvider()
524524
['bar: 1'],
525525
['Installing data...'],
526526
['Data install/update:'],
527-
['Disabling caches:'],
528-
['Current status:'],
529527
['Module \'Foo_One\':'],
530528
['Module \'Bar_Two\':'],
531529
['Data post-updates:'],
532530
['Module \'Foo_One\':'],
533531
['Module \'Bar_Two\':'],
534-
['Enabling caches:'],
535-
['Current status:'],
536532
['Caches clearing:'],
537533
['Cache cleared successfully'],
538534
['Disabling Maintenance Mode:'],
@@ -578,15 +574,11 @@ public function installDataProvider()
578574
['bar: 1'],
579575
['Installing data...'],
580576
['Data install/update:'],
581-
['Disabling caches:'],
582-
['Current status:'],
583577
['Module \'Foo_One\':'],
584578
['Module \'Bar_Two\':'],
585579
['Data post-updates:'],
586580
['Module \'Foo_One\':'],
587581
['Module \'Bar_Two\':'],
588-
['Enabling caches:'],
589-
['Current status:'],
590582
['Installing admin user...'],
591583
['Caches clearing:'],
592584
['Cache cleared successfully'],
@@ -678,9 +670,9 @@ public function testInstallWithOrderIncrementPrefix(array $request, array $logMe
678670
$dataSetup->expects($this->any())->method('getConnection')->willReturn($connection);
679671
$cacheManager = $this->createMock(Manager::class);
680672
$cacheManager->expects($this->any())->method('getAvailableTypes')->willReturn(['foo', 'bar']);
681-
$cacheManager->expects($this->exactly(3))->method('setEnabled')->willReturn(['foo', 'bar']);
682-
$cacheManager->expects($this->exactly(3))->method('clean');
683-
$cacheManager->expects($this->exactly(3))->method('getStatus')->willReturn(['foo' => 1, 'bar' => 1]);
673+
$cacheManager->expects($this->once())->method('setEnabled')->willReturn(['foo', 'bar']);
674+
$cacheManager->expects($this->exactly(2))->method('clean');
675+
$cacheManager->expects($this->once())->method('getStatus')->willReturn(['foo' => 1, 'bar' => 1]);
684676
$appState = $this->getMockBuilder(\Magento\Framework\App\State::class)
685677
->disableOriginalConstructor()
686678
->disableArgumentCloning()
@@ -815,15 +807,11 @@ public function installWithOrderIncrementPrefixDataProvider(): array
815807
['bar: 1'],
816808
['Installing data...'],
817809
['Data install/update:'],
818-
['Disabling caches:'],
819-
['Current status:'],
820810
['Module \'Foo_One\':'],
821811
['Module \'Bar_Two\':'],
822812
['Data post-updates:'],
823813
['Module \'Foo_One\':'],
824814
['Module \'Bar_Two\':'],
825-
['Enabling caches:'],
826-
['Current status:'],
827815
['Creating sales order increment prefix...'], // << added
828816
['Caches clearing:'],
829817
['Cache cleared successfully'],
@@ -1078,9 +1066,9 @@ public function testInstallWithUnresolvableRemoteStorageValidator()
10781066
$dataSetup->expects(static::any())->method('getConnection')->willReturn($connection);
10791067
$cacheManager = $this->createMock(Manager::class);
10801068
$cacheManager->expects(static::any())->method('getAvailableTypes')->willReturn(['foo', 'bar']);
1081-
$cacheManager->expects(static::exactly(3))->method('setEnabled')->willReturn(['foo', 'bar']);
1082-
$cacheManager->expects(static::exactly(3))->method('clean');
1083-
$cacheManager->expects(static::exactly(3))->method('getStatus')->willReturn(['foo' => 1, 'bar' => 1]);
1069+
$cacheManager->expects(static::once())->method('setEnabled')->willReturn(['foo', 'bar']);
1070+
$cacheManager->expects(static::exactly(2))->method('clean');
1071+
$cacheManager->expects(static::once())->method('getStatus')->willReturn(['foo' => 1, 'bar' => 1]);
10841072
$appState = $this->getMockBuilder(\Magento\Framework\App\State::class)
10851073
->disableOriginalConstructor()
10861074
->disableArgumentCloning()
@@ -1362,28 +1350,13 @@ public function installWithInvalidRemoteStorageConfigurationWithEarlyExceptionDa
13621350
/**
13631351
* Test for InstallDataFixtures
13641352
*
1365-
* @dataProvider testInstallDataFixturesDataProvider
1366-
*
1367-
* @param bool $keepCache
1368-
* @param array $expectedToEnableCacheTypes
13691353
* @return void
13701354
*/
1371-
public function testInstallDataFixtures(bool $keepCache, array $expectedToEnableCacheTypes): void
1355+
public function testInstallDataFixtures(): void
13721356
{
13731357
$this->moduleList->method('getOne')->willReturn(['setup_version' => '2.0.0']);
13741358

13751359
$cacheManagerMock = $this->createMock(Manager::class);
1376-
//simulate disabled layout cache type
1377-
$cacheManagerMock->expects($this->atLeastOnce())
1378-
->method('getStatus')
1379-
->willReturn(['layout' => 0]);
1380-
$cacheManagerMock->expects($this->atLeastOnce())
1381-
->method('getAvailableTypes')
1382-
->willReturn(['block_html', 'full_page', 'layout' , 'config', 'collections']);
1383-
$cacheManagerMock->expects($this->exactly(2))
1384-
->method('setEnabled')
1385-
->withConsecutive([$expectedToEnableCacheTypes, false], [$expectedToEnableCacheTypes, true])
1386-
->willReturn([]);
13871360

13881361
$this->objectManager->expects($this->atLeastOnce())
13891362
->method('create')
@@ -1437,25 +1410,7 @@ public function testInstallDataFixtures(bool $keepCache, array $expectedToEnable
14371410
->method('create')
14381411
->willReturn($dataSetup);
14391412

1440-
$this->object->installDataFixtures($this->request, $keepCache);
1441-
}
1442-
1443-
/**
1444-
* DataProvider for testInstallDataFixtures
1445-
*
1446-
* @return array
1447-
*/
1448-
public function testInstallDataFixturesDataProvider(): array
1449-
{
1450-
return [
1451-
'keep cache' => [
1452-
true, ['block_html', 'full_page']
1453-
],
1454-
'do not keep a cache' => [
1455-
false,
1456-
['block_html', 'full_page', 'layout']
1457-
],
1458-
];
1413+
$this->object->installDataFixtures($this->request);
14591414
}
14601415

14611416
public function testCheckInstallationFilePermissions()

0 commit comments

Comments
 (0)