function hosting_package_instance_sync in Hosting 7.4
Same name and namespace in other branches
- 5 package/hosting_package.instance.inc \hosting_package_instance_sync()
- 6.2 package/hosting_package.instance.inc \hosting_package_instance_sync()
- 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 - @todo Please document this function.
- hosting_platform_post_hosting_delete_task in platform/
hosting_platform.drush.inc - Implements hook_post_hosting_TASK_TYPE_task().
- hosting_platform_post_hosting_verify_task in platform/
hosting_platform.drush.inc - Implements hook_post_hosting_TASK_TYPE_task().
- hosting_site_post_hosting_delete_task in site/
hosting_site.drush.inc - Implements hook_post_hosting_TASK_TYPE_task().
- hosting_site_post_hosting_import_task in site/
hosting_site.drush.inc - Implements hook_post_hosting_import_task().
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_update('hosting_package_instance')
->fields(array(
'status' => -1,
))
->condition('rid', $rid)
->execute();
$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 = :rid';
$platform = db_query($sql, array(
':rid' => $rid,
))
->fetchField();
}
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 (is_array($args[$index]) && 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'] : '';
$instance->version = isset($package['version']) ? $package['version'] : 'Unknown';
$instance->schema_version = isset($package['schema_version']) ? $package['schema_version'] : 0;
$instance->version_code = hosting_package_instance_version_code($instance->version);
$instance->status = array_key_exists('status', $package) ? $package['status'] : 0;
$instance->platform = isset($package['platform']) ? $package['platform'] : $platform;
hosting_package_instance_save($instance);
}
}
db_delete('hosting_package_instance')
->condition('rid', $rid)
->condition('status', -1)
->execute();
}