@@ -53,36 +53,9 @@ public function __construct(DirectoryList $directoryList, WriteFactory $writeFac
53
53
*/
54
54
public function regenerate ()
55
55
{
56
- if ($ this ->write ->isExist (self ::REGENERATE_FLAG )) {
57
- //TODO: to be removed in scope of MAGETWO-53476
58
- //clean cache
59
- $ deploymentConfig = $ this ->directoryList ->getPath (DirectoryList::CONFIG );
60
- $ configPool = new ConfigFilePool ();
61
- $ envPath = $ deploymentConfig . '/ ' . $ configPool ->getPath (ConfigFilePool::APP_ENV );
62
- if ($ this ->write ->isExist ($ this ->write ->getRelativePath ($ envPath ))) {
63
- $ this ->saveCacheStatus ($ envPath );
64
- }
65
- //TODO: Till here
66
- $ cachePath = $ this ->write ->getRelativePath ($ this ->directoryList ->getPath (DirectoryList::CACHE ));
67
- $ generationPath = $ this ->write ->getRelativePath ($ this ->directoryList ->getPath (DirectoryList::GENERATION ));
68
- $ diPath = $ this ->write ->getRelativePath ($ this ->directoryList ->getPath (DirectoryList::DI ));
69
-
70
- if ($ this ->write ->isDirectory ($ generationPath )) {
71
- $ this ->write ->delete ($ generationPath );
72
- }
73
- if ($ this ->write ->isDirectory ($ diPath )) {
74
- $ this ->write ->delete ($ diPath );
75
- }
76
- if ($ this ->write ->isDirectory ($ cachePath )) {
77
- $ this ->write ->delete ($ cachePath );
78
- }
79
- //add to queue
80
-
81
- $ this ->write ->delete (self ::REGENERATE_FLAG );
82
- }
56
+ $ this ->cleanGeneratedFiles ();
83
57
}
84
58
85
-
86
59
/**
87
60
* Clean var/generation, var/di and var/cache
88
61
*
@@ -92,14 +65,14 @@ public function cleanGeneratedFiles()
92
65
{
93
66
if ($ this ->write ->isExist (self ::REGENERATE_FLAG )) {
94
67
95
- $ cacheStatus = [];
68
+ $ enabledCacheTypes = [];
96
69
97
70
//TODO: to be removed in scope of MAGETWO-53476
98
71
$ deploymentConfig = $ this ->directoryList ->getPath (DirectoryList::CONFIG );
99
72
$ configPool = new ConfigFilePool ();
100
73
$ envPath = $ deploymentConfig . '/ ' . $ configPool ->getPath (ConfigFilePool::APP_ENV );
101
74
if ($ this ->write ->isExist ($ this ->write ->getRelativePath ($ envPath ))) {
102
- $ cacheStatus = $ this ->getCacheStatus ();
75
+ $ enabledCacheTypes = $ this ->getEnabledCacheTypes ();
103
76
$ this ->disableAllCacheTypes ();
104
77
}
105
78
//TODO: Till here
@@ -123,7 +96,7 @@ public function cleanGeneratedFiles()
123
96
$ this ->write ->delete ($ cachePath );
124
97
}
125
98
$ this ->write ->delete (self ::REGENERATE_FLAG );
126
- $ this ->restoreCacheStatus ( $ cacheStatus );
99
+ $ this ->enableCacheTypes ( $ enabledCacheTypes );
127
100
}
128
101
}
129
102
@@ -139,66 +112,25 @@ public function requestRegeneration()
139
112
}
140
113
141
114
/**
142
- * Read Cache types from env.php and write to a json file.
143
- *
144
- * @param string $envPath
145
- * @return void
115
+ * Reads Cache configuration from env.php and returns indexed array containing all the enabled cache types.
146
116
*
117
+ * @return string []
147
118
*/
148
- private function saveCacheStatus ( $ envPath )
119
+ private function getEnabledCacheTypes ( )
149
120
{
150
- $ cacheData = include $ envPath ;
151
-
152
- if (isset ($ cacheData ['cache_types ' ])) {
153
- $ enabledCacheTypes = $ cacheData ['cache_types ' ];
154
- $ enabledCacheTypes = array_filter ($ enabledCacheTypes , function ($ value ) {
155
- return $ value ;
156
- });
157
- if (!empty ($ enabledCacheTypes )) {
158
- $ varDir = $ this ->directoryList ->getPath (DirectoryList::VAR_DIR );
159
- $ this ->write ->writeFile (
160
- $ this ->write ->getRelativePath ($ varDir ) . '/.cachestates.json ' ,
161
- json_encode ($ enabledCacheTypes )
162
- );
163
- $ cacheTypes = array_keys ($ cacheData ['cache_types ' ]);
164
-
165
- foreach ($ cacheTypes as $ cacheType ) {
166
- $ cacheData ['cache_types ' ][$ cacheType ] = 0 ;
167
- }
168
-
169
- $ formatter = new PhpFormatter ();
170
- $ contents = $ formatter ->format ($ cacheData );
171
-
172
- $ this ->write ->writeFile ($ this ->write ->getRelativePath ($ envPath ), $ contents );
173
- if (function_exists ('opcache_invalidate ' )) {
174
- opcache_invalidate (
175
- $ this ->write ->getAbsolutePath ($ envPath )
176
- );
177
- }
178
- }
179
- }
180
- }
181
-
182
- /**
183
- * Reads Cache configuration from env.php and returns the 'cache_types' key data which is the current
184
- * cache status.
185
- *
186
- * @return array
187
- */
188
- private function getCacheStatus ()
189
- {
190
- $ cacheStatus = [];
191
- if (empty ($ envPath )) {
192
- $ envPath = $ this ->getEnvPath ();
193
- }
194
-
121
+ $ enabledCacheTypes = [];
122
+ $ envPath = $ this ->getEnvPath ();
195
123
if ($ this ->write ->isReadable ($ this ->write ->getRelativePath ($ envPath ))) {
196
124
$ envData = include $ envPath ;
197
125
if (isset ($ envData ['cache_types ' ])) {
198
126
$ cacheStatus = $ envData ['cache_types ' ];
127
+ $ enabledCacheTypes = array_filter ($ cacheStatus , function ($ value ) {
128
+ return $ value ;
129
+ });
130
+ $ enabledCacheTypes = array_keys ($ enabledCacheTypes );
199
131
}
200
132
}
201
- return $ cacheStatus ;
133
+ return $ enabledCacheTypes ;
202
134
}
203
135
204
136
@@ -246,24 +178,24 @@ private function disableAllCacheTypes()
246
178
}
247
179
248
180
/**
249
- * restore the cacache setting in env.php
181
+ * Enables apppropriate cache types in app/etc/ env.php based on the passed in $cacheTypes array
250
182
* TODO: to be removed in scope of MAGETWO-53476
251
183
*
252
- * @param array
184
+ * @param string []
253
185
*
254
186
* @return void
255
187
*/
256
- private function restoreCacheStatus ( $ cacheStatus )
188
+ private function enableCacheTypes ( $ cacheTypes )
257
189
{
258
- if (empty ($ cacheStatus )) {
190
+ if (empty ($ cacheTypes )) {
259
191
return ;
260
192
}
261
193
$ envPath = $ this ->getEnvPath ();
262
194
if ($ this ->write ->isReadable ($ this ->write ->getRelativePath ($ envPath ))) {
263
195
$ envData = include $ envPath ;
264
- foreach ($ cacheStatus as $ cacheType => $ state ) {
196
+ foreach ($ cacheTypes as $ cacheType ) {
265
197
if (isset ($ envData ['cache_types ' ][$ cacheType ])) {
266
- $ envData ['cache_types ' ][$ cacheType ] = $ state ;
198
+ $ envData ['cache_types ' ][$ cacheType ] = 1 ;
267
199
}
268
200
}
269
201
0 commit comments