Completed
Push — master ( b6ebb2...06767e )
by Aimeos
01:46
created

CacheCommand::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2015-2016
6
 * @package laravel
7
 * @subpackage Command
8
 */
9
10
11
namespace Aimeos\Shop\Command;
12
13
use Symfony\Component\Console\Input\InputArgument;
14
15
16
/**
17
 * Command for clearing the content cache
18
 * @package laravel
19
 * @subpackage Command
20
 */
21
class CacheCommand extends AbstractCommand
22
{
23
	/**
24
	 * The name and signature of the console command.
25
	 *
26
	 * @var string
27
	 */
28
	protected $signature = 'aimeos:cache
29
		{site? : Site codes to clear the Aimeos content cache for like "default unittest" (none for all)}
30
	';
31
32
	/**
33
	 * The console command description.
34
	 *
35
	 * @var string
36
	 */
37
	protected $description = 'Clears the content cache';
38
39
40
	/**
41
	 * Execute the console command.
42
	 *
43
	 * @return mixed
44
	 */
45
	public function handle()
46
	{
47
		$context = $this->getLaravel()->make( 'Aimeos\Shop\Base\Context' )->get( false, 'command' );
48
		$context->setEditor( 'aimeos:cache' );
49
50
		$localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $context );
51
52
		foreach( $this->getSiteItems( $context, $this->argument( 'site' ) ) as $siteItem )
53
		{
54
			$localeItem = $localeManager->bootstrap( $siteItem->getCode(), '', '', false );
55
56
			$lcontext = clone $context;
57
			$lcontext->setLocale( $localeItem );
58
59
			$cache = new \Aimeos\MAdmin\Cache\Proxy\Standard( $lcontext );
60
			$lcontext->setCache( $cache );
61
62
			$this->info( sprintf( 'Clearing the Aimeos cache for site "%1$s"', $siteItem->getCode() ) );
63
64
			\Aimeos\MAdmin\Cache\Manager\Factory::createManager( $lcontext )->getCache()->clear();
65
		}
66
	}
67
}
68