Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 'status' command for cache cli script / Also improved readability ... #949

Merged
merged 2 commits into from
Jan 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dev/shell/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 . '=<type1>,<type2>,...]'
. ' [--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::',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
21 changes: 14 additions & 7 deletions lib/internal/Magento/Framework/App/Cache/ManagerApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ManagerApp implements AppInterface
const KEY_SET = 'set';
const KEY_CLEAN = 'clean';
const KEY_FLUSH = 'flush';
const KEY_STATUS = 'status';
/**#@- */

/**
Expand Down Expand Up @@ -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;
}
Expand Down