|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2016 |
|
6
|
|
|
* @package Slim |
|
7
|
|
|
* @subpackage Command |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Aimeos\Slim\Command; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Aimeos cache command class |
|
15
|
|
|
* |
|
16
|
|
|
* @package Slim |
|
17
|
|
|
* @subpackage Command |
|
18
|
|
|
*/ |
|
19
|
|
|
class Cache extends Base implements Iface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Returns the command usage and options |
|
23
|
|
|
* |
|
24
|
|
|
* @return string Command usage and options |
|
25
|
|
|
*/ |
|
26
|
|
|
public static function usage() : string |
|
27
|
|
|
{ |
|
28
|
|
|
return "Usage: php cache.php [--extdir=<path>]* [--config=<path>|<file>]* [\"sitecode1 [sitecode2]*\"]\n"; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Executes the command |
|
34
|
|
|
* |
|
35
|
|
|
* @param array $argv Associative array from $_SERVER['argv'] |
|
36
|
|
|
*/ |
|
37
|
|
|
public static function run( array $argv ) |
|
38
|
|
|
{ |
|
39
|
|
|
array_shift( $argv ); |
|
40
|
|
|
$options = self::getOptions( $argv ); |
|
41
|
|
|
$sites = array_shift( $argv ); |
|
42
|
|
|
|
|
43
|
|
|
$extdirs = ( isset( $options['extdir'] ) ? (array) $options['extdir'] : array() ); |
|
44
|
|
|
$aimeos = new \Aimeos\Bootstrap( $extdirs ); |
|
45
|
|
|
|
|
46
|
|
|
$ctx = self::getContext( $aimeos->getConfigPaths(), $options ); |
|
47
|
|
|
$siteItems = self::getSiteItems( $ctx, $sites ); |
|
48
|
|
|
|
|
49
|
|
|
self::clear( $ctx, $siteItems ); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Returns a new context object |
|
55
|
|
|
* |
|
56
|
|
|
* @param array $confPaths List of configuration paths from the bootstrap object |
|
57
|
|
|
* @param array $options Associative list of configuration options as key/value pairs |
|
58
|
|
|
* @return \Aimeos\MShop\Context\Item\Iface Context object |
|
59
|
|
|
*/ |
|
60
|
|
|
protected static function getContext( array $confPaths, array $options ) : \Aimeos\MShop\Context\Item\Iface |
|
61
|
|
|
{ |
|
62
|
|
|
$config = array(); |
|
63
|
|
|
$ctx = new \Aimeos\MShop\Context\Item\Standard(); |
|
64
|
|
|
|
|
65
|
|
|
if( isset( $options['config'] ) ) |
|
66
|
|
|
{ |
|
67
|
|
|
foreach( (array) $options['config'] as $path ) |
|
68
|
|
|
{ |
|
69
|
|
|
if( is_file( $path ) ) { |
|
70
|
|
|
$config = array_replace_recursive( $config, require $path ); |
|
71
|
|
|
} else { |
|
72
|
|
|
$confPaths[] = $path; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$conf = new \Aimeos\MW\Config\PHPArray( $config, $confPaths ); |
|
78
|
|
|
$conf = new \Aimeos\MW\Config\Decorator\Memory( $conf ); |
|
79
|
|
|
|
|
80
|
|
|
if( ( $cfg = $conf->get( 'command' ) ) !== null ) { |
|
81
|
|
|
$conf = new \Aimeos\MW\Config\Decorator\Memory( $conf, $cfg ); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$ctx->setConfig( $conf ); |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
$dbm = new \Aimeos\MW\DB\Manager\PDO( $conf ); |
|
88
|
|
|
$ctx->setDatabaseManager( $dbm ); |
|
89
|
|
|
|
|
90
|
|
|
$logger = new \Aimeos\MW\Logger\Errorlog( \Aimeos\MW\Logger\Base::INFO ); |
|
91
|
|
|
$ctx->setLogger( $logger ); |
|
92
|
|
|
|
|
93
|
|
|
return $ctx; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Removes the cached data for the given sites |
|
99
|
|
|
* |
|
100
|
|
|
* @param \Aimeos\MShop\Context\Item\Iface $ctx Context object |
|
101
|
|
|
* @param \Aimeos\Map $siteItems List of site items implementing \Aimeos\MShop\Locale\Site\Iface |
|
102
|
|
|
*/ |
|
103
|
|
|
protected static function clear( \Aimeos\MShop\Context\Item\Iface $ctx, \Aimeos\Map $siteItems ) |
|
104
|
|
|
{ |
|
105
|
|
|
$localeManager = \Aimeos\MShop::create( $ctx, 'locale' ); |
|
106
|
|
|
|
|
107
|
|
|
foreach( $siteItems as $siteItem ) |
|
108
|
|
|
{ |
|
109
|
|
|
$localeItem = $localeManager->bootstrap( $siteItem->getCode(), '', '', false ); |
|
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
$lcontext = clone $ctx; |
|
112
|
|
|
$lcontext->setLocale( $localeItem ); |
|
113
|
|
|
|
|
114
|
|
|
$cache = new \Aimeos\MAdmin\Cache\Proxy\Standard( $lcontext ); |
|
115
|
|
|
$lcontext->setCache( $cache ); |
|
116
|
|
|
|
|
117
|
|
|
printf( "Clearing the Aimeos cache for site \"%1\$s\"\n", $siteItem->getCode() ); |
|
118
|
|
|
|
|
119
|
|
|
\Aimeos\MAdmin::create( $lcontext, 'cache' )->getCache()->clear(); |
|
|
|
|
|
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
} |