hosting_migrate.drush.inc

Implement drush hooks for the hosting migrate module.

Functions

File

migrate/hosting_migrate.drush.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Implement drush hooks for the hosting migrate module.
  5. */
  6. function drush_hosting_migrate_pre_hosting_task($task) {
  7. $task = &drush_get_context('HOSTING_TASK');
  8. if ($task->ref->type == 'site' && $task->task_type == 'migrate') {
  9. $platform = node_load($task->task_args['target_platform']);
  10. $task->args[2] = hosting_context_name($platform->nid);
  11. $site = $task->ref;
  12. if (strtolower(trim($site->title)) != strtolower(trim($task->task_args['new_uri']))) {
  13. $task->args[3] = '@' . strtolower(trim($task->task_args['new_uri']));
  14. }
  15. if ($site->db_server != $task->task_args['new_db_server']) {
  16. $task->options['new_db_server'] = hosting_context_name($task->task_args['new_db_server']);
  17. }
  18. $profile_instance = _hosting_migrate_get_target_profile_name($task);
  19. if (sizeof($profile_instance)) {
  20. $task->options['profile'] = $profile_instance->short_name;
  21. }
  22. else {
  23. drush_set_error("HOSTING_NO_VALID_PROFILE", dt("There are no valid install profiles on the target platform to migrate to"));
  24. }
  25. }
  26. }
  27. function _hosting_migrate_get_target_profile_name($task) {
  28. // load the original install profile
  29. $profile = node_load($task->ref->profile);
  30. // get the profile instance we are migrating to.
  31. $profile_instance = hosting_package_instance_load(array(
  32. 'i.rid' => $task->task_args['target_platform'],
  33. 'p.short_name' => $profile->short_name,
  34. ));
  35. if (!sizeof($profile_instance)) {
  36. // get a possible upgrade path for the profile.
  37. $profile_instance = hosting_package_instance_load(array(
  38. 'i.rid' => $task->task_args['target_platform'],
  39. 'p.old_short_name' => $profile->short_name,
  40. ));
  41. }
  42. return $profile_instance;
  43. }
  44. /**
  45. * @todo Please document this function.
  46. * @see http://drupal.org/node/1354
  47. */
  48. function hosting_migrate_post_hosting_migrate_task($task, $data) {
  49. if ($task->ref->type == 'site') {
  50. $target = $task->task_args['target_platform'];
  51. $site = $task->ref;
  52. if (strtolower(trim($site->title)) != strtolower(trim($task->task_args['new_uri']))) {
  53. $site->title = strtolower(trim($task->task_args['new_uri']));
  54. hosting_context_register($site->nid, $site->title);
  55. }
  56. if ($site->db_server != $task->task_args['new_db_server']) {
  57. $site->db_server = $task->task_args['new_db_server'];
  58. }
  59. $site->db_name = $data['context']['db_name'];
  60. $profile = hosting_package_instance_load(array(
  61. 'i.rid' => $target,
  62. 'p.short_name' => $data['context']['profile'],
  63. ));
  64. if ($profile) {
  65. $site->profile = $profile->package_id;
  66. }
  67. $site->verified = REQUEST_TIME;
  68. $site->no_verify = TRUE;
  69. $site->platform = $target;
  70. node_save($site);
  71. $task->ref = $site;
  72. //do the package synching
  73. $context = $data['context'];
  74. $packages = $context['packages'];
  75. hosting_package_sync($packages);
  76. hosting_package_instance_sync($task->ref->nid, $task->ref->type, $packages);
  77. // Record the backup created during migrate.
  78. $task->task_args['description'] = t('Pre-migration backup');
  79. hosting_site_post_hosting_backup_task($task, $data);
  80. }
  81. }