I am trying to write a custom module that performs rsync of individual files between different aliases of a site. The purpose is to keep two versions of a live site in sync. To accomplish this I'm trying to call a function that is part of the Drush module drush_core_call_rsync($source, $destination) (rsync.core.inc:105) from my module code. I am getting a Call to undefined function error.

- Why is the Drush module code not loaded to the environmant?
- Is there some way to explicitly load the Drush code for my module?
- Is there another way I could be trying to invoke Drush operations in code?

I've tried drush_invoke() and drush_invoke_process() as well but getting similar results.

Crossposted at http://drupal.stackexchange.com/questions/75175/how-to-run-drush-command...

Comments

greg.1.anderson’s picture

drush_invoke_process is the way to go. For an example, see examples/sync_enable.drush.inc, and replace the calls to pm-enable with core-rsync and appropriate values.

The drush_sup module also spends a lot of time calling drush functions with drush_invoke_process.

tinflute’s picture

Thanks for the tip.
I'm still getting Fatal error: Call to undefined function drush_invoke_process() in ...
error when passing 2, 3 or 4 args to that function.
The function appears to require only the first 2.
Any reason you can think of that the Drush code is not being seen from my module?
Command-line drush works fine.
I am running this off windows, so that could be the issue.
Will try to replicate from a Linux env.

greg.1.anderson’s picture

Status: Active » Fixed

You're trying to call Drush from a module? That's not supported, sorry.

If you just need to call rsync from Drupal module code, just use the php exec function. If you really need to call Drush from Drupal, you could also use exec, but that's not exactly recommended. (All security holes thereby created are your own fault.)

If you just want to call Drush functions periodically, you could call Drush from cron, sort of like drupal-backup-all does. Sorry, I don't know too much about cron on Windows. cygwin has it, but msysgit does not, I believe. There's probably other ways to call Drush periodically on Windows.

tinflute’s picture

This clarifies things a lot.
Will definitely go with the exec approach.
Thanks
p.s. if you post the link to this page on the drupal.SE question, I'll mark it correct.

Status: Fixed » Closed (fixed)

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