8
8
9
9
use Magento \Backend \Setup \ConfigOptionsList as BackendConfigOptionsList ;
10
10
use Magento \Framework \App \Cache \Manager ;
11
+ use Magento \Framework \App \Cache \Manager as CacheManager ;
11
12
use Magento \Framework \App \Cache \Type \Block as BlockCache ;
12
13
use Magento \Framework \App \Cache \Type \Config as ConfigCache ;
13
14
use Magento \Framework \App \Cache \Type \Layout as LayoutCache ;
@@ -934,14 +935,9 @@ public function installDataFixtures(array $request = [], $keepCacheStatuses = fa
934
935
];
935
936
936
937
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 );
945
941
}
946
942
947
943
/** @var \Magento\Framework\Registry $registry */
@@ -954,14 +950,19 @@ function ($value, string $key) use ($frontendCaches) {
954
950
$ setup = $ this ->dataSetupFactory ->create ();
955
951
$ this ->checkFilePermissionsForDbUpgrade ();
956
952
$ 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
+ }
965
966
}
966
967
967
968
$ registry ->unregister ('setup-mode-enabled ' );
@@ -1742,4 +1743,25 @@ public function removeUnusedTriggers(): void
1742
1743
$ this ->triggerCleaner ->removeTriggers ();
1743
1744
$ this ->cleanCaches ();
1744
1745
}
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
+ }
1745
1767
}
0 commit comments