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 ;
@@ -920,18 +921,25 @@ private function convertationOfOldScriptsIsAllowed(array $request)
920
921
* Installs data fixtures
921
922
*
922
923
* @param array $request
924
+ * @param boolean $keepCacheStatuses
923
925
* @return void
924
926
* @throws Exception
925
927
* @throws \Magento\Framework\Setup\Exception
926
928
*/
927
- public function installDataFixtures (array $ request = [])
929
+ public function installDataFixtures (array $ request = [], $ keepCacheStatuses = false )
928
930
{
929
931
$ frontendCaches = [
930
932
PageCache::TYPE_IDENTIFIER ,
931
933
BlockCache::TYPE_IDENTIFIER ,
932
934
LayoutCache::TYPE_IDENTIFIER ,
933
935
];
934
936
937
+ if ($ keepCacheStatuses ) {
938
+ $ disabledCaches = $ this ->getDisabledCacheTypes ($ frontendCaches );
939
+
940
+ $ frontendCaches = array_diff ($ frontendCaches , $ disabledCaches );
941
+ }
942
+
935
943
/** @var \Magento\Framework\Registry $registry */
936
944
$ registry = $ this ->objectManagerProvider ->get ()->get (\Magento \Framework \Registry::class);
937
945
//For backward compatibility in install and upgrade scripts with enabled parallelization.
@@ -942,11 +950,20 @@ public function installDataFixtures(array $request = [])
942
950
$ setup = $ this ->dataSetupFactory ->create ();
943
951
$ this ->checkFilePermissionsForDbUpgrade ();
944
952
$ 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
+ }
950
967
951
968
$ registry ->unregister ('setup-mode-enabled ' );
952
969
}
@@ -995,7 +1012,7 @@ private function throwExceptionForNotWritablePaths(array $paths)
995
1012
*/
996
1013
private function handleDBSchemaData ($ setup , $ type , array $ request )
997
1014
{
998
- if (!( $ type === 'schema ' || $ type === 'data ' ) ) {
1015
+ if ($ type !== 'schema ' && $ type !== 'data ' ) {
999
1016
// phpcs:ignore Magento2.Exceptions.DirectThrow
1000
1017
throw new Exception ("Unsupported operation type $ type is requested " );
1001
1018
}
@@ -1014,17 +1031,13 @@ private function handleDBSchemaData($setup, $type, array $request)
1014
1031
'objectManager ' => $ this ->objectManagerProvider ->get ()
1015
1032
]
1016
1033
);
1034
+
1035
+ $ patchApplierParams = $ type === 'schema ' ?
1036
+ ['schemaSetup ' => $ setup ] :
1037
+ ['moduleDataSetup ' => $ setup , 'objectManager ' => $ this ->objectManagerProvider ->get ()];
1038
+
1017
1039
/** @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 );
1028
1041
1029
1042
foreach ($ moduleNames as $ moduleName ) {
1030
1043
if ($ this ->isDryRun ($ request )) {
@@ -1086,11 +1099,11 @@ private function handleDBSchemaData($setup, $type, array $request)
1086
1099
1087
1100
if ($ type === 'schema ' ) {
1088
1101
$ this ->log ->log ('Schema post-updates: ' );
1089
- $ handlerType = 'schema-recurring ' ;
1090
1102
} elseif ($ type === 'data ' ) {
1091
1103
$ this ->log ->log ('Data post-updates: ' );
1092
- $ handlerType = 'data-recurring ' ;
1093
1104
}
1105
+ $ handlerType = $ type === 'schema ' ? 'schema-recurring ' : 'data-recurring ' ;
1106
+
1094
1107
foreach ($ moduleNames as $ moduleName ) {
1095
1108
if ($ this ->isDryRun ($ request )) {
1096
1109
$ this ->log ->log ("Module ' {$ moduleName }': " );
@@ -1726,4 +1739,27 @@ public function removeUnusedTriggers(): void
1726
1739
$ this ->triggerCleaner ->removeTriggers ();
1727
1740
$ this ->cleanCaches ();
1728
1741
}
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
+ }
1729
1765
}
0 commit comments