I need to do a few things which could be easily made with Drush commands, but I need to achieve them through PHP code inside my module, on an hook_update_N().

It seems to me that I need to use drush_invoke() but it doesn't currently exists when I tested in a devel block. I searched here and there how to include (safely) this function, but I had no luck on that.

I guess it is simple and my question could sound silly.

How can I use drush_invoke() in my code called from hook_update_N()?

  • The drush_invoke() API docs has a "calls to" section that you can reference in the Drush codebase to demonstrate how the function is used.
    – Shawn Conn
    Jul 6, 2018 at 20:45
  • 2
    My code? What code? Please update your question to include an MCVE.
    – leymannx
    Jul 6, 2018 at 23:37
  • My tags says it is for Drupal 7. I will update my question to be more explicit on this. Jul 8, 2018 at 13:55
  • Notice that What code? is not asking which Drupal version you are using, but which code you are using.
    – apaderno
    Jul 23, 2018 at 9:52


Browse other questions tagged or ask your own question.