function views_drush_revert_views
Callback function for views-revert command.
1 string reference to 'views_drush_revert_views'
- views_drush_command in drush/
views.drush.inc - Implement hook_drush_command().
File
-
drush/
views.drush.inc, line 106
Code
function views_drush_revert_views() {
$views = views_get_all_views();
$i = 0;
// The provided views names specified in the command.
$viewnames = _convert_csv_to_array(func_get_args());
// Find all overridden views.
foreach ($views as $view) {
if ($view->disabled) {
continue;
}
if ($view->type == dt('Overridden')) {
$overridden[$view->name] = $view->name;
}
}
// Return early if there are no overridden views in the system.
if (empty($overridden)) {
return drush_set_error(dt('There are no overridden views in the system.'));
}
// If the user specified in the command the views to be overridden.
if (!empty($viewnames)) {
foreach ($viewnames as $key => $viewname) {
$is_overridden = key_exists($viewname, $overridden);
// Check if the provided view name is in the system
if ($viewname && !key_exists($viewname, $views)) {
drush_set_error(dt("'@viewname' view is not present in the system.", array(
'@viewname' => $viewname,
)));
}
elseif (!$is_overridden) {
drush_set_error(dt("The view specified '@viewname' is not overridden.", array(
'@viewname' => $viewname,
)));
}
elseif ($is_overridden) {
views_drush_revert_view($views[$viewname]);
$i++;
}
else {
drush_set_error(dt("The view specified '@viewname' is not provided in code, and thus cannot be reverted.", array(
'@viewname' => $viewname,
)));
}
}
}
else {
// list of choices for the user
$overridden['all'] = dt('Revert all overridden views');
// add a choice at the end
$choice = drush_choice($overridden, 'Enter a number to choose which view to revert.', '!key');
// prompt the user
if ($choice !== FALSE) {
// revert all views option
if ($choice == 'all') {
$i = views_drush_revert_allviews($views);
}
else {
views_drush_revert_view($views[$choice]);
$i++;
}
}
}
// final results output
if ($i == 0) {
drush_log(dt('No views were reverted.'), 'ok');
}
else {
drush_log(dt('Reverted a total of @count views.', array(
'@count' => $i,
)), 'ok');
}
}