7
7
namespace Magento \Setup \Model ;
8
8
9
9
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 ;
10
12
use Magento \Framework \App \DeploymentConfig \Reader ;
11
13
use Magento \Framework \App \DeploymentConfig \Writer ;
12
14
use Magento \Framework \App \Filesystem \DirectoryList ;
35
37
use Magento \Framework \Setup \SchemaSetupInterface ;
36
38
use Magento \Framework \Setup \UpgradeDataInterface ;
37
39
use Magento \Framework \Setup \UpgradeSchemaInterface ;
40
+ use Magento \PageCache \Model \Cache \Type as PageCache ;
38
41
use Magento \Setup \Console \Command \InstallCommand ;
39
42
use Magento \Setup \Controller \ResponseTypeInterface ;
40
43
use Magento \Setup \Model \ConfigModel as SetupConfigModel ;
@@ -336,7 +339,7 @@ public function install($request)
336
339
}
337
340
$ script [] = ['Installing database schema: ' , 'installSchema ' , [$ request ]];
338
341
$ script [] = ['Installing user configuration... ' , 'installUserConfig ' , [$ request ]];
339
- $ script [] = ['Enabling caches: ' , 'enableCaches ' , []];
342
+ $ script [] = ['Enabling caches: ' , 'updateCaches ' , [true ]];
340
343
$ script [] = ['Installing data... ' , 'installDataFixtures ' , [$ request ]];
341
344
if (!empty ($ request [InstallCommand::INPUT_KEY_SALES_ORDER_INCREMENT_PREFIX ])) {
342
345
$ script [] = [
@@ -866,6 +869,12 @@ private function convertationOfOldScriptsIsAllowed(array $request)
866
869
*/
867
870
public function installDataFixtures (array $ request = [])
868
871
{
872
+ $ frontendCaches = [
873
+ PageCache::TYPE_IDENTIFIER ,
874
+ BlockCache::TYPE_IDENTIFIER ,
875
+ LayoutCache::TYPE_IDENTIFIER ,
876
+ ];
877
+
869
878
/** @var \Magento\Framework\Registry $registry */
870
879
$ registry = $ this ->objectManagerProvider ->get ()->get (\Magento \Framework \Registry::class);
871
880
//For backward compatibility in install and upgrade scripts with enabled parallelization.
@@ -876,7 +885,11 @@ public function installDataFixtures(array $request = [])
876
885
$ setup = $ this ->dataSetupFactory ->create ();
877
886
$ this ->checkFilePermissionsForDbUpgrade ();
878
887
$ this ->log ->log ('Data install/update: ' );
888
+ $ this ->log ->log ('Disabling caches: ' );
889
+ $ this ->updateCaches (false , $ frontendCaches );
879
890
$ this ->handleDBSchemaData ($ setup , 'data ' , $ request );
891
+ $ this ->log ->log ('Enabling caches: ' );
892
+ $ this ->updateCaches (true , $ frontendCaches );
880
893
881
894
$ registry ->unregister ('setup-mode-enabled ' );
882
895
}
@@ -1248,23 +1261,39 @@ public function uninstall()
1248
1261
}
1249
1262
1250
1263
/**
1251
- * Enables caches after installing application
1264
+ * Enable or disable caches for specific types that are available
1252
1265
*
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.
1254
1268
*
1255
- * @SuppressWarnings(PHPMD.UnusedPrivateMethod) Called by install() via callback.
1269
+ * @param bool $isEnabled
1270
+ * @param array $types
1271
+ * @return void
1256
1272
*/
1257
- private function enableCaches ( )
1273
+ private function updateCaches ( $ isEnabled , $ types = [] )
1258
1274
{
1259
1275
/** @var \Magento\Framework\App\Cache\Manager $cacheManager */
1260
1276
$ 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
+ );
1264
1293
1265
1294
$ this ->log ->log ('Current status: ' );
1266
1295
// phpcs:ignore Magento2.Functions.DiscouragedFunction
1267
- $ this ->log ->log (print_r ($ cacheManager -> getStatus () , true ));
1296
+ $ this ->log ->log (print_r ($ cacheStatus , true ));
1268
1297
}
1269
1298
1270
1299
/**
0 commit comments