Here is a patch which (hopefully) adds a new file, providing the drush command for reverting views.

It works like this:
drush views-revert
[prompts the user with a list of overridden views to choose from, or to revert all]

drush views-revert archive myview2
[reverts the two specified views]

I've tested it quite a bit, but further testing couldn't hurt. It has checks for making sure the view is in overridden, and stuff like that. A code review could not hurt either.

Note: I've created the patch using the instructions from the Git instructions tab, hopefully it will work!

Members fund testing for the Drupal project. Drupal Association Learn more

Comments

Manuel Garcia’s picture

FileSize
5.02 KB

Here is a reworked patch, with input from jonhattan.

- removed the command callback and used the default taken by drush
- removed calls to dt('Overridden'), assuming it's not needed.
- moved functions into _drush_function so to avoid name collisions
- initialized $overriden array (php 5.3)

dawehner’s picture


+    if ($view->disabled) continue;

Can't we do a if (empty($view->disabled)) {

Manuel Garcia’s picture

FileSize
5.02 KB

True, changed that to be:

 if (empty($view->disabled) && ($view->type == 'Overridden')) {
      $overridden[$view->name] = $view->name;
    }
dww’s picture

Issue tags: +drush

I'll definitely try to take a close look at this in the near future. This would be great!

Thanks,
-Derek

p.s. In the expectation that there will be more issues about drush support for various views things, tagging, too. ;)

dawehner’s picture

Status: Needs review » Fixed
Issue tags: -drush

Made some minor improvements: code style/some untranslated messages/@ as placeholder etc.

Commited it to all branches.

It's working perfect.
Especially the listing of available views to revert is awesome!!
Thanks for this patch.

dww’s picture

Status: Fixed » Needs work
Issue tags: +drush

Hrm, just looked now that this is committed. I think views_revert.drush.inc was a bad move. This should have just been added directly in views.drush.inc. Not the end of the world, but I think it's a lot cleaner that way.

Also, restoring the 'drush' tag, since I'm about to submit a bunch of new issues for this initiative based on a good IRC chat with manuee and dereine. ;)

Manuel Garcia’s picture

Status: Needs work » Needs review
FileSize
10.07 KB

I agree dww - hopefully views.drush.inc won't grow ultra large, but we'll see.

The attached patch does the following:
1. Moves the code from views_revert.drush.inc into views.drush.inc
2. Removes the file views_revert.drush.inc
3. Renames the function names into views_drush_FUNCTION, so as to have a safe namespace, and avoid potential collisions with views.

Manuel Garcia’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev

humm I forgot to mention that I made the patch against 7.x-3.x although I think it could apply fine on 6.x-3.x

Manuel Garcia’s picture

Status: Needs review » Needs work

OK, the game has changed since the new UI, and big merge has been committed to 3.x.

Views now uses ctools export api, so this means that:
1. drush views-revert now throws a fatal error:
PHP Fatal error: Call to undefined function views_object_cache_clear() in /home/manuel/htdocs/drupal7/sites/all/modules/views/views.drush.inc on line 153
2. My patch for drush ctools-revert now works with views: #1084062: Drush command to revert overridden ctools exported objects and renders the need for drush views-revert obsolete (if it goes in).

So I think we should perhaps work on that ctools patch a bit more to get it committed, and remove this one... at least from 7.x-3.x, not sure if 6.x-3.x also got the new exportables stuf.

dww’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev

Yeah, as a start, let's clean up 6.x-[23].x. We can return to D7 once the dust settles a bit more. ;)

Thanks!
-Derek

Manuel Garcia’s picture

Status: Needs work » Needs review

well, the patch applies fine on 6.x-3-x.

Manuel Garcia’s picture

Here is a patch that adds some proper documentation and examples to the command.

drush help vr

Cyberwolf’s picture

Subscribing.

dawehner’s picture

Status: Needs review » Fixed

Thanks. Stuf like this is quite helpful. Commited to both 6.x-3.x and 7.x-3.x

enboig’s picture

Is it commited to 7.x-4.x?

# git clone --branch 7.x-4.x http://git.drupal.org/project/drush.git
# drush views-revert
The drush command 'views-revert' could not be found.
dawehner’s picture

No this is part of views.

Status: Fixed » Closed (fixed)
Issue tags: -drush

Automatically closed -- issue fixed for 2 weeks with no activity.

colan’s picture

Issue summary: View changes

The issue for reverting all views with Drush can be found over at #1389720: Add support for "drush views-revert all".