|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* TFlushCachesAction class file |
|
4
|
|
|
* |
|
5
|
|
|
* @author Brad Anderson <[email protected]> |
|
6
|
|
|
* @link https://github.com/pradosoft/prado |
|
7
|
|
|
* @license https://github.com/pradosoft/prado/blob/master/LICENSE |
|
8
|
|
|
* @package Prado\Shell\Actions |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Prado\Shell\Actions; |
|
12
|
|
|
|
|
13
|
|
|
use Prado\Caching\ICache; |
|
14
|
|
|
use Prado\Shell\TShellAction; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* This command clears all application modules implementing ICache. |
|
18
|
|
|
* |
|
19
|
|
|
* @author Brad Anderson <belisoful[at]icloud[dot]com> |
|
20
|
|
|
* @package Prado\Shell\Actions |
|
21
|
|
|
* @since 4.2.0 |
|
22
|
|
|
*/ |
|
23
|
|
|
class TFlushCachesAction extends TShellAction |
|
24
|
|
|
{ |
|
25
|
|
|
protected $action = 'flushcaches'; |
|
26
|
|
|
protected $parameters = []; |
|
27
|
|
|
protected $optional = ['directory']; |
|
28
|
|
|
protected $description = 'Flushes all application TCache modules. Use case: upgrading a performance mode website by clearing out the old cache.'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param array $args parameters |
|
32
|
|
|
* @return bool |
|
33
|
|
|
*/ |
|
34
|
|
|
public function performAction($args) |
|
35
|
|
|
{ |
|
36
|
|
|
$app = null; |
|
|
|
|
|
|
37
|
|
|
if (count($args) <= 1) { |
|
38
|
|
|
$args[1] = '.'; |
|
39
|
|
|
} |
|
40
|
|
|
if (false === ($xml = $this->getAppConfigFile($args[1]))) { |
|
|
|
|
|
|
41
|
|
|
return false; |
|
42
|
|
|
} |
|
43
|
|
|
$app = $this->initializePradoApplication($args[1]); |
|
44
|
|
|
|
|
45
|
|
|
$app->onLoadState(); |
|
46
|
|
|
$app->onLoadStateComplete(); |
|
47
|
|
|
$cachesFlushed = []; |
|
48
|
|
|
foreach ($app->getModulesByType('Prado\\Caching\\ICache') as $id => $module) { |
|
49
|
|
|
$module = (!$module) ? $app->getModule($id) : $module; |
|
50
|
|
|
$module->flush(); |
|
51
|
|
|
$cachesFlushed[] = get_class($module); |
|
52
|
|
|
} |
|
53
|
|
|
$app->onSaveState(); |
|
54
|
|
|
$app->onSaveStateComplete(); |
|
55
|
|
|
if (!count($cachesFlushed)) { |
|
56
|
|
|
$cachesFlushed[] = 'no caches (none were found)'; |
|
57
|
|
|
} |
|
58
|
|
|
echo "** Application flushed " . implode(', ', $cachesFlushed) . "\n\n"; |
|
59
|
|
|
return true; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|