You are here

function drush_apachesolr_solr_variable_delete in Apache Solr Search 8

Same name and namespace in other branches
  1. 6.3 drush/apachesolr.drush.inc \drush_apachesolr_solr_variable_delete()
  2. 7 drush/apachesolr.drush.inc \drush_apachesolr_solr_variable_delete()

Command callback. Delete a variable.

Parameters

$arg_name:

Return value

string

File

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

Code

function drush_apachesolr_solr_variable_delete($arg_name) {
  $env_id = drush_get_option('id', apachesolr_default_environment());

  // Look for similar variable names.
  try {
    $found = _apachesolr_drush_variable_like($env_id, $arg_name, TRUE);
  } catch (Exception $e) {
    return drush_set_error('APACHESOLR_ENV_ID_ERROR', $e
      ->getMessage());
  }
  drush_log(dt('Using environment ID "!env_id"', array(
    '!env_id' => $env_id,
  )), 'success');
  $options = array_keys($found);
  if (drush_get_option('exact', FALSE)) {
    $options = isset($found[$arg_name]) ? array(
      $arg_name,
    ) : array();
  }
  if (empty($options)) {
    drush_print(dt('!name not found.', array(
      '!name' => $arg_name,
    )));
    return '';
  }
  $name = NULL;
  if (count($options) == 1 && drush_get_context('DRUSH_AFFIRMATIVE')) {
    $name = $arg_name;
  }
  else {
    $choice = drush_choice($options, 'Enter a number to choose which variable to delete.');
    if ($choice !== FALSE) {
      $name = $options[$choice];
    }
  }
  if ($name) {
    drush_op('apachesolr_environment_variable_del', $env_id, $name);
    drush_log(dt('!choice was deleted.', array(
      '!choice' => $name,
    )), 'success');
  }
}