5
5
*/
6
6
namespace Magento \Framework \Code ;
7
7
8
+ use Magento \Framework \Config \Data \ConfigData ;
8
9
use Magento \Framework \App \Filesystem \DirectoryList ;
10
+ use Magento \Framework \Config \File \ConfigFilePool ;
9
11
use Magento \Framework \Filesystem \Directory \WriteFactory ;
10
12
use Magento \Framework \Filesystem \Directory \WriteInterface ;
13
+ use Magento \Framework \App \DeploymentConfig \Writer \PhpFormatter ;
11
14
12
15
/**
13
16
* Regenerates generated code and DI configuration
@@ -49,6 +52,43 @@ public function __construct(DirectoryList $directoryList, WriteFactory $writeFac
49
52
public function regenerate ()
50
53
{
51
54
if ($ this ->write ->isExist (self ::REGENERATE_FLAG )) {
55
+ //clean cache
56
+ $ deploymentConfig = $ this ->directoryList ->getPath (DirectoryList::CONFIG );
57
+ $ configPool = new ConfigFilePool ();
58
+ $ envPath = $ deploymentConfig . '/ ' . $ configPool ->getPath (ConfigFilePool::APP_ENV );
59
+ if ($ this ->write ->isExist ($ this ->write ->getRelativePath ($ envPath ))) {
60
+ $ cacheData = include $ envPath ;
61
+
62
+ if (isset ($ cacheData ['cache_types ' ])) {
63
+ $ enabledCacheTypes = $ cacheData ['cache_types ' ];
64
+ $ enabledCacheTypes = array_filter ($ enabledCacheTypes , function ($ value ) {
65
+ return $ value ;
66
+ }
67
+ );
68
+ if (!empty ($ enabledCacheTypes )) {
69
+ $ this ->write ->writeFile ($ this ->write ->getRelativePath (
70
+ $ this ->directoryList ->getPath (DirectoryList::VAR_DIR )) . '/.cachestates.json ' ,
71
+ json_encode ($ enabledCacheTypes )
72
+ );
73
+ $ cacheTypes = array_keys ($ cacheData ['cache_types ' ]);
74
+
75
+ foreach ($ cacheTypes as $ cacheType ) {
76
+ $ cacheData ['cache_types ' ][$ cacheType ] = 0 ;
77
+ }
78
+
79
+ $ formatter = new PhpFormatter ();
80
+ $ contents = $ formatter ->format ($ cacheData );
81
+
82
+ $ this ->write ->writeFile ($ this ->write ->getRelativePath ($ envPath ), $ contents );
83
+ if (function_exists ('opcache_invalidate ' )) {
84
+ opcache_invalidate (
85
+ $ this ->write ->getAbsolutePath ($ envPath )
86
+ );
87
+ }
88
+ }
89
+ }
90
+ }
91
+ $ cachePath = $ this ->write ->getRelativePath ($ this ->directoryList ->getPath (DirectoryList::CACHE ));
52
92
$ generationPath = $ this ->write ->getRelativePath ($ this ->directoryList ->getPath (DirectoryList::GENERATION ));
53
93
$ diPath = $ this ->write ->getRelativePath ($ this ->directoryList ->getPath (DirectoryList::DI ));
54
94
@@ -58,6 +98,11 @@ public function regenerate()
58
98
if ($ this ->write ->isDirectory ($ diPath )) {
59
99
$ this ->write ->delete ($ diPath );
60
100
}
101
+ if ($ this ->write ->isDirectory ($ cachePath )) {
102
+ $ this ->write ->delete ($ cachePath );
103
+ }
104
+ //add to queue
105
+
61
106
$ this ->write ->delete (self ::REGENERATE_FLAG );
62
107
}
63
108
}
0 commit comments