function drush_cache_command_clear

8.0.x cache.drush.inc drush_cache_command_clear($type = NULL)
6.x cache.drush.inc drush_cache_command_clear($type = NULL)
7.x cache.drush.inc drush_cache_command_clear($type = NULL)
5.x cache.drush.inc drush_cache_command_clear($type = NULL)
master cache.drush.inc drush_cache_command_clear($type = NULL)

Command callback for drush cache-clear.

1 string reference to 'drush_cache_command_clear'
cache_drush_command in commands/core/cache.drush.inc
Implementation of hook_drush_command().

File

commands/core/cache.drush.inc, line 70

Code

function drush_cache_command_clear($type = NULL) {
  $types = drush_cache_clear_types(drush_has_boostrapped(DRUSH_BOOTSTRAP_DRUPAL_FULL));

  // Check if the provided type ($type) is a valid cache type.
  if ($type && !key_exists($type, $types)) {
    // If we haven't done a full bootstrap, provide a more
    // specific message with instructions to the user on
    // bootstrapping a Drupal site for more options.
    if (!drush_has_boostrapped(DRUSH_BOOTSTRAP_DRUPAL_FULL)) {
      $all_types = drush_cache_clear_types(TRUE);
      if (key_exists($type, $all_types)) {
        return drush_set_error(dt("'!type' cache requires a working Drupal site to operate on. Use the --root and --uri options, or a site @alias, or cd to a directory containing a Drupal settings.php file.", array('!type' => $type)));
      }
      else {
        return drush_set_error(dt("'!type' cache is not a valid cache type. There may be more cache types available if you select a working Drupal site.", array('!type' => $type)));
      }
    }
    return drush_set_error(dt("'!type' cache is not a valid cache type.", array('!type' => $type)));
  }

  if ($type) {
    drush_op($types[$type]);
    if ($type == 'all' && !drush_has_boostrapped(DRUSH_BOOTSTRAP_DRUPAL_FULL)) {
      $type = 'drush';
    }
  }
  else {
    // Don't offer 'all' unless Drush has bootstrapped the Drupal site
    if (!drush_has_boostrapped(DRUSH_BOOTSTRAP_DRUPAL_FULL)) {
      unset($types['all']);
    }
    $type = drush_choice($types, 'Enter a number to choose which cache to clear.', '!key');
    if ($type !== FALSE) {
      call_user_func($types[$type]);
    }
  }
  if ($type !== FALSE) {
    $site_label = '';
    if ($type != 'drush') {
      $self_name = drush_sitealias_bootstrapped_site_name();
      if (isset($self_name)) {
        $site_label = dt(' in !name', array('!name' => $self_name));
      }
    }
    drush_log(dt("'!name' cache was cleared!insitename", array('!name' => $type, '!insitename' => $site_label)), 'success');
  }
}