Skip to content

Commit 6285694

Browse files
committed
Merge remote-tracking branch 'origin/MC-30236' into 2.4-develop-pr9
2 parents 1a3a405 + 4be5439 commit 6285694

File tree

2 files changed

+56
-14
lines changed

2 files changed

+56
-14
lines changed

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

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
namespace Magento\Setup\Model;
88

99
use Magento\Backend\Setup\ConfigOptionsList as BackendConfigOptionsList;
10+
use Magento\Framework\App\Cache\Type\Block as BlockCache;
11+
use Magento\Framework\App\Cache\Type\Layout as LayoutCache;
1012
use Magento\Framework\App\DeploymentConfig\Reader;
1113
use Magento\Framework\App\DeploymentConfig\Writer;
1214
use Magento\Framework\App\Filesystem\DirectoryList;
@@ -35,6 +37,7 @@
3537
use Magento\Framework\Setup\SchemaSetupInterface;
3638
use Magento\Framework\Setup\UpgradeDataInterface;
3739
use Magento\Framework\Setup\UpgradeSchemaInterface;
40+
use Magento\PageCache\Model\Cache\Type as PageCache;
3841
use Magento\Setup\Console\Command\InstallCommand;
3942
use Magento\Setup\Controller\ResponseTypeInterface;
4043
use Magento\Setup\Model\ConfigModel as SetupConfigModel;
@@ -336,7 +339,7 @@ public function install($request)
336339
}
337340
$script[] = ['Installing database schema:', 'installSchema', [$request]];
338341
$script[] = ['Installing user configuration...', 'installUserConfig', [$request]];
339-
$script[] = ['Enabling caches:', 'enableCaches', []];
342+
$script[] = ['Enabling caches:', 'updateCaches', [true]];
340343
$script[] = ['Installing data...', 'installDataFixtures', [$request]];
341344
if (!empty($request[InstallCommand::INPUT_KEY_SALES_ORDER_INCREMENT_PREFIX])) {
342345
$script[] = [
@@ -866,6 +869,12 @@ private function convertationOfOldScriptsIsAllowed(array $request)
866869
*/
867870
public function installDataFixtures(array $request = [])
868871
{
872+
$frontendCaches = [
873+
PageCache::TYPE_IDENTIFIER,
874+
BlockCache::TYPE_IDENTIFIER,
875+
LayoutCache::TYPE_IDENTIFIER,
876+
];
877+
869878
/** @var \Magento\Framework\Registry $registry */
870879
$registry = $this->objectManagerProvider->get()->get(\Magento\Framework\Registry::class);
871880
//For backward compatibility in install and upgrade scripts with enabled parallelization.
@@ -876,7 +885,11 @@ public function installDataFixtures(array $request = [])
876885
$setup = $this->dataSetupFactory->create();
877886
$this->checkFilePermissionsForDbUpgrade();
878887
$this->log->log('Data install/update:');
888+
$this->log->log('Disabling caches:');
889+
$this->updateCaches(false, $frontendCaches);
879890
$this->handleDBSchemaData($setup, 'data', $request);
891+
$this->log->log('Enabling caches:');
892+
$this->updateCaches(true, $frontendCaches);
880893

881894
$registry->unregister('setup-mode-enabled');
882895
}
@@ -1248,23 +1261,39 @@ public function uninstall()
12481261
}
12491262

12501263
/**
1251-
* Enables caches after installing application
1264+
* Enable or disable caches for specific types that are available
12521265
*
1253-
* @return void
1266+
* If no types are specified then it will enable or disable all available types
1267+
* Note this is called by install() via callback.
12541268
*
1255-
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) Called by install() via callback.
1269+
* @param bool $isEnabled
1270+
* @param array $types
1271+
* @return void
12561272
*/
1257-
private function enableCaches()
1273+
private function updateCaches($isEnabled, $types = [])
12581274
{
12591275
/** @var \Magento\Framework\App\Cache\Manager $cacheManager */
12601276
$cacheManager = $this->objectManagerProvider->get()->create(\Magento\Framework\App\Cache\Manager::class);
1261-
$types = $cacheManager->getAvailableTypes();
1262-
$enabledTypes = $cacheManager->setEnabled($types, true);
1263-
$cacheManager->clean($enabledTypes);
1277+
1278+
$availableTypes = $cacheManager->getAvailableTypes();
1279+
$types = empty($types) ? $availableTypes : array_intersect($availableTypes, $types);
1280+
$enabledTypes = $cacheManager->setEnabled($types, $isEnabled);
1281+
if ($isEnabled) {
1282+
$cacheManager->clean($enabledTypes);
1283+
}
1284+
1285+
// Only get statuses of specific cache types
1286+
$cacheStatus = array_filter(
1287+
$cacheManager->getStatus(),
1288+
function (string $key) use ($types) {
1289+
return in_array($key, $types);
1290+
},
1291+
ARRAY_FILTER_USE_KEY
1292+
);
12641293

12651294
$this->log->log('Current status:');
12661295
// phpcs:ignore Magento2.Functions.DiscouragedFunction
1267-
$this->log->log(print_r($cacheManager->getStatus(), true));
1296+
$this->log->log(print_r($cacheStatus, true));
12681297
}
12691298

12701299
/**

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@ public function testInstall(array $request, array $logMessages)
307307
$dataSetup->expects($this->any())->method('getConnection')->willReturn($connection);
308308
$cacheManager = $this->createMock(\Magento\Framework\App\Cache\Manager::class);
309309
$cacheManager->expects($this->any())->method('getAvailableTypes')->willReturn(['foo', 'bar']);
310-
$cacheManager->expects($this->once())->method('setEnabled')->willReturn(['foo', 'bar']);
311-
$cacheManager->expects($this->any())->method('clean');
310+
$cacheManager->expects($this->exactly(3))->method('setEnabled')->willReturn(['foo', 'bar']);
311+
$cacheManager->expects($this->exactly(3))->method('clean');
312+
$cacheManager->expects($this->exactly(3))->method('getStatus')->willReturn(['foo' => 1, 'bar' => 1]);
312313
$appState = $this->getMockBuilder(\Magento\Framework\App\State::class)
313314
->disableOriginalConstructor()
314315
->disableArgumentCloning()
@@ -382,6 +383,7 @@ public function testInstall(array $request, array $logMessages)
382383

383384
/**
384385
* @return array
386+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
385387
*/
386388
public function installDataProvider()
387389
{
@@ -410,15 +412,20 @@ public function installDataProvider()
410412
['Installing user configuration...'],
411413
['Enabling caches:'],
412414
['Current status:'],
413-
[''],
415+
[print_r(['foo' => 1, 'bar' => 1], true)],
414416
['Installing data...'],
415417
['Data install/update:'],
418+
['Disabling caches:'],
419+
['Current status:'],
420+
[print_r([], true)],
416421
['Module \'Foo_One\':'],
417422
['Module \'Bar_Two\':'],
418423
['Data post-updates:'],
419424
['Module \'Foo_One\':'],
420425
['Module \'Bar_Two\':'],
421-
//['Installing admin user...'],
426+
['Enabling caches:'],
427+
['Current status:'],
428+
[print_r([], true)],
422429
['Caches clearing:'],
423430
['Cache cleared successfully'],
424431
['Disabling Maintenance Mode:'],
@@ -456,14 +463,20 @@ public function installDataProvider()
456463
['Installing user configuration...'],
457464
['Enabling caches:'],
458465
['Current status:'],
459-
[''],
466+
[print_r(['foo' => 1, 'bar' => 1], true)],
460467
['Installing data...'],
461468
['Data install/update:'],
469+
['Disabling caches:'],
470+
['Current status:'],
471+
[print_r([], true)],
462472
['Module \'Foo_One\':'],
463473
['Module \'Bar_Two\':'],
464474
['Data post-updates:'],
465475
['Module \'Foo_One\':'],
466476
['Module \'Bar_Two\':'],
477+
['Enabling caches:'],
478+
['Current status:'],
479+
[print_r([], true)],
467480
['Installing admin user...'],
468481
['Caches clearing:'],
469482
['Cache cleared successfully'],

0 commit comments

Comments
 (0)