Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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!
Comment | File | Size | Author |
---|---|---|---|
#12 | drush-views-revert-documentation.patch | 1.56 KB | Manuel Garcia |
#7 | views-revert-drush4.patch | 10.07 KB | Manuel Garcia |
#3 | views-revert-drush3.patch | 5.02 KB | Manuel Garcia |
#1 | views-revert-drush2.patch | 5.02 KB | Manuel Garcia |
views-revert-drush.patch | 5.02 KB | Manuel Garcia | |
Comments
Comment #1
Manuel Garcia CreditAttribution: Manuel Garcia commentedHere 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)
Comment #2
dawehnerCan't we do a if (empty($view->disabled)) {
Comment #3
Manuel Garcia CreditAttribution: Manuel Garcia commentedTrue, changed that to be:
Comment #4
dwwI'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. ;)
Comment #5
dawehnerMade 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.
Comment #6
dwwHrm, 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. ;)
Comment #7
Manuel Garcia CreditAttribution: Manuel Garcia commentedI 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.
Comment #8
Manuel Garcia CreditAttribution: Manuel Garcia commentedhumm 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
Comment #9
Manuel Garcia CreditAttribution: Manuel Garcia commentedOK, 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.
Comment #10
dwwYeah, 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
Comment #11
Manuel Garcia CreditAttribution: Manuel Garcia commentedwell, the patch applies fine on 6.x-3-x.
Comment #12
Manuel Garcia CreditAttribution: Manuel Garcia commentedHere is a patch that adds some proper documentation and examples to the command.
drush help vr
Comment #13
Cyberwolf CreditAttribution: Cyberwolf commentedSubscribing.
Comment #14
dawehnerThanks. Stuf like this is quite helpful. Commited to both 6.x-3.x and 7.x-3.x
Comment #15
enboig CreditAttribution: enboig commentedIs it commited to 7.x-4.x?
Comment #16
dawehnerNo this is part of views.
Comment #19
colanThe issue for reverting all views with Drush can be found over at #1389720: Add support for "drush views-revert all".