You are here

function hosting_import_site in Hostmaster (Aegir) 6

Helper function to generate update a site node during import.

Parameters

$site_id: The node ID of the existing site node to update.

$data: An associative array of data to add to the site node. Keys should correspond to properties on the node object to overwrite.

$platform: The node ID of the platform that the site is deployed on.

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

File

modules/hosting/site/hosting_site.module, line 380

Code

function hosting_import_site($site_id, $data, $platform) {
  global $user;
  $client = node_load(HOSTING_DEFAULT_CLIENT);
  if ($data['client_name']) {
    $client = hosting_import_client($data['client_name']);
  }
  elseif ($data['client_email']) {

    // @deprecated drop this after 1.x
    $client = hosting_import_client($data['client_email']);
  }
  $site = node_load($site_id);
  $site->nid = $site_id;
  $site->uid = $client->uid;
  $site->status = 1;
  $site->site_status = 1;
  $site->platform = $platform;
  $site->no_verify = TRUE;
  $site->verified = time();
  $site->client = $client->nid;
  $site->ip_addresses = array_values($data['site_ip_addresses']);
  $site->cron_key = $data['cron_key'] ? $data['cron_key'] : '';
  $site->aliases = $data['aliases'] ? $data['aliases'] : array();
  $site->db_server = $site->db_server ? $site->db_server : HOSTING_DEFAULT_DB_SERVER;
  $site->site_language = $data['language'] ? $data['language'] : 'en';

  // Drupal 6 introduced a language field on nodes
  unset($data['language']);
  $profile = hosting_package_instance_load(array(
    'i.rid' => $platform,
    'p.short_name' => $data['profile'],
  ));
  if (!$profile) {
    $profile = hosting_package_instance_load(array(
      'i.rid' => $platform,
      'p.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);
}