Generic_AdminActions_Flush.php
7.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<?php
namespace W3TC;
class Generic_AdminActions_Flush {
private $_config = null;
function __construct() {
$this->_config = Dispatcher::config();
}
/**
* Flush all caches action
*
* @return void
*/
function w3tc_flush_all() {
w3tc_flush_all();
$this->_redirect_after_flush( 'flush_all' );
}
/**
* Flush memcache cache action
*
* @return void
*/
function w3tc_flush_memcached() {
$this->flush_memcached();
Util_Admin::redirect( array(
'w3tc_note' => 'flush_memcached'
), true );
}
/**
* Flush opcode caches action
*
* @return void
*/
function w3tc_flush_opcode() {
$this->flush_opcode();
Util_Admin::redirect( array(
'w3tc_note' => 'flush_opcode'
), true );
}
/**
* Flush file caches action
*
* @return void
*/
function w3tc_flush_file() {
$this->flush_file();
Util_Admin::redirect( array(
'w3tc_note' => 'flush_file'
), true );
}
/**
* Flush from static files and further
*
* @return void
*/
function w3tc_flush_statics() {
$cf = Dispatcher::component( 'CacheFlush' );
$cf->browsercache_flush();
w3tc_flush_posts();
$state_note = Dispatcher::config_state_note();
$state_note->set( 'common.show_note.flush_statics_needed', false );
$state_note->set( 'common.show_note.flush_posts_needed', false );
$state_note->set( 'common.show_note.plugins_updated', false );
Util_Admin::redirect_with_custom_messages2( array(
'notes' => array(
__( 'Static files cache successfully emptied.', 'w3-total-cache' )
)
), true );
}
/**
* Flush posts
*
* @return void
*/
function w3tc_flush_posts() {
w3tc_flush_posts();
$state_note = Dispatcher::config_state_note();
$state_note->set( 'common.show_note.flush_posts_needed', false );
$state_note->set( 'common.show_note.plugins_updated', false );
$this->_redirect_after_flush( 'flush_pgcache' );
}
/**
* Flush page cache action
*
* @return void
*/
function w3tc_flush_pgcache() {
$pgcacheflush = Dispatcher::component( 'PgCache_Flush' );
$pgcacheflush->flush();
$pgcacheflush->flush_post_cleanup();
$state_note = Dispatcher::config_state_note();
$state_note->set( 'common.show_note.flush_posts_needed', false );
$state_note->set( 'common.show_note.plugins_updated', false );
Util_Admin::redirect( array(
'w3tc_note' => 'flush_pgcache'
), true );
}
/**
* Flush database cache action
*
* @return void
*/
function w3tc_flush_dbcache() {
$this->flush_dbcache();
Util_Admin::redirect( array(
'w3tc_note' => 'flush_dbcache'
), true );
}
/**
* Flush object cache action
*
* @return void
*/
function w3tc_flush_objectcache() {
$this->flush_objectcache();
$state_note = Dispatcher::config_state_note();
$state_note->set( 'objectcache.show_note.flush_needed', false );
Util_Admin::redirect( array(
'w3tc_note' => 'flush_objectcache'
), true );
}
/**
* Flush fragment cache action
*
* @return void
*/
function w3tc_flush_fragmentcache() {
$this->flush_fragmentcache();
$this->_config->set( 'notes.need_empty_fragmentcache', false );
$this->_config->save();
Util_Admin::redirect( array(
'w3tc_note' => 'flush_fragmentcache'
), true );
}
/**
* Flush minify action
*
* @return void
*/
function w3tc_flush_minify() {
$this->flush_minify();
$state_note = Dispatcher::config_state_note();
$state_note->set( 'minify.show_note.need_flush', false );
Util_Admin::redirect( array(
'w3tc_note' => 'flush_minify'
), true );
}
/**
* Flush browser cache action
*
* @return void
*/
function w3tc_flush_browser_cache() {
$cacheflush = Dispatcher::component( 'CacheFlush' );
$cacheflush->browsercache_flush();
$state_note = Dispatcher::config_state_note();
$state_note->set( 'common.show_note.flush_statics_needed', false );
$state_note->set( 'common.show_note.flush_posts_needed', true );
Util_Admin::redirect( array(
'w3tc_note' => 'flush_browser_cache'
), true );
}
/*
* Flush varnish cache
*/
function w3tc_flush_varnish() {
$this->flush_varnish();
Util_Admin::redirect( array(
'w3tc_note' => 'flush_varnish'
), true );
}
/*
* Flush CDN mirror
*/
function w3tc_flush_cdn() {
$this->flush_cdn();
Util_Admin::redirect( array(
'w3tc_note' => 'flush_cdn'
), true );
}
/**
* PgCache purge post
*
* @return void
*/
function w3tc_flush_post() {
$post_id = Util_Request::get_integer( 'post_id' );
w3tc_flush_post( $post_id );
Util_Admin::redirect( array(
'w3tc_note' => 'pgcache_purge_post'
), true );
}
/**
* Flush specified cache
*
* @param string $type
* @return void
*/
function flush( $type ) {
$state = Dispatcher::config_state();
$state_note = Dispatcher::config_state_note();
if ( $this->_config->get_string( 'pgcache.engine' ) == $type && $this->_config->get_boolean( 'pgcache.enabled' ) ) {
$state_note->set( 'common.show_note.flush_posts_needed', false );
$state_note->set( 'common.show_note.plugins_updated', false );
$this->flush_pgcache();
}
if ( $this->_config->get_string( 'dbcache.engine' ) == $type && $this->_config->get_boolean( 'dbcache.enabled' ) ) {
$this->flush_dbcache();
}
if ( $this->_config->get_string( 'objectcache.engine' ) == $type && $this->_config->get_boolean( 'objectcache.enabled' ) ) {
$this->flush_objectcache();
}
if ( $this->_config->get_string( array( 'fragmentcache', 'engine' ) ) == $type ) {
$this->flush_fragmentcache();
}
if ( $this->_config->get_string( 'minify.engine' ) == $type && $this->_config->get_boolean( 'minify.enabled' ) ) {
$state_note->set( 'minify.show_note.need_flush', false );
$this->flush_minify();
}
}
/**
* Flush memcached cache
*
* @return void
*/
function flush_memcached() {
$this->flush( 'memcached' );
}
/**
* Flush APC cache
*
* @return void
*/
function flush_opcode() {
$cacheflush = Dispatcher::component( 'CacheFlush' );
$cacheflush->opcache_flush();
}
/**
* Flush file cache
*
* @return void
*/
function flush_file() {
$this->flush( 'file' );
$this->flush( 'file_generic' );
}
/**
* Flush database cache
*
* @return void
*/
function flush_dbcache() {
$flusher = Dispatcher::component( 'CacheFlush' );
$flusher->dbcache_flush();
}
/**
* Flush object cache
*
* @return void
*/
function flush_objectcache() {
$flusher = Dispatcher::component( 'CacheFlush' );
$flusher->objectcache_flush();
}
/**
* Flush fragment cache
*/
function flush_fragmentcache() {
$flusher = Dispatcher::component( 'CacheFlush' );
$flusher->fragmentcache_flush();
}
/**
* Flush minify cache
*
* @return void
*/
function flush_minify() {
$w3_minify = Dispatcher::component( 'Minify_MinifiedFileRequestHandler' );
$w3_minify->flush();
}
/**
* Flush varnish cache
*/
function flush_varnish() {
// this attaches execute_delayed_operations! otherwise
// specific module flush will not have effect
$cacheflush = Dispatcher::component( 'CacheFlush' );
$varnishflush = Dispatcher::component( 'Varnish_Flush' );
$varnishflush->flush();
}
/**
* Flush CDN mirror
*/
function flush_cdn() {
$cacheflush = Dispatcher::component( 'CacheFlush' );
$cacheflush->cdn_purge_all();
}
private function _redirect_after_flush( $success_note ) {
$flush = Dispatcher::component( 'CacheFlush' );
$status = $flush->execute_delayed_operations();
$errors = array();
foreach ( $status as $i ) {
if ( isset( $i['error'] ) )
$errors[] = $i['error'];
}
if ( empty( $errors ) ) {
Util_Admin::redirect( array(
'w3tc_note' => $success_note
), true );
} else {
Util_Admin::redirect_with_custom_messages2( array(
'errors' => array( 'Failed to flush: ' .
implode( ', ', $errors ) )
), true );
}
}
}