You are here

function hosting_package_instance_sync in Hosting 6.2

Same name and namespace in other branches
  1. 5 package/hosting_package.instance.inc \hosting_package_instance_sync()
  2. 7.4 package/hosting_package.instance.inc \hosting_package_instance_sync()
  3. 7.3 package/hosting_package.instance.inc \hosting_package_instance_sync()

Generate instances to reference nodes to releases.

This function uses extensible parameters, so you can pass multiple groups of packages to reference to the node.

This mimics Drupal's module and theme override functionality, in that only the top most item will be referenced to the node.

Parameters

$rid: The nid of the entity on which we are operating.

$type: The type of the entity on which we are operating (platform, site or profile.

7 calls to hosting_package_instance_sync()
hosting_migrate_post_hosting_migrate_task in migrate/hosting_migrate.drush.inc
hosting_platform_post_hosting_delete_task in platform/hosting_platform.drush.inc
Implementation of hook_hosting_post_DELETE().
hosting_platform_post_hosting_verify_task in platform/hosting_platform.drush.inc
Implementation hook_post_verify().
hosting_site_post_hosting_delete_task in site/hosting_site.drush.inc
implementation of hook_hosting_post_DELETE
hosting_site_post_hosting_import_task in site/hosting_site.drush.inc

... See full list

File

package/hosting_package.instance.inc, line 24
API for mapping packages to various Hosting node types

Code

function hosting_package_instance_sync($rid, $type) {
  db_query("UPDATE {hosting_package_instance} SET status = -1 WHERE rid = %d", $rid);
  $map = _hosting_package_plural_map();
  $args = func_get_args();
  $rid = array_shift($args);

  // We need to pass in $type, since there's a possibility of collision b/w a
  // profile's iid, and the nid of a site or platform.
  $type = array_shift($args);

  // Figure out the platform nid
  if ($type == 'platform') {
    $platform = $rid;
  }
  elseif ($type == 'site') {
    $node = node_load($rid);
    $platform = $node->platform;
  }
  elseif ($type == 'profile') {
    $sql = 'SELECT rid
            FROM {hosting_package_instance}
            WHERE iid = %d';
    $platform = db_result(db_query($sql, $rid));
  }
  else {
    watchdog('hosting_package', 'Unrecognized entity type (' . $type . ') passed to hosting_package_instance_sync().', array(), WATCHDOG_WARNING);
  }
  foreach ($map as $plural => $key) {
    $merged = array();
    foreach ($args as $index => $arg) {
      if (array_key_exists($plural, $args[$index])) {
        $merged = array_merge($merged, $args[$index][$plural]);
      }
    }
    foreach ($merged as $name => $package) {
      $instance = hosting_package_instance_load(array(
        'i.rid' => $rid,
        'i.package_id' => $package['package_id'],
      ));
      if (!$instance) {
        $instance = new stdClass();
        $instance->rid = $rid;
        $instance->package_id = $package['package_id'];
      }
      $instance->languages = isset($package['info']['languages']) ? $package['info']['languages'] : array();
      $instance->filename = isset($package['filename']) ? $package['filename'] : NULL;
      $instance->version = isset($package['version']) ? $package['version'] : 'Unknown';
      $instance->version_code = hosting_package_instance_version_code($instance->version);
      $instance->schema_version = isset($package['schema_version']) ? $package['schema_version'] : NULL;
      $instance->status = array_key_exists('status', $package) ? $package['status'] : 0;
      $instance->platform = isset($package['platform']) ? $package['platform'] : $platform;
      hosting_package_instance_save($instance);
    }
  }
  db_query("DELETE FROM {hosting_package_instance} WHERE rid=%d AND status=-1", $rid);
}