You are here

function hosting_import_site in Hosting 5

Same name and namespace in other branches
  1. 6.2 site/hosting_site.module \hosting_import_site()

Helper function to generate new site node during import

1 call to hosting_import_site()
hosting_site_post_hosting_import_task in site/hosting_site.drush.inc

File

site/hosting_site.module, line 138

Code

function hosting_import_site($site_id, $data, $platform = HOSTING_DEFAULT_PLATFORM) {
  global $user;
  $client = node_load(HOSTING_DEFAULT_CLIENT);
  if ($data['client_email']) {
    $client = hosting_import_client($data['client_email'], $data['client_name'], $data['client_organization']);
  }
  $site = new stdClass();
  $site->nid = $site_id;
  $site->uid = $client->uid;
  $site->status = 1;
  $site->site_status = 1;
  $site->platform = $platform;
  $site->client = $client->nid;
  $db_server = hosting_get_db_server($data['db_id']);
  $site->db_server = $db_server ? $db_server->nid : HOSTING_DEFAULT_DB_SERVER;
  $site->language = $data['language'] ? $data['language'] : 'en';

  // This should really be handled via a hook system, to allow hosting_alias to see these fields, but later.

  #$site->aliases = $data['aliases'] ? $data['aliases'] : array();
  $profile = hosting_package_instance_load(array(
    'rid' => $platform,
    'short_name' => $data['profile'],
  ));
  if (!$profile) {
    $profile = hosting_package_instance_load(array(
      'rid' => $platform,
      'short_name' => 'default',
    ));
  }
  $site->profile = $profile->package_id;

  // cast site object to array, will be using various array_* functions on the data.
  $site = (array) $site;

  // Protect the fields already in the site object.
  foreach (array_keys($site) as $key) {
    unset($data[$key]);
  }

  // Load all the original node fields.
  $site = array_merge((array) node_load($site_id), $site);

  // Map the imported fields onto the node object.
  $site = array_merge($site, $data);

  // Cast back to object.
  $site = (object) $site;
  node_save($site);
}