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,9 @@ 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 ->updateCaches (false , $ frontendCaches , false );
879
889
$ this ->handleDBSchemaData ($ setup , 'data ' , $ request );
890
+ $ this ->updateCaches (true , $ frontendCaches , false );
880
891
881
892
$ registry ->unregister ('setup-mode-enabled ' );
882
893
}
@@ -1248,23 +1259,32 @@ public function uninstall()
1248
1259
}
1249
1260
1250
1261
/**
1251
- * Enables caches after installing application
1262
+ * Enable or disable caches for specific types
1252
1263
*
1253
- * @return void
1264
+ * If no types are specified then it will enable or disable all available types
1265
+ * Note this is called by install() via callback.
1254
1266
*
1255
- * @SuppressWarnings(PHPMD.UnusedPrivateMethod) Called by install() via callback.
1267
+ * @param bool $isEnabled
1268
+ * @param array $types
1269
+ * @param bool $logStatus
1270
+ * @return void
1256
1271
*/
1257
- private function enableCaches ( )
1272
+ private function updateCaches ( $ isEnabled , $ types = [], $ logStatus = true )
1258
1273
{
1259
1274
/** @var \Magento\Framework\App\Cache\Manager $cacheManager */
1260
1275
$ 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 );
1276
+ $ types = empty ($ types ) ? $ cacheManager ->getAvailableTypes () : $ types ;
1277
+
1278
+ $ enabledTypes = $ cacheManager ->setEnabled ($ types , $ isEnabled );
1279
+ if ($ isEnabled ){
1280
+ $ cacheManager ->clean ($ enabledTypes );
1281
+ }
1264
1282
1265
- $ this ->log ->log ('Current status: ' );
1266
- // phpcs:ignore Magento2.Functions.DiscouragedFunction
1267
- $ this ->log ->log (print_r ($ cacheManager ->getStatus (), true ));
1283
+ if ($ logStatus ) {
1284
+ $ this ->log ->log ('Current status: ' );
1285
+ // phpcs:ignore Magento2.Functions.DiscouragedFunction
1286
+ $ this ->log ->log (print_r ($ cacheManager ->getStatus (), true ));
1287
+ }
1268
1288
}
1269
1289
1270
1290
/**
0 commit comments