You are here

function hosting_package_instance_sync in Hosting 5

Same name and namespace in other branches
  1. 6.2 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.

3 calls to hosting_package_instance_sync()
hosting_platform_post_hosting_verify_task in platform/hosting_platform.drush.inc
Implementation hook_post_verify
hosting_site_post_hosting_install_task in site/hosting_site.drush.inc
implementation of the hosting_post_install hook
hosting_site_post_hosting_verify_task in site/hosting_site.drush.inc

File

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(
        'rid' => $rid,
        'package_id' => $package['package_id'],
      ));
      if (!$instance) {
        $instance = new stdClass();
        $instance->rid = $rid;
        $instance->package_id = $package['package_id'];
      }
      $instance->languages = $package['info']['languages'];
      $instance->filename = $package['filename'];
      $instance->version = $package['version'] ? $package['version'] : 'Unknown';
      $instance->schema_version = $package['schema_version'];
      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);
}