You are here

function hosting_package_sync in Hostmaster (Aegir) 6

Sync the package and package release nodes with the information retrieved from the verify task

@todo Make this prettier.

5 calls to hosting_package_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.module, line 374

Code

function hosting_package_sync(&$data) {
  foreach ($data as $plural => $packages) {
    $type = _hosting_package_plural_map($plural);
    foreach ($packages as $short_name => $file) {
      $name = isset($file['info']['name']) ? $file['info']['name'] : $short_name;
      if (!($package = hosting_get_package($short_name))) {

        // Create a new package.
        $package = new stdClass();
        $package->type = 'package';
        $package->uid = 1;
        $package->package_type = $type;
        $package->short_name = $short_name;
        $package->old_short_name = isset($file['info']['old_short_name']) ? $file['info']['old_short_name'] : '';
        $package->status = 1;
      }

      // we only call node save when the title, description changes
      // or when it's a new package.
      if (!isset($package->nid) || isset($package->title) && $package->title != $name || isset($file['info']['description']) && $package->description != $file['info']['description'] || isset($file['info']['old_short_name']) && $package->old_short_name != $file['info']['old_short_name']) {
        $package->title = $name;
        $package->description = isset($file['info']['description']) ? $file['info']['description'] : '';
        $package->old_short_name = isset($file['info']['old_short_name']) ? $file['info']['old_short_name'] : '';
        node_save($package);
      }
      $data[$plural][$short_name]['package_id'] = $package->nid;
    }
  }
}