You are here

function apachesolr_drush_solr_delete_index in Apache Solr Search 7

Same name and namespace in other branches
  1. 8 drush/apachesolr.drush.inc \apachesolr_drush_solr_delete_index()
  2. 5.2 apachesolr.drush.inc \apachesolr_drush_solr_delete_index()
  3. 6.3 drush/apachesolr.drush.inc \apachesolr_drush_solr_delete_index()
  4. 6 drush/apachesolr.drush.inc \apachesolr_drush_solr_delete_index()
  5. 6.2 drush/apachesolr.drush.inc \apachesolr_drush_solr_delete_index()

Selectively delete content from the apachesolr index.

Each argument is a filter on what to delete from the index. They are of the form entity (to delete all content of that entity) or entity:bundle (to delete all content of that bundle).

1 string reference to 'apachesolr_drush_solr_delete_index'
apachesolr_drush_command in drush/apachesolr.drush.inc
Implements hook_drush_command().

File

drush/apachesolr.drush.inc, line 215
drush integration for apachesolr.

Code

function apachesolr_drush_solr_delete_index() {
  module_load_include('inc', 'apachesolr', 'apachesolr.index');
  $args = func_get_args();
  $env_id = drush_get_option('environment-id');
  if (empty($env_id)) {
    $env_id = apachesolr_default_environment();
  }
  if (count($args) > 0) {
    foreach ($args as $type) {
      $parts = explode(':', $type);
      if (count($parts) === 1) {
        $success = apachesolr_index_delete_index($env_id, $type);
      }
      elseif (count($parts) == 2) {
        $success = apachesolr_index_delete_index($env_id, $parts[0], $parts[1]);
      }
      else {
        drush_set_error(dt('The syntax for each type is either entity or entity:bundle'));
      }
    }
  }
  else {
    $success = apachesolr_index_delete_index($env_id);
  }
  if ($success) {
    drush_print(dt('Deleted the Solr index'));
  }
  else {
    drush_set_error(dt('An error occured while trying to delete the index.'));
  }
}