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.
Would it be possible to add a command that sets/unsets maintenance mode for one or more Drupal installations? We run many many Drupal sites on a multisite installation at work, and when upgrading Drupal it would be incredibly useful to be able to put all the sites into maintenance mode at once, rather than visiting each site. Setting a global maintenance mode message as well would be useful.
Comment | File | Size | Author |
---|---|---|---|
#29 | drush-variable.patch | 1.26 KB | John Morahan |
#25 | variables.patch | 6.64 KB | Jody Lynn |
#24 | variables_patch.patch | 451 bytes | clockworkrobot |
#18 | variables.patch | 6.46 KB | Jody Lynn |
#10 | drush_variable.diff | 2.73 KB | adrian |
Comments
Comment #1
moshe weitzman CreditAttribution: moshe weitzman commentedThis is certainly possible, and is a fine idea. Patches welcome.
Comment #2
adrian CreditAttribution: adrian commentedi was actually thinking a module which provides a mechanism to set any drupal variable.
Personally, all my settings.php files check for a global.inc , which they include, so i can set variables in one place for all of them (files directories, etc)
Comment #3
moshe weitzman CreditAttribution: moshe weitzman commentedwell said, adrian. adjusting title.
i also have used a global include file on a multi-site project.
Comment #4
moshe weitzman CreditAttribution: moshe weitzman commentedComment #5
moshe weitzman CreditAttribution: moshe weitzman commentedperhaps we go one step further and provide a 'php' command which lets you run any php you want (like devel.module block). in this case, it would be variable_set('maintainence', 1) or somesuch. then again, a dedicated command for maintainence is nice so you don't have to lookup variable names.
Comment #6
sprior CreditAttribution: sprior commentedToday I wrote some code which implements set a variable (it's not much code at all) and would like to contribute it to drush. The question is whether it should go in drush itself or drush_extras? As far as I know it would be version agnostic.
I've never contributed code to Drupal before, so learning the process for doing so will actually be bigger than the code itself. Can someone give an opinion on which of the 2 projects the code should go in and where to find instructions for submitting it?
Comment #7
moshe weitzman CreditAttribution: moshe weitzman commentedWe can put that in drush proper. Thanks.
Comment #8
sprior CreditAttribution: sprior commentedPatch attached to add setvar to core.
Comment #9
sprior CreditAttribution: sprior commentedpatch needs review.
Comment #10
adrian CreditAttribution: adrian commentedHere's an updated version of the patch with 'variable get' , 'variable set' and 'variable del' commands implemented.
Comment #11
moshe weitzman CreditAttribution: moshe weitzman commentedLooks good. But to my eyes, the command listing is getting long. How do we maintain sanity once Contrib starts piling on its commands? Any thoughts?
Comment #12
adrian CreditAttribution: adrian commentedumm. that's completely unavoidable.
it's a swiss army knife after all =)
Comment #13
moshe weitzman CreditAttribution: moshe weitzman commentedI added a --filter option for the help command so lets pile em on! Actually, lets turn this into 1 command with 3 operations.
Comment #14
adrian CreditAttribution: adrian commentedI am also considering adding support for json as the value , so you can set arrays and the like via the command line.
variable_get also needs to pretty print the output if it's an array and the like.
also need to pick up the difference between 'true' and true (ie: figure out and cast the input string correctly).
Comment #15
moshe weitzman CreditAttribution: moshe weitzman commentedComment #16
rsvelko CreditAttribution: rsvelko commented100% agree with #13.
Idea - if easy and useful we can borrow some code from devel module.
Question: these variable commands here - do they give me a listing or even better a searchable list of drupal variables?
(If not adding this seems easy with some php and mysql selects from the vars table.)
Comments?
PS Now with update.php invokation and maintanance mode - we are getting closer to the fully automatic updates of core and modules. Some more points from UPGRADE.txt and we are ready... :)
Comment #17
rsvelko CreditAttribution: rsvelko commentedQuote from #16:
" ...
Question: these variable commands here - do they give me a listing or even better a searchable list of drupal variables?
(If not adding this seems easy with some php and mysql selects from the vars table.)
..."
in drush_sm the code to list vars is ready - as well as some CCK and views export ... the maintainer wants to control these with CVS so he needed an export ...
Comment #18
Jody LynnI didn't find this issue until done coding drush variable integration, so this is a new patch, more code than the last one but also I think more useful. I wrote it to give me options when I don't know the exact variable name (essentially searchable as requested in comment 17).
Adrian's points in #14 are still issues somewhat, but I think it's workable as is.
This could be the shizz for avoiding config pages.
Comment #19
jonhattan@Jody Lynn: I think it would be of interest to allow searching variables containing the string, not only those that startswith(). Think of searching all variables related to "zen" or "file". Even better, it would be awesome to use the % wildcard on demand:
Note that current code already allows for wildcards as the argument is not cleaned up.
In addition a problem that can't be addressed is that some variables don't exist and a default value is used until they are set, as the maintenance mode variable. So you can't search what's the name of the maintenance mode variable. %offline%? %maintenance%?
Comment #20
moshe weitzman CreditAttribution: moshe weitzman commentedCould someone review this and we'll commit. ... I'd love to see the improvements from 14.
Comment #21
ezraw CreditAttribution: ezraw commentedPatched and tested #18. Tried, vdel, vset, and vget. Works as expected. Great feature additions. Thanks everyone.
Comment #22
devrand CreditAttribution: devrand commentedThanks for the great feature, i have tested the patch and it works for me also, at least vset and vget.
Can anyone tell me what the vset command is doing in detail?
E.g. for putting the site into offline mode, does it only log into the mysql db and sets the site_offline parameter of the variable table?
I'm only asking because someone pointed out some cache problems (maybe with cache_page, memcached) if doing this: http://samat.org/2008/10/31/taking-drupal-site-offline-mysql-and-command...
Comment #23
moshe weitzman CreditAttribution: moshe weitzman commenteduse drush_set_error(). this lets the script proceed in case rollback or other stuff is needed. Change later instances of drush_die() as well.
data changing operations should be called via drush_op(). that gives you automatic support for the --simulate feature.
confirmation messages should call drush_log() instead of drush_print(). that gets them properly recorded even when called by a remote drush instance.
again, use drush_op()
again, use drush_log()
This review is powered by Dreditor.
Comment #24
clockworkrobot CreditAttribution: clockworkrobot commented#18 patch looked the business, but I have been getting infinite looping when trying to set variables in a Drupal 5 environment.
A patch to the #18 variables.patch is attached which escapes the vset while loop when an exact match is found. This might need adjustment for the fuzzy search functionality.
Comment #25
Jody LynnThanks Moshe
Updated patch with Moshe's changes and added the performance improvement from #24 (it shouldn't need any adjustment)
Comment #26
ezrawolfe CreditAttribution: ezrawolfe commentedTested the vdel, vget and vset and it still works great for me.
Comment #27
Jody LynnComment #28
moshe weitzman CreditAttribution: moshe weitzman commentedI added expanded the names of each command and aliases vget, vset, vdel. Also documented the --yes feature. Finally, moved this all to a new variable.drush.inc in the core folder. Nice and clean.
Committed to HEAD. Thanks all.
Would be great to add some of the features from #14.
Comment #29
John Morahan CreditAttribution: John Morahan commentedlooks like the function names are not right for the new variable.drush.inc file
Comment #30
moshe weitzman CreditAttribution: moshe weitzman commentedcommitted. thx ... was a last second untested change by me.
Comment #32
gustavoiranzo CreditAttribution: gustavoiranzo commentedHow to use
Vget preprocess_css: "1"
I want to change from 1 to 0 ([347] : preprocess_css -- )
And run
drush -r /var/www/sitios/multidesa -l sitio1.arg vset
output list of variables
And
1)
Enter a number to choose which variable to set.
1
347
preprocess_css was set to [success]
An error occurred at function : drush_variable_variable_set
2)
Enter a number to choose which variable to set.
0
and output
Cancelled
An error occurred at function : drush_variable_variable_set [error]
[error]
Excuse me, could someone explain me how to change the variable preprocess_css eg from 1 to 0
Thank you very much for implementing the truth that saves me a lot of work, this very good drush.
Sorry my inglis.
Comment #33
gustavoiranzo CreditAttribution: gustavoiranzo commentedI apologize for asking to reopen this issue
Thank
Comment #34
moshe weitzman CreditAttribution: moshe weitzman commentedyou have to pass a variable name and value as arguments to the command. see `drush vset --help` for more detail
i just committed a fix which shows proper errors when you get this wrong
Comment #35
gustavoiranzo CreditAttribution: gustavoiranzo commentedthank you.
Comment #36
naught101 CreditAttribution: naught101 commentedfix for searching, etc.
Comment #37
apotek CreditAttribution: apotek commentedRemoved comment. Comment added to this feature request instead: http://drupal.org/node/664452#comment-3141974
Comment #38
John_Buehrer CreditAttribution: John_Buehrer commentedWhat if I want to manipulate a variable whose name is a prefix for other variables, but without any pattern matching? The context is automated scripting (under Unix), where there's no interactive user to make an informed choice.
I came up with some awkward workarounds.
Background: manipulate variable date_default_timezone:
Get:
Delete:
Add, if you know the variable doesn't already exist.
Modify, if you know the variable exists. This use-case already works as desired.
Comment #39
John_Buehrer CreditAttribution: John_Buehrer commentedI found a better workaround for scripting, though I still suggest a fix to the approach above.
Comment #40
John_Buehrer CreditAttribution: John_Buehrer commentedThe new http://drush.ws page mentions option --always-set (which does not appear in other docs). It unconditionally creates new variables, or modifies existing ones.
Caveats: I don't see how to force the timezone type to be integer rather than string, and this option seems not to work for vget and vdel.