Skip to content

Commit 2e30777

Browse files
author
Dale Sikkema
committed
Merge remote-tracking branch 'mainline/develop' into ext-s51
2 parents 644ea0e + 79e7ce6 commit 2e30777

File tree

301 files changed

+5059
-4621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

301 files changed

+5059
-4621
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Console\Command;
8+
9+
use Magento\Framework\App\Cache\Manager;
10+
use Symfony\Component\Console\Command\Command;
11+
use Symfony\Component\Console\Input\InputOption;
12+
13+
abstract class AbstractCacheCommand extends Command
14+
{
15+
/**
16+
* Input option bootsrap
17+
*/
18+
const INPUT_KEY_BOOTSTRAP = 'bootstrap';
19+
20+
/**
21+
* CacheManager
22+
*
23+
* @var Manager
24+
*/
25+
protected $cacheManager;
26+
27+
/**
28+
* Constructor
29+
*
30+
* @param Manager $cacheManager
31+
*/
32+
public function __construct(Manager $cacheManager)
33+
{
34+
$this->cacheManager = $cacheManager;
35+
parent::__construct();
36+
}
37+
38+
/**
39+
* {@inheritdoc}
40+
*/
41+
protected function configure()
42+
{
43+
$this->addOption(
44+
self::INPUT_KEY_BOOTSTRAP,
45+
null,
46+
InputOption::VALUE_REQUIRED,
47+
'add or override parameters of the bootstrap'
48+
);
49+
}
50+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Console\Command;
8+
9+
use Symfony\Component\Console\Input\InputArgument;
10+
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Input\InputOption;
12+
13+
abstract class AbstractCacheManageCommand extends AbstractCacheCommand
14+
{
15+
/**
16+
* Input argument types
17+
*/
18+
const INPUT_KEY_TYPES = 'types';
19+
20+
/**
21+
* Input key all
22+
*/
23+
const INPUT_KEY_ALL = 'all';
24+
25+
/**
26+
* {@inheritdoc}
27+
*/
28+
protected function configure()
29+
{
30+
$this->addArgument(
31+
self::INPUT_KEY_TYPES,
32+
InputArgument::IS_ARRAY,
33+
'List of cache types, space separated. If omitted, all caches will be affected'
34+
);
35+
$this->addOption(
36+
self::INPUT_KEY_ALL,
37+
null,
38+
InputOption::VALUE_NONE,
39+
'All cache types'
40+
);
41+
parent::configure();
42+
}
43+
44+
45+
/**
46+
* Get requested cache types
47+
*
48+
* @param InputInterface $input
49+
* @return array
50+
*/
51+
protected function getRequestedTypes(InputInterface $input)
52+
{
53+
$requestedTypes = [];
54+
if ($input->getArgument(self::INPUT_KEY_TYPES)) {
55+
$requestedTypes = $input->getArgument(self::INPUT_KEY_TYPES);
56+
$requestedTypes = array_filter(array_map('trim', $requestedTypes), 'strlen');
57+
}
58+
if (empty($requestedTypes)) {
59+
return [];
60+
} else {
61+
$availableTypes = $this->cacheManager->getAvailableTypes();
62+
$unsupportedTypes = array_diff($requestedTypes, $availableTypes);
63+
if ($unsupportedTypes) {
64+
throw new \InvalidArgumentException(
65+
"The following requested cache types are not supported: '" . join("', '", $unsupportedTypes)
66+
. "'." . PHP_EOL . 'Supported types: ' . join(", ", $availableTypes)
67+
);
68+
}
69+
return array_values(array_intersect($availableTypes, $requestedTypes));
70+
}
71+
}
72+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Console\Command;
8+
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
12+
abstract class AbstractCacheSetCommand extends AbstractCacheManageCommand
13+
{
14+
/**
15+
* Is enable cache or not
16+
*
17+
* @return bool
18+
*/
19+
abstract protected function isEnable();
20+
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
protected function execute(InputInterface $input, OutputInterface $output)
25+
{
26+
$isEnable = $this->isEnable();
27+
if ($input->getOption(self::INPUT_KEY_ALL)) {
28+
$types = $this->cacheManager->getAvailableTypes();
29+
} else {
30+
$types = $this->getRequestedTypes($input);
31+
}
32+
$changedTypes = $this->cacheManager->setEnabled($types, $isEnable);
33+
if ($changedTypes) {
34+
$output->writeln('Changed cache status:');
35+
foreach ($changedTypes as $type) {
36+
$output->writeln(sprintf('%30s: %d -> %d', $type, !$isEnable, $isEnable));
37+
}
38+
} else {
39+
$output->writeln('There is nothing to change in cache status');
40+
}
41+
if (!empty($changedTypes) && $isEnable) {
42+
$this->cacheManager->clean($changedTypes);
43+
$output->writeln('Cleaned cache types:');
44+
$output->writeln(join(PHP_EOL, $changedTypes));
45+
}
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Console\Command;
8+
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
12+
abstract class AbstractCacheTypeManageCommand extends AbstractCacheManageCommand
13+
{
14+
/**
15+
* Perform a cache management action on cache types
16+
*
17+
* @param array $cacheTypes
18+
* @return void
19+
*/
20+
abstract protected function performAction(array $cacheTypes);
21+
22+
/**
23+
* Get display message
24+
*
25+
* @return string
26+
*/
27+
abstract protected function getDisplayMessage();
28+
29+
/**
30+
* Perform cache management action
31+
*
32+
* @param InputInterface $input
33+
* @param OutputInterface $output
34+
* @return void
35+
*/
36+
protected function execute(InputInterface $input, OutputInterface $output)
37+
{
38+
if ($input->getOption(self::INPUT_KEY_ALL)) {
39+
$types = $this->cacheManager->getAvailableTypes();
40+
} else {
41+
$types = $this->getRequestedTypes($input);
42+
}
43+
$this->performAction($types);
44+
$output->writeln($this->getDisplayMessage());
45+
$output->writeln(join(PHP_EOL, $types));
46+
}
47+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Console\Command;
8+
9+
/**
10+
* Command for cleaning cache
11+
*/
12+
class CacheCleanCommand extends AbstractCacheTypeManageCommand
13+
{
14+
/**
15+
* {@inheritdoc}
16+
*/
17+
protected function configure()
18+
{
19+
$this->setName('cache:clean');
20+
$this->setDescription('Cleans cache type(s)');
21+
parent::configure();
22+
}
23+
24+
/**
25+
* Cleans cache types
26+
*
27+
* @param array $cacheTypes
28+
* @return void
29+
*/
30+
protected function performAction(array $cacheTypes)
31+
{
32+
$this->cacheManager->clean($cacheTypes);
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
protected function getDisplayMessage()
39+
{
40+
return 'Cleaned cache types:';
41+
}
42+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Console\Command;
8+
9+
/**
10+
* Command for disabling cache
11+
*/
12+
class CacheDisableCommand extends AbstractCacheSetCommand
13+
{
14+
/**
15+
* {@inheritdoc}
16+
*/
17+
protected function configure()
18+
{
19+
$this->setName('cache:disable');
20+
$this->setDescription('Disables cache type(s)');
21+
parent::configure();
22+
}
23+
24+
/**
25+
* Is Disable cache
26+
*
27+
* @return bool
28+
*/
29+
protected function isEnable()
30+
{
31+
return false;
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Console\Command;
8+
9+
/**
10+
* Command for enabling cache
11+
*/
12+
class CacheEnableCommand extends AbstractCacheSetCommand
13+
{
14+
/**
15+
* {@inheritdoc}
16+
*/
17+
protected function configure()
18+
{
19+
$this->setName('cache:enable');
20+
$this->setDescription('Enables cache type(s)');
21+
parent::configure();
22+
}
23+
24+
/**
25+
* Is enable cache
26+
*
27+
* @return bool
28+
*/
29+
protected function isEnable()
30+
{
31+
return true;
32+
}
33+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Console\Command;
8+
9+
/**
10+
* Command for flushing cache
11+
*/
12+
class CacheFlushCommand extends AbstractCacheTypeManageCommand
13+
{
14+
/**
15+
* {@inheritdoc}
16+
*/
17+
protected function configure()
18+
{
19+
$this->setName('cache:flush');
20+
$this->setDescription('Flushes cache storage used by cache type(s)');
21+
parent::configure();
22+
}
23+
24+
/**
25+
* Flushes cache types
26+
*
27+
* @param array $cacheTypes
28+
* @return void
29+
*/
30+
protected function performAction(array $cacheTypes)
31+
{
32+
$this->cacheManager->flush($cacheTypes);
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
protected function getDisplayMessage()
39+
{
40+
return 'Flushed cache types:';
41+
}
42+
}

0 commit comments

Comments
 (0)