From b18677f6b6d4e4debdf9ff76470a4f6db7341da3 Mon Sep 17 00:00:00 2001 From: Facundo Capua Date: Wed, 24 Dec 2014 10:26:36 -0300 Subject: [PATCH 1/2] Added 'status' command for cache cli script / Also improved readability in output messages --- dev/shell/cache.php | 3 +++ .../Framework/App/Cache/ManagerAppTest.php | 18 +++++++++------- .../Framework/App/Cache/ManagerApp.php | 21 ++++++++++++------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/dev/shell/cache.php b/dev/shell/cache.php index 91724bbb25c24..f6bc3066b0789 100644 --- a/dev/shell/cache.php +++ b/dev/shell/cache.php @@ -14,17 +14,20 @@ $usage = 'Usage: php -f cache.php -- [--' . ManagerApp::KEY_SET . '=1|0]' . ' [--' . ManagerApp::KEY_CLEAN . ']' + . ' [--' . ManagerApp::KEY_STATUS . ']' . ' [--' . ManagerApp::KEY_FLUSH . ']' . ' [--' . ManagerApp::KEY_TYPES . '=,,...]' . ' [--bootstrap=' . escapeshellarg('INIT_PARAM=foo&ANOTHER_PARAM[key]=bar') . '] --' . ManagerApp::KEY_TYPES . ' - list of cache types, comma-separated. If omitted, all caches will be affected --' . ManagerApp::KEY_SET . ' - enable or disable the specified cache types --' . ManagerApp::KEY_CLEAN . ' - clean data of the specified cache types + --' . ManagerApp::KEY_STATUS . ' - display current status for each cache type --' . ManagerApp::KEY_FLUSH . ' - destroy all data in storage that the specified cache types reside on --bootstrap - add or override parameters of the bootstrap' . PHP_EOL; $longOpts = [ ManagerApp::KEY_SET . '::', ManagerApp::KEY_CLEAN, + ManagerApp::KEY_STATUS, ManagerApp::KEY_FLUSH, ManagerApp::KEY_TYPES . '::', 'bootstrap::', diff --git a/dev/tests/unit/testsuite/Magento/Framework/App/Cache/ManagerAppTest.php b/dev/tests/unit/testsuite/Magento/Framework/App/Cache/ManagerAppTest.php index 8ab5f43b9a294..29a0c808a2296 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/App/Cache/ManagerAppTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/App/Cache/ManagerAppTest.php @@ -31,13 +31,17 @@ protected function setUp() public function testLaunchStatus() { + $requestArgs = [ + ManagerApp::KEY_STATUS => true + ]; + $this->response->expects($this->once()) ->method('setBody') ->with( $this->matches("Current status:%afoo: 1%abar: 1%abaz: 0") ); - $model = new ManagerApp($this->cacheManager, $this->response, []); + $model = new ManagerApp($this->cacheManager, $this->response, $requestArgs); $model->launch(); } @@ -57,7 +61,7 @@ public function testLaunchEnable() $this->response->expects($this->once()) ->method('setBody') ->with( - $this->matches("Changed cache status:%abaz: 0 -> 1%aCleaned cache types: baz%a") + $this->matches("Changed cache status:\n%abaz: 0 -> 1\nCleaned cache types:\nbaz") ); $model = new ManagerApp($this->cacheManager, $this->response, $requestArgs); @@ -79,7 +83,7 @@ public function testLaunchDisable() $this->response->expects($this->once()) ->method('setBody') ->with( - $this->matches("Changed cache status:%abaz: 1 -> 0%a%a") + $this->matches("Changed cache status:\n%abaz: 1 -> 0\n") ); $model = new ManagerApp($this->cacheManager, $this->response, $requestArgs); @@ -102,7 +106,7 @@ public function testLaunchFlush() $this->response->expects($this->once()) ->method('setBody') ->with( - $this->matches("Flushed cache types: foo, bar%a") + $this->matches("Flushed cache types:\nfoo\nbar") ); $model = new ManagerApp($this->cacheManager, $this->response, $requestArgs); @@ -125,7 +129,7 @@ public function testLaunchClean() $this->response->expects($this->once()) ->method('setBody') ->with( - $this->matches("Cleaned cache types: foo, bar%a") + $this->matches("Cleaned cache types:\nfoo\nbar") ); $model = new ManagerApp($this->cacheManager, $this->response, $requestArgs); @@ -151,7 +155,7 @@ public function testLaunchSetAndClean() $this->response->expects($this->once()) ->method('setBody') ->with( - $this->matches("Changed cache status:%afoo: 0 -> 1%aCleaned cache types: foo, bar%a") + $this->matches("Changed cache status:\n%afoo: 0 -> 1\nCleaned cache types:\nfoo\nbar") ); $model = new ManagerApp($this->cacheManager, $this->response, $requestArgs); @@ -178,7 +182,7 @@ public function testLaunchAll() $this->response->expects($this->once()) ->method('setBody') ->with( - $this->matches("Changed cache status:%abaz: 0 -> 1%aFlushed cache types: foo, baz%a") + $this->matches("Changed cache status:\n%abaz: 0 -> 1%aFlushed cache types:\nfoo\nbaz") ); $model = new ManagerApp($this->cacheManager, $this->response, $requestArgs); diff --git a/lib/internal/Magento/Framework/App/Cache/ManagerApp.php b/lib/internal/Magento/Framework/App/Cache/ManagerApp.php index a8c035ff01524..5a941e9885cdc 100644 --- a/lib/internal/Magento/Framework/App/Cache/ManagerApp.php +++ b/lib/internal/Magento/Framework/App/Cache/ManagerApp.php @@ -21,6 +21,7 @@ class ManagerApp implements AppInterface const KEY_SET = 'set'; const KEY_CLEAN = 'clean'; const KEY_FLUSH = 'flush'; + const KEY_STATUS = 'status'; /**#@- */ /** @@ -88,18 +89,24 @@ public function launch() } if (isset($this->requestArgs[self::KEY_FLUSH])) { $this->cacheManager->flush($types); - $output[] = 'Flushed cache types: ' . join(', ', $types); + $output[] = 'Flushed cache types:'; + $output[] = join("\n", $types); } elseif (isset($this->requestArgs[self::KEY_CLEAN])) { $this->cacheManager->clean($types); - $output[] = 'Cleaned cache types: ' . join(', ', $types); + $output[] = 'Cleaned cache types:'; + $output[] = join("\n", $types); + } elseif (isset($this->requestArgs[self::KEY_STATUS])){ + $output[] = 'Current status:'; + foreach ($this->cacheManager->getStatus() as $cache => $status) { + $output[] = sprintf('%30s: %d', $cache, $status); + } } elseif (!empty($enabledTypes)) { $this->cacheManager->clean($enabledTypes); - $output[] = 'Cleaned cache types: ' . join(', ', $enabledTypes); - } - $output[] = 'Current status:'; - foreach ($this->cacheManager->getStatus() as $cache => $status) { - $output[] = sprintf('%30s: %d', $cache, $status); + $output[] = 'Cleaned cache types:'; + $output[] = join("\n", $enabledTypes); } + + $output[] = ''; $this->response->setBody(join("\n", $output)); return $this->response; } From 0feee34fb255b47e5e2384025fa96d073aaf4ef6 Mon Sep 17 00:00:00 2001 From: Facundo Capua Date: Wed, 24 Dec 2014 12:55:12 -0300 Subject: [PATCH 2/2] Fix code format --- lib/internal/Magento/Framework/App/Cache/ManagerApp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/App/Cache/ManagerApp.php b/lib/internal/Magento/Framework/App/Cache/ManagerApp.php index 5a941e9885cdc..12911084c4b2d 100644 --- a/lib/internal/Magento/Framework/App/Cache/ManagerApp.php +++ b/lib/internal/Magento/Framework/App/Cache/ManagerApp.php @@ -95,7 +95,7 @@ public function launch() $this->cacheManager->clean($types); $output[] = 'Cleaned cache types:'; $output[] = join("\n", $types); - } elseif (isset($this->requestArgs[self::KEY_STATUS])){ + } elseif (isset($this->requestArgs[self::KEY_STATUS])) { $output[] = 'Current status:'; foreach ($this->cacheManager->getStatus() as $cache => $status) { $output[] = sprintf('%30s: %d', $cache, $status);