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 ;
@@ -934,14 +935,9 @@ public function installDataFixtures(array $request = [], $keepCacheStatuses = fa
934935 ];
935936
936937 if ($ keepCacheStatuses ) {
937- $ cacheManager = $ this ->objectManagerProvider ->get ()->create (\Magento \Framework \App \Cache \Manager::class);
938- $ disabledCaches = array_filter (
939- $ cacheManager ->getStatus (),
940- function ($ value , string $ key ) use ($ frontendCaches ) {
941- return $ value == false && in_array ($ key , $ frontendCaches );
942- },
943- ARRAY_FILTER_USE_BOTH
944- );
938+ $ disabledCaches = $ this ->getDisabledCacheTypes ($ frontendCaches );
939+
940+ $ frontendCaches = array_diff ($ frontendCaches , $ disabledCaches );
945941 }
946942
947943 /** @var \Magento\Framework\Registry $registry */
@@ -954,14 +950,19 @@ function ($value, string $key) use ($frontendCaches) {
954950 $ setup = $ this ->dataSetupFactory ->create ();
955951 $ this ->checkFilePermissionsForDbUpgrade ();
956952 $ this ->log ->log ('Data install/update: ' );
957- $ this ->log ->log ('Disabling caches: ' );
958- $ this ->updateCaches (false , $ frontendCaches );
959- $ this ->handleDBSchemaData ($ setup , 'data ' , $ request );
960- $ this ->log ->log ('Enabling caches: ' );
961- $ this ->updateCaches (true , $ frontendCaches );
962- if ($ keepCacheStatuses && !empty ($ disabledCaches )) {
963- $ this ->log ->log ('Disabling pre-disabled caches: ' );
964- $ this ->updateCaches (false , array_keys ($ disabledCaches ));
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+ }
965966 }
966967
967968 $ registry ->unregister ('setup-mode-enabled ' );
@@ -1742,4 +1743,25 @@ public function removeUnusedTriggers(): void
17421743 $ this ->triggerCleaner ->removeTriggers ();
17431744 $ this ->cleanCaches ();
17441745 }
1746+
1747+ /**
1748+ * @param array $cacheTypesToCheck
1749+ * @return array
1750+ */
1751+ private function getDisabledCacheTypes (array $ cacheTypesToCheck ): array
1752+ {
1753+ $ disabledCaches = [];
1754+
1755+ /** @var CacheManager $cacheManager */
1756+ $ cacheManager = $ this ->objectManagerProvider ->get ()->create (CacheManager::class);
1757+ $ cacheStatus = $ cacheManager ->getStatus ();
1758+
1759+ foreach ($ cacheTypesToCheck as $ cacheType ) {
1760+ if (isset ($ cacheStatus [$ cacheType ]) && $ cacheStatus [$ cacheType ] === 0 ) {
1761+ $ disabledCaches [] = $ cacheType ;
1762+ }
1763+ }
1764+
1765+ return $ disabledCaches ;
1766+ }
17451767}
0 commit comments