You are here

function hosting_package_instance_sync in Hostmaster (Aegir) 6

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.

5 calls to hosting_package_instance_sync()
hosting_migrate_post_hosting_migrate_task in modules/hosting/migrate/hosting_migrate.drush.inc
hosting_platform_post_hosting_verify_task in modules/hosting/platform/hosting_platform.drush.inc
Implementation hook_post_verify().
hosting_site_post_hosting_import_task in modules/hosting/site/hosting_site.drush.inc
hosting_site_post_hosting_install_task in modules/hosting/site/hosting_site.drush.inc
implementation of the hosting_post_install hook
hosting_site_post_hosting_verify_task in modules/hosting/site/hosting_site.drush.inc

File

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

Code

function hosting_package_instance_sync($rid) {
  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);
  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($package['version']);
      $instance->schema_version = isset($package['schema_version']) ? $package['schema_version'] : NULL;
      if (array_key_exists('status', $package)) {
        $instance->status = $package['status'];
      }
      else {
        $instance->status = 0;
      }
      hosting_package_instance_save($instance);
    }
  }
  db_query("DELETE FROM {hosting_package_instance} WHERE rid=%d AND status=-1", $rid);
}