-1

I need to run a specific command after each update of a certain module. Is there any way to use hook_update_N without having to update the N for each version? A hook_update_always solution?

The use case is that I have Features with Rules. These Rules are not always reverted to the new version when the Feature is updated. If I can have a revert/delete function to run after every update of this Feature/module it would save me some headache.

9
  • Sorry, but this is really difficult to understand. Could you please provide some sample case and clarify?
    – leymannx
    Commented May 30, 2018 at 9:24
  • I've updated the question with my use case.
    – Leiph
    Commented May 31, 2018 at 13:00
  • You are actually looking for a deployment routine, aren't you?
    – leymannx
    Commented May 31, 2018 at 13:23
  • Are you executing "drush fr my-feature" or equivalent? If the rule isn't being reverted this is a bug in features and that's what you should be focussing on. Commented Jun 1, 2018 at 8:50
  • @leymannx : We are doing prototypes with Rules and Features. (It has proven to be much faster than ordinary 'git-routines'.) So - yes, this is a deployment related need, but it is the deployment during the development iterations.
    – Leiph
    Commented Jun 1, 2018 at 13:53

1 Answer 1

1

Basically, all you have to do is to provide a custom module that implements hook_update_N, and everytime you want your features to be reverted, you add a new hook_update_N to your module time by time.

Starting with hook_update_7001, then hook_update_7002, then hook_update_7003 etc. (presuming you are using D7).

On your live server then you have to run drush updatedb, it will check for the newest update functions and run the code that's put inside them.

And then there's this question which already has a lot of answers to show you what to put inside your update function to revert a feature programmatically (skip the Drush answer).


How you set up your deploy routine then, that's totally up to you. Normally you would have a webhook or some continuous integration SaaS like CircleCi setup to run a predefined deployment script on every code release automatically. This (Bash-)script then would run let's say git pull, drush cc all, drush updb -y, drush fra -y always automatically.

4
  • 1
    Nitpicking: It would be 7100, 7101, 7102 and so on - 7001, 7002 etc are designated for migrations from Drupal 6. Not that core actually cares, it'll run them anyway, but just for posterity
    – Clive
    Commented May 31, 2018 at 14:04
  • Sorry, but this doesn't address my OP. I need - if possible - a static code to be placed in the mymodule.install-file.
    – Leiph
    Commented Jun 1, 2018 at 14:05
  • @Leiph – Which doesn't exist (,yet). That's why we use deployment routines. But good luck anyways :)
    – leymannx
    Commented Jun 1, 2018 at 15:42
  • No, that was obvious from the documentation. I was hoping that someone had managed to do a workaround. Add something to the update task list, or reset the schema counter during update, or something else. But anyhow - thanks for your efforts.
    – Leiph
    Commented Jun 3, 2018 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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