Passing values into the site drushrc.php file during migrations
It's possible rely to on manipulating the context for certain tasks and using hook_post_command to make use of that data. In this case, I wanted to save values to the site's drushrc.php file.
Add the following code to hook_post_provision_verify
:
<?php
if (d()->type == 'site') {
$val = drush_get_option('my_custom_option');
drush_set_option('my_custom_option', $val, 'site');
}
?>
This makes sure that my_custom_option
perpetuates through these potentially destructive operations. Since it is provision-verify that writes the drushrc.php file for the site, options set in the site context during hook_post_provision_verify
will be saved.
The final step is to make sure the verify hook is run with the appropriate options at the end of my migrate task, so add this to hook_post_provision_migrate
.
<?php
if (d()->type == 'site') {
$options = array('my_custom_option' => drush_get_option('my_custom_option'));
$target = drush_get_option('target_name');
provision_backend_invoke($target, 'provision-verify', array(), $options);
}
?>
I got this idea from looking at the drush_provision_drupal_provision_migrate function
in platform/migrate.provision.inc
.
I used this approach to create a patch for provision_civicrm
This was originally documented in the provision issue queue.