function drush_views_data_export_validate in Views data export 7.4
Same name and namespace in other branches
- 6.3 views_data_export.drush.inc \drush_views_data_export_validate()
- 6 views_data_export.drush.inc \drush_views_data_export_validate()
- 6.2 views_data_export.drush.inc \drush_views_data_export_validate()
- 7 views_data_export.drush.inc \drush_views_data_export_validate()
- 7.3 views_data_export.drush.inc \drush_views_data_export_validate()
Implementation of drush_hook_COMMAND_validate().
File
- ./
views_data_export.drush.inc, line 62
Code
function drush_views_data_export_validate() {
// Because of a bug in the way that Drush 4 computes the name of functions to
// call from a Drush command, we may end up getting called twice, so we just
// don't do anything on subsequent invocations.
static $already_run = FALSE;
if ($already_run) {
return;
}
$already_run = TRUE;
$args = drush_get_arguments();
array_shift($args);
if (count($args) !== 3) {
return drush_set_error('ARGUMENTS_REQUIRED', dt('All arguments are required.'));
}
if (!($view = views_get_view($args[0]))) {
return drush_set_error('VIEW_DOES_NOT_EXIST', dt('The view !view does not exist.', array(
'!view' => $args[0],
)));
}
if (!$view
->set_display($args[1])) {
return drush_set_error('VIEW_DOES_NOT_EXIST', dt('The view !view does not have the !display display.', array(
'!view' => $args[0],
'!display' => $args[1],
)));
}
else {
if ($view->current_display != $args[1]) {
drush_log(dt('Using different display from specified display: @display', array(
'@display' => $view->current_display,
)), 'notice');
}
drush_set_option('views_data_export_display_id', $view->current_display);
}
$format = drush_get_option('format');
$valid_formats = array(
'csv',
'doc',
'txt',
'xls',
'xml',
);
if (!empty($format) && !in_array($format, $valid_formats)) {
return drush_set_error('VIEWS_DATA_EXPORT_INVALID_OPTION', dt('The "--format" option is invalid, please supply one of the following: !formats', array(
'!formats' => implode(', ', $valid_formats),
)));
}
}