You are here

function hosting_drush_import in Hosting 7.4

Same name and namespace in other branches
  1. 6.2 hosting.drush.inc \hosting_drush_import()
  2. 7.3 hosting.drush.inc \hosting_drush_import()

Imports a drush named context / "site alias" into the hostmaster frontend.

By creating nodes and translating the value. This is bascally the reverse of the context_options hook.

Parameters

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

Return value

int The node ID associated with the alias.

3 calls to hosting_drush_import()
drush_hosting_import in ./hosting.drush.inc
Command to import an existing provision named context.
hosting_context_nid in ./hosting.module
Lookup the node ID for a hosting context name.
hosting_site_post_hosting_import_task in site/hosting_site.drush.inc
Implements hook_post_hosting_import_task().

File

./hosting.drush.inc, line 124
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 Drush commands which may want to save this node.
  $modules = drush_command_implements('drush_context_import');
  foreach ($modules as $module) {
    $func = "{$module}_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;
}