Drupal 8: Set and get module version via Drush

Submitted by Peter Majmesku on Wed, 05/09/2018 - 09:19

Sometimes you want to know, which version of a certain Drupal 8 module is installed on your system. Then just execute via command line (you must have Drush installed):

drush ev "var_dump(\Drupal::keyValue('system.schema')->get('my_nice_module'))";

This will show you an output like

/Users/peter/Dev/project/vendor/drush/drush/src/Commands/core/PhpCommands.php(28) : eval()'d code:1:
int(8000) 

So module version 8.0 is installed on your system. This is very good for update hooks! Because now you must create an update hook with the name "my_nice_module_update_8001()" to be applied via the "drush updb" command. 

Setting the module version can be done via the following command:

drush ev "\Drupal::keyValue('system.schema')->set('my_nice_module', (int) 8149)";

This can be helpful for workarounds, if you want to bypass "buggy" update hooks or just update hooks, which you do not want to apply.

You can check the KeyValueFactory PHP class to learn more about the inner workings of the Drush command (file location is "docroot/core/lib/Drupal/Core/KeyValueStore/KeyValueFactory.php").

Tags

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.