0

I have an ansible script that transfers a production database to my devel server, then runs a few Drush commands to prepare it (e.g. updating the filesystem settings, clearing the cache).

A more complex task is updating a nested configuration value like the following one.

mail_system:
  default-system: SmtpMailSystem
  maillog: MaillogMailSystem

Supposedly I ought to be able to do this with drush ev (aka php-eval) and variable_get() and variable_set() as with drush7 ev '$v = variable_get("file_public_path")', but I get this error message.

Error: Call to undefined function variable_get() in /usr/local/bin/drush7.4.0/commands/core/core.drush.inc(1122): eval()'d code, line 1

It does work correctly when I use the interactive shell.

drush7 core-cli
self> variable_get('mail_system');
array:2 [
  "default-system" => "SmtpMailSystem"
  "maillog" => "MaillogMailSystem"
]

I can work-around it by reading the content of $conf easily enough.

drush7 ev 'global $conf; echo $conf["mail_system"]["default-system"];' 

Writing involves a database query and clearly variable_set() is in core.

Why cannot I use variable_get() and variable_set()?

I am using Drush 7.4.0 and Drupal 7.59.

(I also have Drush 8.1.16 available, but that's much use for this, Drush 8's cget and cset require Drupal 8, and Drush 8 doesn't have Drush 7's vget and vset.)

0

It seems you are confusing Drush 8 and 9 - Drush 8 has vget and vset.

Using Drush 8, the following two commands worked:

drush vget "mail_system"

drush ev 'print_r(variable_get("mail_system"));'

PS! Drush 7 isn't supported and you should use Drush 8 (currently 8.1.17) for Drupal 7.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.