88
99use Magento \Backend \Setup \ConfigOptionsList as BackendConfigOptionsList ;
1010use Magento \Framework \App \Cache \Manager ;
11+ use Magento \Framework \App \Cache \Manager as CacheManager ;
1112use Magento \Framework \App \Cache \Type \Block as BlockCache ;
1213use Magento \Framework \App \Cache \Type \Config as ConfigCache ;
1314use Magento \Framework \App \Cache \Type \Layout as LayoutCache ;
@@ -920,18 +921,25 @@ private function convertationOfOldScriptsIsAllowed(array $request)
920921 * Installs data fixtures
921922 *
922923 * @param array $request
924+ * @param boolean $keepCacheStatuses
923925 * @return void
924926 * @throws Exception
925927 * @throws \Magento\Framework\Setup\Exception
926928 */
927- public function installDataFixtures (array $ request = [])
929+ public function installDataFixtures (array $ request = [], $ keepCacheStatuses = false )
928930 {
929931 $ frontendCaches = [
930932 PageCache::TYPE_IDENTIFIER ,
931933 BlockCache::TYPE_IDENTIFIER ,
932934 LayoutCache::TYPE_IDENTIFIER ,
933935 ];
934936
937+ if ($ keepCacheStatuses ) {
938+ $ disabledCaches = $ this ->getDisabledCacheTypes ($ frontendCaches );
939+
940+ $ frontendCaches = array_diff ($ frontendCaches , $ disabledCaches );
941+ }
942+
935943 /** @var \Magento\Framework\Registry $registry */
936944 $ registry = $ this ->objectManagerProvider ->get ()->get (\Magento \Framework \Registry::class);
937945 //For backward compatibility in install and upgrade scripts with enabled parallelization.
@@ -942,11 +950,20 @@ public function installDataFixtures(array $request = [])
942950 $ setup = $ this ->dataSetupFactory ->create ();
943951 $ this ->checkFilePermissionsForDbUpgrade ();
944952 $ this ->log ->log ('Data install/update: ' );
945- $ this ->log ->log ('Disabling caches: ' );
946- $ this ->updateCaches (false , $ frontendCaches );
947- $ this ->handleDBSchemaData ($ setup , 'data ' , $ request );
948- $ this ->log ->log ('Enabling caches: ' );
949- $ this ->updateCaches (true , $ frontendCaches );
953+
954+ if ($ frontendCaches ) {
955+ $ this ->log ->log ('Disabling caches: ' );
956+ $ this ->updateCaches (false , $ frontendCaches );
957+ }
958+
959+ try {
960+ $ this ->handleDBSchemaData ($ setup , 'data ' , $ request );
961+ } finally {
962+ if ($ frontendCaches ) {
963+ $ this ->log ->log ('Enabling caches: ' );
964+ $ this ->updateCaches (true , $ frontendCaches );
965+ }
966+ }
950967
951968 $ registry ->unregister ('setup-mode-enabled ' );
952969 }
@@ -995,7 +1012,7 @@ private function throwExceptionForNotWritablePaths(array $paths)
9951012 */
9961013 private function handleDBSchemaData ($ setup , $ type , array $ request )
9971014 {
998- if (!( $ type === 'schema ' || $ type === 'data ' ) ) {
1015+ if ($ type !== 'schema ' && $ type !== 'data ' ) {
9991016 // phpcs:ignore Magento2.Exceptions.DirectThrow
10001017 throw new Exception ("Unsupported operation type $ type is requested " );
10011018 }
@@ -1014,17 +1031,13 @@ private function handleDBSchemaData($setup, $type, array $request)
10141031 'objectManager ' => $ this ->objectManagerProvider ->get ()
10151032 ]
10161033 );
1034+
1035+ $ patchApplierParams = $ type === 'schema ' ?
1036+ ['schemaSetup ' => $ setup ] :
1037+ ['moduleDataSetup ' => $ setup , 'objectManager ' => $ this ->objectManagerProvider ->get ()];
1038+
10171039 /** @var PatchApplier $patchApplier */
1018- if ($ type === 'schema ' ) {
1019- $ patchApplier = $ this ->patchApplierFactory ->create (['schemaSetup ' => $ setup ]);
1020- } elseif ($ type === 'data ' ) {
1021- $ patchApplier = $ this ->patchApplierFactory ->create (
1022- [
1023- 'moduleDataSetup ' => $ setup ,
1024- 'objectManager ' => $ this ->objectManagerProvider ->get ()
1025- ]
1026- );
1027- }
1040+ $ patchApplier = $ this ->patchApplierFactory ->create ($ patchApplierParams );
10281041
10291042 foreach ($ moduleNames as $ moduleName ) {
10301043 if ($ this ->isDryRun ($ request )) {
@@ -1086,11 +1099,11 @@ private function handleDBSchemaData($setup, $type, array $request)
10861099
10871100 if ($ type === 'schema ' ) {
10881101 $ this ->log ->log ('Schema post-updates: ' );
1089- $ handlerType = 'schema-recurring ' ;
10901102 } elseif ($ type === 'data ' ) {
10911103 $ this ->log ->log ('Data post-updates: ' );
1092- $ handlerType = 'data-recurring ' ;
10931104 }
1105+ $ handlerType = $ type === 'schema ' ? 'schema-recurring ' : 'data-recurring ' ;
1106+
10941107 foreach ($ moduleNames as $ moduleName ) {
10951108 if ($ this ->isDryRun ($ request )) {
10961109 $ this ->log ->log ("Module ' {$ moduleName }': " );
@@ -1726,4 +1739,27 @@ public function removeUnusedTriggers(): void
17261739 $ this ->triggerCleaner ->removeTriggers ();
17271740 $ this ->cleanCaches ();
17281741 }
1742+
1743+ /**
1744+ * Returns list of disabled cache types
1745+ *
1746+ * @param array $cacheTypesToCheck
1747+ * @return array
1748+ */
1749+ private function getDisabledCacheTypes (array $ cacheTypesToCheck ): array
1750+ {
1751+ $ disabledCaches = [];
1752+
1753+ /** @var CacheManager $cacheManager */
1754+ $ cacheManager = $ this ->objectManagerProvider ->get ()->create (CacheManager::class);
1755+ $ cacheStatus = $ cacheManager ->getStatus ();
1756+
1757+ foreach ($ cacheTypesToCheck as $ cacheType ) {
1758+ if (isset ($ cacheStatus [$ cacheType ]) && $ cacheStatus [$ cacheType ] === 0 ) {
1759+ $ disabledCaches [] = $ cacheType ;
1760+ }
1761+ }
1762+
1763+ return $ disabledCaches ;
1764+ }
17291765}
0 commit comments