hosting_clone.drush.inc 2.23 KB
Newer Older
1 2 3 4 5 6
<?php
// $Id$

function drush_hosting_clone_pre_hosting_task($task) {
  $task =& drush_get_context('HOSTING_TASK');
  if ($task->ref->type == 'site' && $task->task_type == 'clone') {
7
    $task->args[2] = '@' . $task->task_args['new_uri'];
8
    $platform = node_load($task->task_args['target_platform']);
9
    $task->args[3] = hosting_context_name($platform->nid);
10 11 12 13 14 15 16 17 18 19

    $profile_instance = _hosting_migrate_get_target_profile_name($task);

    if (sizeof($profile_instance)) {
      $task->options['profile'] = $profile_instance->short_name;
    }
    else {
      drush_set_error("HOSTING_NO_VALID_PROFILE", dt("There are no valid install profiles on the target platform to migrate to"));
    }

20 21 22 23
    if ($site->db_server != $task->task_args['new_db_server']) {
      $task->options['new_db_server'] = hosting_context_name($task->task_args['new_db_server']);
    }

mig5's avatar
mig5 committed
24 25 26 27
    if (module_exists('hosting_alias')) {
      $task->options['aliases'] = str_replace("\n", ",", $task->task_args['aliases']);
      $task->options['redirection'] = $task->task_args['redirection'];
    }
28 29 30 31 32 33 34 35 36
  }
}


function hosting_clone_post_hosting_clone_task($task, $data) {
  if ($task->ref->type == 'site') {
    $target = $task->task_args['target_platform'];
    $clone = new stdClass();
    # 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', 'port') as $field) {
38 39
      $clone->$field = $task->ref->$field;
    }
40 41
    $clone->title = $task->task_args['new_uri'];
    $clone->hosting_name = $clone->title;
42 43 44
    $clone->platform = $target;
    $clone->import = 1; # make sure the site doesn't reinstall...
    $clone->verified = 0; # ... and it does verify
mig5's avatar
mig5 committed
45 46
    $clone->aliases = $task->task_args['aliases'];
    $clone->redirection = $task->task_args['redirection'];
47 48 49 50 51
    
    if ($clone->db_server != $task->task_args['new_db_server']) {
      $clone->db_server = $task->task_args['new_db_server'];
    }

52 53 54 55 56 57 58 59 60

    $profile = hosting_package_instance_load(array(
      'rid' => $target,
      'short_name' => $data['context']['profile']
    ));
    if ($profile) {
      $clone->profile = $profile->package_id;
    }

61 62 63
    node_save($clone);
  }
}
mig5's avatar
mig5 committed
64