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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moshe weitzman’s picture

This is certainly possible, and is a fine idea. Patches welcome.

adrian’s picture

i 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)

moshe weitzman’s picture

Title: Maintenance mode for multi-site installations » Set a variable (e.g. Maintenance mode)

well said, adrian. adjusting title.

i also have used a global include file on a multi-site project.

moshe weitzman’s picture

Title: Set a variable (e.g. Maintenance mode) » Permanently set a variable (e.g. Maintenance mode)
moshe weitzman’s picture

perhaps 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.

sprior’s picture

Today 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?

moshe weitzman’s picture

We can put that in drush proper. Thanks.

sprior’s picture

FileSize
2.08 KB

Patch attached to add setvar to core.

sprior’s picture

Status: Active » Needs review

patch needs review.

adrian’s picture

FileSize
2.73 KB

Here's an updated version of the patch with 'variable get' , 'variable set' and 'variable del' commands implemented.

moshe weitzman’s picture

Looks 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?

adrian’s picture

umm. that's completely unavoidable.

it's a swiss army knife after all =)

moshe weitzman’s picture

Status: Needs review » Needs work

I added a --filter option for the help command so lets pile em on! Actually, lets turn this into 1 command with 3 operations.

adrian’s picture

I 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).

moshe weitzman’s picture

Assigned: Unassigned » adrian
rsvelko’s picture

100% 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... :)

rsvelko’s picture

Quote 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 ...

Jody Lynn’s picture

Title: Permanently set a variable (e.g. Maintenance mode) » Drush Get, Set, and Delete variables
Status: Needs work » Needs review
FileSize
6.46 KB

I 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.

jonhattan’s picture

@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:

drush vget file
drush vget file%
drush vget %file%
drush vget %file%_%

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%?

moshe weitzman’s picture

Could someone review this and we'll commit. ... I'd love to see the improvements from 14.

ezraw’s picture

Status: Needs review » Reviewed & tested by the community

Patched and tested #18. Tried, vdel, vset, and vget. Works as expected. Great feature additions. Thanks everyone.

devrand’s picture

Thanks 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...

moshe weitzman’s picture

Status: Reviewed & tested by the community » Needs work
+++ commands/core/core.drush.inc	9 Aug 2009 21:01:25 -0000
@@ -439,3 +476,139 @@ function drush_core_watchdog_delete($typ
+    drush_die('No variable specified');

use drush_set_error(). this lets the script proceed in case rollback or other stuff is needed. Change later instances of drush_die() as well.

+++ commands/core/core.drush.inc	9 Aug 2009 21:01:25 -0000
@@ -439,3 +476,139 @@ function drush_core_watchdog_delete($typ
+    variable_set($args[0], $value);

data changing operations should be called via drush_op(). that gives you automatic support for the --simulate feature.

+++ commands/core/core.drush.inc	9 Aug 2009 21:01:25 -0000
@@ -439,3 +476,139 @@ function drush_core_watchdog_delete($typ
+    drush_print(dt('!name was set to !value.', array('!name' => $args[0], '!value' => $value)));

confirmation messages should call drush_log() instead of drush_print(). that gets them properly recorded even when called by a remote drush instance.

+++ commands/core/core.drush.inc	9 Aug 2009 21:01:25 -0000
@@ -439,3 +476,139 @@ function drush_core_watchdog_delete($typ
+        variable_set($choice, $value);

again, use drush_op()

+++ commands/core/core.drush.inc	9 Aug 2009 21:01:25 -0000
@@ -439,3 +476,139 @@ function drush_core_watchdog_delete($typ
+        drush_print(dt('!name was set to !value', array('!name' => $choice, '!value' => $value)));

again, use drush_log()

This review is powered by Dreditor.

clockworkrobot’s picture

FileSize
451 bytes

#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.

Jody Lynn’s picture

Status: Needs work » Needs review
FileSize
6.64 KB

Thanks Moshe

Updated patch with Moshe's changes and added the performance improvement from #24 (it shouldn't need any adjustment)

ezrawolfe’s picture

Tested the vdel, vget and vset and it still works great for me.

Jody Lynn’s picture

Status: Needs review » Reviewed & tested by the community
moshe weitzman’s picture

Status: Reviewed & tested by the community » Fixed

I 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.

John Morahan’s picture

Status: Fixed » Needs review
FileSize
1.26 KB

looks like the function names are not right for the new variable.drush.inc file

moshe weitzman’s picture

Status: Needs review » Fixed

committed. thx ... was a last second untested change by me.

Status: Fixed » Closed (fixed)

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

gustavoiranzo’s picture

Title: Drush Get, Set, and Delete variables » How to use

How 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.

gustavoiranzo’s picture

Title: How to use » How to use ?
Status: Closed (fixed) » Active

I apologize for asking to reopen this issue
Thank

moshe weitzman’s picture

Status: Active » Closed (fixed)

you 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

gustavoiranzo’s picture

thank you.

drush help vset
Set a variable

Examples:
 drush vset --yes preprocess_css 1         Set the preprocess_css variable to true. Skip confirmation.
 drush vset pr 1                           Choose from a list of variables beginning with "pr" to set to true.

Arguments:
 name                                      The name of a variable or the first few letters of its name.
 value                                     The value to assign to the variable.

Options:
 --yes                                     Skip confirmation if only one variable name matches.
naught101’s picture

Title: How to use ? » Drush Get, Set, and Delete variables

fix for searching, etc.

apotek’s picture

Removed comment. Comment added to this feature request instead: http://drupal.org/node/664452#comment-3141974

John_Buehrer’s picture

Title: Drush Get, Set, and Delete variables » Drush Get, Set, and Delete variables - A way to be exact?
Component: Code » PM (dl, en, up ...)

What 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:

$ alias dr='drush -r /Applications/MAMP/htdocs/my_site/'

$ dr vget date_default_timezone
date_default_timezone_name: "s:13:"Europe/Zurich";"
date_default_timezone: "i:7200;"

Get:

$ dr vget date_default_timezone | grep date_default_timezone:
date_default_timezone: "i:7200;"

Delete:

$ num=`echo 0 | dr vdel date_default_timezone | perl -ne 'next unless /\[(\d+)\] :\s+date_default_timezone\s*$/; print "$1\n";'`

$ echo $num | dr vdel date_default_timezone
Enter a number to choose which variable to delete.
  [0] : Cancel
  [1] : date_default_timezone
  [2] : date_default_timezone_name
date_default_timezone was deleted.                                                           [success]

Add, if you know the variable doesn't already exist.

$ echo 1 | dr vset -y date_default_timezone 'i:7200;'
Enter a number to choose which variable to set.
  [0] : Cancel
  [1] : date_default_timezone (new variable)
  [2] : date_default_timezone_name
date_default_timezone was set to i:7200;                                                     [success]

Modify, if you know the variable exists. This use-case already works as desired.

$ dr vset -y date_default_timezone 'i:10800;'
date_default_timezone was set to i:10800;.                                                    [success]
John_Buehrer’s picture

I found a better workaround for scripting, though I still suggest a fix to the approach above.

$ dr php-eval 'echo variable_get("date_default_timezone", "UNSET"). "\n";'
7200

# -- Put the value in quotes (eg, "10800") to get type=string
$ dr php-eval 'variable_set("date_default_timezone", 10800);' 
$ dr php-eval 'echo variable_get("date_default_timezone", "UNSET"). "\n";'
10800
 
$ dr php-eval 'variable_del("date_default_timezone");'
$ dr php-eval 'echo variable_get("date_default_timezone", "UNSET"). "\n";'
UNSET

$ dr php-eval 'variable_set("date_default_timezone", 7200);'
$ dr php-eval 'echo variable_get("date_default_timezone", "UNSET"). "\n";'
7200

# -- FYI - What's really in the DB:
$ dr sqlq "SELECT * FROM variable WHERE name='date_default_timezone';"
name	value
date_default_timezone	i:7200;
John_Buehrer’s picture

The 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.

$ dr vset --always-set date_default_timezone 10800
date_default_timezone was set to 10800.    [success]

$ dr sqlq "SELECT * FROM variable WHERE name LIKE '%date_default_timezone%';"
name	value
date_default_timezone	s:5:"10800";
date_default_timezone_name	s:13:"Europe/Zurich";

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.