You are here

function hosting_clone_post_hosting_clone_task in Hosting 7.3

Same name and namespace in other branches
  1. 6.2 clone/hosting_clone.drush.inc \hosting_clone_post_hosting_clone_task()
  2. 7.4 clone/hosting_clone.drush.inc \hosting_clone_post_hosting_clone_task()

@todo Please document this function.

See also

http://drupal.org/node/1354

File

clone/hosting_clone.drush.inc, line 38
Drush include for the site cloning module.

Code

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
    foreach (array(
      'type',
      'status',
      'uid',
      'comment',
      'promote',
      'moderate',
      'sticky',
      'name',
      'format',
      'client',
      'db_server',
      'profile',
      'site_status',
      'site_language',
    ) as $field) {
      $clone->{$field} = $task->ref->{$field};
    }
    $clone->title = hosting_site_clean_domain($task->task_args['new_uri']);
    $clone->hosting_name = hosting_site_get_domain($clone->title);
    $clone->platform = $target;
    $clone->import = 1;

    # make sure the site doesn't reinstall...
    $clone->verified = 0;

    # ... and it does verify
    $clone->aliases = isset($task->task_args['aliases']) ? $task->task_args['aliases'] : array();
    $clone->redirection = isset($task->task_args['redirection']) ? $task->task_args['redirection'] : FALSE;
    if ($clone->db_server != $task->task_args['new_db_server']) {
      $clone->db_server = $task->task_args['new_db_server'];
    }
    $profile = hosting_package_instance_load(array(
      'i.rid' => $target,
      'p.short_name' => $data['context']['profile'],
    ));
    if ($profile) {
      $clone->profile = $profile->package_id;
    }
    node_save($clone);

    // Record the backup created during clone.
    $task->task_args['description'] = t('Pre-clone backup');
    hosting_site_post_hosting_backup_task($task, $data);
  }
}