@@ -93,32 +93,44 @@ protected function execute(InputInterface $input, OutputInterface $output)
93
93
$ realCacheDir = $ this ->getContainer ()->getParameter ('kernel.cache_dir ' );
94
94
}
95
95
96
+ $ fs = $ this ->filesystem ;
96
97
$ io = new SymfonyStyle ($ input , $ output );
97
98
98
99
$ kernel = $ this ->getApplication ()->getKernel ();
99
100
$ realCacheDir = isset ($ realCacheDir ) ? $ realCacheDir : $ kernel ->getContainer ()->getParameter ('kernel.cache_dir ' );
100
101
// the old cache dir name must not be longer than the real one to avoid exceeding
101
102
// the maximum length of a directory or file path within it (esp. Windows MAX_PATH)
102
103
$ oldCacheDir = substr ($ realCacheDir , 0 , -1 ).('~ ' === substr ($ realCacheDir , -1 ) ? '+ ' : '~ ' );
104
+ $ fs ->remove ($ oldCacheDir );
103
105
104
106
if (!is_writable ($ realCacheDir )) {
105
107
throw new \RuntimeException (sprintf ('Unable to write in the "%s" directory ' , $ realCacheDir ));
106
108
}
107
109
108
- if ($ this ->filesystem ->exists ($ oldCacheDir )) {
109
- $ this ->filesystem ->remove ($ oldCacheDir );
110
- }
111
-
112
110
$ io ->comment (sprintf ('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info> ' , $ kernel ->getEnvironment (), var_export ($ kernel ->isDebug (), true )));
113
111
$ this ->cacheClearer ->clear ($ realCacheDir );
114
112
115
113
// The current event dispatcher is stale, let's not use it anymore
116
114
$ this ->getApplication ()->setDispatcher (new EventDispatcher ());
117
115
118
- if ($ input ->getOption ('no-warmup ' )) {
119
- $ this ->filesystem ->rename ($ realCacheDir , $ oldCacheDir );
120
- } else {
121
- $ this ->warmupCache ($ input , $ output , $ realCacheDir , $ oldCacheDir );
116
+ $ containerDir = new \ReflectionObject ($ kernel ->getContainer ());
117
+ $ containerDir = basename (dirname ($ containerDir ->getFileName ()));
118
+
119
+ // the warmup cache dir name must have the same length as the real one
120
+ // to avoid the many problems in serialized resources files
121
+ $ warmupDir = substr ($ realCacheDir , 0 , -1 ).('_ ' === substr ($ realCacheDir , -1 ) ? '- ' : '_ ' );
122
+
123
+ if ($ output ->isVerbose () && $ fs ->exists ($ warmupDir )) {
124
+ $ io ->comment ('Clearing outdated warmup directory... ' );
125
+ }
126
+ $ fs ->remove ($ warmupDir );
127
+ $ fs ->mkdir ($ warmupDir );
128
+
129
+ if (!$ input ->getOption ('no-warmup ' )) {
130
+ if ($ output ->isVerbose ()) {
131
+ $ io ->comment ('Warming up cache... ' );
132
+ }
133
+ $ this ->warmup ($ warmupDir , $ realCacheDir , !$ input ->getOption ('no-optional-warmers ' ));
122
134
123
135
if ($ this ->warning ) {
124
136
@trigger_error ($ this ->warning , E_USER_DEPRECATED );
@@ -127,12 +139,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
127
139
}
128
140
}
129
141
142
+ $ containerDir = $ fs ->exists ($ warmupDir .'/ ' .$ containerDir ) ? false : $ containerDir ;
143
+
144
+ $ fs ->rename ($ realCacheDir , $ oldCacheDir );
145
+ $ fs ->rename ($ warmupDir , $ realCacheDir );
146
+
147
+ if ($ containerDir ) {
148
+ $ fs ->rename ($ oldCacheDir .'/ ' .$ containerDir , $ realCacheDir .'/ ' .$ containerDir );
149
+ touch ($ realCacheDir .'/ ' .$ containerDir .'.legacy ' );
150
+ }
151
+
130
152
if ($ output ->isVerbose ()) {
131
153
$ io ->comment ('Removing old cache directory... ' );
132
154
}
133
155
134
156
try {
135
- $ this -> filesystem ->remove ($ oldCacheDir );
157
+ $ fs ->remove ($ oldCacheDir );
136
158
} catch (IOException $ e ) {
137
159
$ io ->warning ($ e ->getMessage ());
138
160
}
@@ -144,34 +166,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
144
166
$ io ->success (sprintf ('Cache for the "%s" environment (debug=%s) was successfully cleared. ' , $ kernel ->getEnvironment (), var_export ($ kernel ->isDebug (), true )));
145
167
}
146
168
147
- private function warmupCache (InputInterface $ input , OutputInterface $ output , $ realCacheDir , $ oldCacheDir )
148
- {
149
- $ io = new SymfonyStyle ($ input , $ output );
150
-
151
- // the warmup cache dir name must have the same length than the real one
152
- // to avoid the many problems in serialized resources files
153
- $ realCacheDir = realpath ($ realCacheDir );
154
- $ warmupDir = substr ($ realCacheDir , 0 , -1 ).('_ ' === substr ($ realCacheDir , -1 ) ? '- ' : '_ ' );
155
-
156
- if ($ this ->filesystem ->exists ($ warmupDir )) {
157
- if ($ output ->isVerbose ()) {
158
- $ io ->comment ('Clearing outdated warmup directory... ' );
159
- }
160
- $ this ->filesystem ->remove ($ warmupDir );
161
- }
162
-
163
- if ($ output ->isVerbose ()) {
164
- $ io ->comment ('Warming up cache... ' );
165
- }
166
- $ this ->warmup ($ warmupDir , $ realCacheDir , !$ input ->getOption ('no-optional-warmers ' ));
167
-
168
- $ this ->filesystem ->rename ($ realCacheDir , $ oldCacheDir );
169
- if ('\\' === DIRECTORY_SEPARATOR ) {
170
- sleep (1 ); // workaround for Windows PHP rename bug
171
- }
172
- $ this ->filesystem ->rename ($ warmupDir , $ realCacheDir );
173
- }
174
-
175
169
/**
176
170
* @param string $warmupDir
177
171
* @param string $realCacheDir
0 commit comments