You are here

function hosting_drush_import in Hostmaster (Aegir) 6

Imports a drush named context / "site alias" into the hostmaster front end, by creating nodes and translating the value.

This is bascally the reverse of the context_options hook.

Parameters

$alias: The name of the provision context to import.

3 calls to hosting_drush_import()
drush_hosting_import in modules/hosting/hosting.drush.inc
Command to import an existing provision named context and generate nodes for it.
hosting_platform_drush_context_import in modules/hosting/platform/hosting_platform.drush.inc
Implementation of hook_drush_context_import().
hosting_site_drush_context_import in modules/hosting/site/hosting_site.drush.inc

File

modules/hosting/hosting.drush.inc, line 109
Drush include for the Hosting module.

Code

function hosting_drush_import($alias) {
  $name = is_object($alias) ? $alias->name : $alias;
  static $known_contexts = array();

  // avoid re-importing the same object twice in one execution
  // of the script.
  if (isset($known_contexts[$name])) {
    drush_log("Already re-imported {$name} in this process.");
    return $known_contexts[$name];
  }
  $context = d($name);
  if ($node = hosting_context_load($name)) {
    drush_log("Context {$name} already has an associated node. Updating {$node->type} node {$node->nid} instead.");
    $node->no_verify = TRUE;
    $known_contexts[$name] = $node->nid;
  }
  else {

    // First time we've seen this context.
    $node = new stdClass();
    $node->type = $context->type;

    // set the hosting name too
    $node->hosting_name = trim($context->name, '@');
    $node->status = 1;
  }

  // iterate through all the objects which may want to save this node.
  $modules = drush_command_implements('drush_context_import');
  foreach ($modules as $name) {
    $func = "{$name}_drush_context_import";
    $func($context, $node);
  }
  node_save($node);
  if ($node->nid) {
    drush_log("Context {$name} has been imported. Updated {$node->type} node {$node->nid}.");
    $known_contexts[$name] = $node->nid;
  }
  return $node->nid;
}