function drush_apachesolr_solr_variable_set in Apache Solr Search 7
Same name and namespace in other branches
- 8 drush/apachesolr.drush.inc \drush_apachesolr_solr_variable_set()
- 6.3 drush/apachesolr.drush.inc \drush_apachesolr_solr_variable_set()
Command callback. Set a variable.
Parameters
string $arg_name:
mixed $value:
Return value
mixed
File
- drush/
apachesolr.drush.inc, line 453 - drush integration for apachesolr.
Code
function drush_apachesolr_solr_variable_set($arg_name, $value) {
$args = func_get_args();
if (!isset($value)) {
return drush_set_error('DRUSH_VARIABLE_ERROR', dt('No value specified.'));
}
$env_id = drush_get_option('id', apachesolr_default_environment());
try {
$found = _apachesolr_drush_variable_like($env_id, $arg_name, TRUE);
} catch (Exception $e) {
return drush_set_error('APACHESOLR_ENV_ID_ERROR', $e
->getMessage());
}
$options[] = "{$arg_name} " . dt('(new variable)');
$match = isset($found[$arg_name]);
if (!$match && $found) {
$options = array_merge($options, array_keys($found));
}
if ($value == '-') {
$value = stream_get_contents(STDIN);
}
// If the value is a string (usual case, unless we are called from code),
// then format the input
if (is_string($value)) {
$value = _apachesolr_drush_variable_format($value, drush_get_option('format', 'auto'));
}
// Format the output for display
if (is_array($value)) {
$display = "\n" . var_export($value, TRUE);
}
elseif (is_integer($value)) {
$display = $value;
}
elseif (is_bool($value)) {
$display = $value ? "TRUE" : "FALSE";
}
else {
$display = '"' . $value . '"';
}
$name = NULL;
if (drush_get_option('always-set', FALSE) || $match) {
$name = $arg_name;
}
else {
$choice = drush_choice($options, 'Enter a number to choose which variable to set.');
if ($choice !== FALSE) {
$name = $choice == 0 ? $arg_name : $options[$choice];
}
}
if ($name) {
drush_op('apachesolr_environment_variable_set', $env_id, $name, $value);
drush_log(dt('!name was set to !value', array(
'!name' => $name,
'!value' => $display,
)), 'success');
}
}