You are here

function hosting_context_register in Hosting 7.4

Same name and namespace in other branches
  1. 6.2 hosting.module \hosting_context_register()
  2. 7.3 hosting.module \hosting_context_register()

Add a node to the context lookup db.

Parameters

int $nid: The nid of the node to associate to the given provision context name.

string $name: The name of the provision context.

8 calls to hosting_context_register()
drush_hosting_resume in ./resume.hosting.inc
Drush command to resume the Aegir frontend site.
hosting_migrate_post_hosting_migrate_task in migrate/hosting_migrate.drush.inc
@todo Please document this function.
hosting_package_update_6004 in package/hosting_package.install
hosting_platform_insert in platform/hosting_platform.module
Implements hook_insert().
hosting_platform_update_6004 in platform/hosting_platform.install

... See full list

File

./hosting.module, line 1213
Hosting module.

Code

function hosting_context_register($nid, $name) {

  // Check first to see if this nid exists in the system. If so, update its
  // name.
  if ($result = db_query("SELECT nid FROM {hosting_context} WHERE nid = :nid", array(
    ':nid' => $nid,
  ))
    ->fetch()) {
    db_update('hosting_context')
      ->fields(array(
      'name' => $name,
    ))
      ->condition('nid', $nid)
      ->execute();
  }
  else {

    // It's a new item.
    $id = db_insert('hosting_context')
      ->fields(array(
      'nid' => $nid,
      'name' => $name,
    ))
      ->execute();
  }

  // We include the file instead of enabling the module,
  // because we do not want the overhead of having all the
  // path UI stuff on nodes.
  require_once DRUPAL_ROOT . '/modules/path/path.module';

  // Delete an existing alias,
  // could be left behind after migrating a site from this name.
  path_delete(array(
    'alias' => "hosting/c/{$name}",
  ));

  // Add the new alias.
  $path = array(
    'source' => "node/{$nid}",
    'alias' => "hosting/c/{$name}",
  );
  path_save($path);
}