hosting_clone.drush.inc

Drush include for the site cloning module.

Functions

Namesort descending Description
drush_hosting_clone_pre_hosting_task
hosting_clone_post_hosting_clone_task @todo Please document this function.

File

clone/hosting_clone.drush.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Drush include for the site cloning module.
  5. */
  6. function drush_hosting_clone_pre_hosting_task($task) {
  7. $task = &drush_get_context('HOSTING_TASK');
  8. if ($task->ref->type == 'site' && $task->task_type == 'clone') {
  9. $task->args[2] = '@' . strtolower(trim($task->task_args['new_uri']));
  10. $platform = node_load($task->task_args['target_platform']);
  11. $task->args[3] = hosting_context_name($platform->nid);
  12. $profile_instance = _hosting_migrate_get_target_profile_name($task);
  13. if (sizeof($profile_instance)) {
  14. $task->options['profile'] = $profile_instance->short_name;
  15. }
  16. else {
  17. drush_set_error("HOSTING_NO_VALID_PROFILE", dt("There are no valid install profiles on the target platform to migrate to"));
  18. }
  19. if ($task->ref->db_server != $task->task_args['new_db_server']) {
  20. $task->options['new_db_server'] = hosting_context_name($task->task_args['new_db_server']);
  21. }
  22. if (module_exists('hosting_alias')) {
  23. $task->options['aliases'] = str_replace("\n", ",", $task->task_args['aliases']);
  24. $task->options['redirection'] = $task->task_args['redirection'];
  25. }
  26. }
  27. }
  28. /**
  29. * @todo Please document this function.
  30. * @see http://drupal.org/node/1354
  31. */
  32. function hosting_clone_post_hosting_clone_task($task, $data) {
  33. if ($task->ref->type == 'site') {
  34. $target = $task->task_args['target_platform'];
  35. $clone = new stdClass();
  36. # copy some of the settings of the cloned site ($task->ref) to $clone
  37. foreach (array('type', 'status', 'uid', 'comment', 'promote', 'moderate', 'sticky', 'name', 'format', 'client', 'db_server', 'profile', 'site_status', 'site_language') as $field) {
  38. $clone->$field = $task->ref->$field;
  39. }
  40. $clone->title = strtolower(trim($task->task_args['new_uri']));
  41. $clone->hosting_name = $clone->title;
  42. $clone->platform = $target;
  43. $clone->import = 1; # make sure the site doesn't reinstall...
  44. $clone->verified = 0; # ... and it does verify
  45. $clone->aliases = isset($task->task_args['aliases']) ? $task->task_args['aliases'] : array();
  46. $clone->redirection = isset($task->task_args['redirection']) ? $task->task_args['redirection'] : FALSE;
  47. if ($clone->db_server != $task->task_args['new_db_server']) {
  48. $clone->db_server = $task->task_args['new_db_server'];
  49. }
  50. $profile = hosting_package_instance_load(array(
  51. 'i.rid' => $target,
  52. 'p.short_name' => $data['context']['profile'],
  53. ));
  54. if ($profile) {
  55. $clone->profile = $profile->package_id;
  56. }
  57. node_save($clone);
  58. // Record the backup created during clone.
  59. $task->task_args['description'] = t('Pre-clone backup');
  60. hosting_site_post_hosting_backup_task($task, $data);
  61. }
  62. }