Skip to content

Commit 6cd1721

Browse files
author
maksek
committed
Merge pull request #949 from fcapua-summa/cli_cache_status
Added 'status' command for cache cli script (MAGETWO-32765)
2 parents 7cf9ebf + 0feee34 commit 6cd1721

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

dev/shell/cache.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,20 @@
1414

1515
$usage = 'Usage: php -f cache.php -- [--' . ManagerApp::KEY_SET . '=1|0]'
1616
. ' [--' . ManagerApp::KEY_CLEAN . ']'
17+
. ' [--' . ManagerApp::KEY_STATUS . ']'
1718
. ' [--' . ManagerApp::KEY_FLUSH . ']'
1819
. ' [--' . ManagerApp::KEY_TYPES . '=<type1>,<type2>,...]'
1920
. ' [--bootstrap=' . escapeshellarg('INIT_PARAM=foo&ANOTHER_PARAM[key]=bar') . ']
2021
--' . ManagerApp::KEY_TYPES . ' - list of cache types, comma-separated. If omitted, all caches will be affected
2122
--' . ManagerApp::KEY_SET . ' - enable or disable the specified cache types
2223
--' . ManagerApp::KEY_CLEAN . ' - clean data of the specified cache types
24+
--' . ManagerApp::KEY_STATUS . ' - display current status for each cache type
2325
--' . ManagerApp::KEY_FLUSH . ' - destroy all data in storage that the specified cache types reside on
2426
--bootstrap - add or override parameters of the bootstrap' . PHP_EOL;
2527
$longOpts = [
2628
ManagerApp::KEY_SET . '::',
2729
ManagerApp::KEY_CLEAN,
30+
ManagerApp::KEY_STATUS,
2831
ManagerApp::KEY_FLUSH,
2932
ManagerApp::KEY_TYPES . '::',
3033
'bootstrap::',

dev/tests/unit/testsuite/Magento/Framework/App/Cache/ManagerAppTest.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,17 @@ protected function setUp()
3131

3232
public function testLaunchStatus()
3333
{
34+
$requestArgs = [
35+
ManagerApp::KEY_STATUS => true
36+
];
37+
3438
$this->response->expects($this->once())
3539
->method('setBody')
3640
->with(
3741
$this->matches("Current status:%afoo: 1%abar: 1%abaz: 0")
3842
);
3943

40-
$model = new ManagerApp($this->cacheManager, $this->response, []);
44+
$model = new ManagerApp($this->cacheManager, $this->response, $requestArgs);
4145
$model->launch();
4246
}
4347

@@ -57,7 +61,7 @@ public function testLaunchEnable()
5761
$this->response->expects($this->once())
5862
->method('setBody')
5963
->with(
60-
$this->matches("Changed cache status:%abaz: 0 -> 1%aCleaned cache types: baz%a")
64+
$this->matches("Changed cache status:\n%abaz: 0 -> 1\nCleaned cache types:\nbaz")
6165
);
6266

6367
$model = new ManagerApp($this->cacheManager, $this->response, $requestArgs);
@@ -79,7 +83,7 @@ public function testLaunchDisable()
7983
$this->response->expects($this->once())
8084
->method('setBody')
8185
->with(
82-
$this->matches("Changed cache status:%abaz: 1 -> 0%a%a")
86+
$this->matches("Changed cache status:\n%abaz: 1 -> 0\n")
8387
);
8488

8589
$model = new ManagerApp($this->cacheManager, $this->response, $requestArgs);
@@ -102,7 +106,7 @@ public function testLaunchFlush()
102106
$this->response->expects($this->once())
103107
->method('setBody')
104108
->with(
105-
$this->matches("Flushed cache types: foo, bar%a")
109+
$this->matches("Flushed cache types:\nfoo\nbar")
106110
);
107111

108112
$model = new ManagerApp($this->cacheManager, $this->response, $requestArgs);
@@ -125,7 +129,7 @@ public function testLaunchClean()
125129
$this->response->expects($this->once())
126130
->method('setBody')
127131
->with(
128-
$this->matches("Cleaned cache types: foo, bar%a")
132+
$this->matches("Cleaned cache types:\nfoo\nbar")
129133
);
130134

131135
$model = new ManagerApp($this->cacheManager, $this->response, $requestArgs);
@@ -151,7 +155,7 @@ public function testLaunchSetAndClean()
151155
$this->response->expects($this->once())
152156
->method('setBody')
153157
->with(
154-
$this->matches("Changed cache status:%afoo: 0 -> 1%aCleaned cache types: foo, bar%a")
158+
$this->matches("Changed cache status:\n%afoo: 0 -> 1\nCleaned cache types:\nfoo\nbar")
155159
);
156160

157161
$model = new ManagerApp($this->cacheManager, $this->response, $requestArgs);
@@ -178,7 +182,7 @@ public function testLaunchAll()
178182
$this->response->expects($this->once())
179183
->method('setBody')
180184
->with(
181-
$this->matches("Changed cache status:%abaz: 0 -> 1%aFlushed cache types: foo, baz%a")
185+
$this->matches("Changed cache status:\n%abaz: 0 -> 1%aFlushed cache types:\nfoo\nbaz")
182186
);
183187

184188
$model = new ManagerApp($this->cacheManager, $this->response, $requestArgs);

lib/internal/Magento/Framework/App/Cache/ManagerApp.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class ManagerApp implements AppInterface
2121
const KEY_SET = 'set';
2222
const KEY_CLEAN = 'clean';
2323
const KEY_FLUSH = 'flush';
24+
const KEY_STATUS = 'status';
2425
/**#@- */
2526

2627
/**
@@ -88,18 +89,24 @@ public function launch()
8889
}
8990
if (isset($this->requestArgs[self::KEY_FLUSH])) {
9091
$this->cacheManager->flush($types);
91-
$output[] = 'Flushed cache types: ' . join(', ', $types);
92+
$output[] = 'Flushed cache types:';
93+
$output[] = join("\n", $types);
9294
} elseif (isset($this->requestArgs[self::KEY_CLEAN])) {
9395
$this->cacheManager->clean($types);
94-
$output[] = 'Cleaned cache types: ' . join(', ', $types);
96+
$output[] = 'Cleaned cache types:';
97+
$output[] = join("\n", $types);
98+
} elseif (isset($this->requestArgs[self::KEY_STATUS])) {
99+
$output[] = 'Current status:';
100+
foreach ($this->cacheManager->getStatus() as $cache => $status) {
101+
$output[] = sprintf('%30s: %d', $cache, $status);
102+
}
95103
} elseif (!empty($enabledTypes)) {
96104
$this->cacheManager->clean($enabledTypes);
97-
$output[] = 'Cleaned cache types: ' . join(', ', $enabledTypes);
98-
}
99-
$output[] = 'Current status:';
100-
foreach ($this->cacheManager->getStatus() as $cache => $status) {
101-
$output[] = sprintf('%30s: %d', $cache, $status);
105+
$output[] = 'Cleaned cache types:';
106+
$output[] = join("\n", $enabledTypes);
102107
}
108+
109+
$output[] = '';
103110
$this->response->setBody(join("\n", $output));
104111
return $this->response;
105112
}

0 commit comments

Comments
 (0)