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

Handle incorrect cache argument #396

Merged
Merged
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
20 changes: 15 additions & 5 deletions commands/cache.bee.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ function cache_bee_command() {
'callback' => 'cache_clear_bee_command',
'group' => 'miscellaneous',
'arguments' => array(
'cache' => bt('The name of the cache to clear. Leave blank to see a list of available caches.'),
'cache' => bt('The name of the cache to clear (not case sensitive). Leave blank to see a list of available caches.'),
),
'optional_arguments' => array('cache'),
'aliases' => array('cc'),
'bootstrap' => BEE_BOOTSTRAP_FULL,
'examples' => array(
'bee cache-clear menu' => bt('Clear the menu cache.'),
'bee cache-clear all' => bt('Clear all caches.'),
'bee cache-clear css_js' => bt('Clear the CSS & JS cache.'),
'bee cache-clear' => bt('Select the cache to clear from a list of available ones.'),
),
),
Expand All @@ -36,7 +37,7 @@ function cache_clear_bee_command($arguments, $options) {
$cache_list = array(
'all' => bt('All'),
'core' => bt('Core (page, admin bar, etc.)'),
'css_js' => bt('CSS & JS'),
'css_js' => bt('CSS & JS [css_js]'),
'entity' => bt('Entity'),
'layout' => bt('Layout'),
'menu' => bt('Menu'),
Expand All @@ -47,10 +48,19 @@ function cache_clear_bee_command($arguments, $options) {
);

// Get the cache to clear.
if (isset($arguments['cache'])) {
$cache = $arguments['cache'];
$cache = isset($arguments['cache']) ? strtolower($arguments['cache']) : NULL;

// Check the cache.
if (!is_null($cache) && !isset($cache_list[$cache])) {
bee_instant_message(bt("'!cache' is not a valid cache to clear.", array(
"!cache" => $cache,
)) . "\n", 'warning'); // Add additional linebreak before select list.
$cache = NULL;
}
else {

// If either no cache was entered or an invalid cache was entered, offer a
// choice of caches to clear.
if (is_null($cache)) {
$cache = bee_choice($cache_list, bt('Select a cache to clear:'), 'all');
}

Expand Down
Loading