You are here

function hosting_platform_load in Hosting 7.4

Same name and namespace in other branches
  1. 5 platform/hosting_platform.module \hosting_platform_load()
  2. 6.2 platform/hosting_platform.module \hosting_platform_load()
  3. 7.3 platform/hosting_platform.module \hosting_platform_load()

Implements hook_load().

File

platform/hosting_platform.module, line 737
Platform node type definition.

Code

function hosting_platform_load($nodes) {
  foreach ($nodes as $nid => &$node) {
    $additions = db_query('
      SELECT
        p.*,
        c.name as web_server_name,
        status AS platform_status
      FROM {hosting_platform} p
      LEFT JOIN {hosting_context} c ON p.web_server = c.nid
      WHERE vid = :vid

    ', array(
      ':vid' => $node->vid,
    ))
      ->fetch();

    // Avoid PHP 5.4 warning when platform doesn't exist yet.
    // See: https://drupal.org/node/1940378
    $additions = $additions ? $additions : new stdClass();
    $iid = db_query("SELECT iid\n                     FROM {hosting_package_instance} i\n                     LEFT JOIN {hosting_package} p\n                     ON p.nid=i.package_id\n                     WHERE p.package_type = :package_type\n                     AND i.rid = :rid", array(
      ':package_type' => 'platform',
      ':rid' => $node->nid,
    ))
      ->fetchField();
    if (empty($node->frommakefile)) {
      $node->frommakefile = array(
        'makefile' => '',
        'make_working_copy' => 0,
      );
    }
    if (!empty($additions->makefile)) {
      $node->frommakefile['makefile'] = $additions->makefile;
    }
    if (!empty($additions->make_working_copy)) {
      $node->frommakefile['make_working_copy'] = $additions->make_working_copy;
    }
    if (module_exists('hosting_package')) {
      $additions->release = hosting_package_instance_load($iid);
      $additions->profiles = hosting_get_profiles($node->nid, 'short_name');
    }
    if (hosting_feature('client')) {
      $result = db_query("SELECT cid FROM {hosting_platform_client_access} WHERE pid = :pid", array(
        ':pid' => $node->nid,
      ));
      foreach ($result as $record) {
        $additions->clients[$record->cid] = $record->cid;
      }
    }

    // @TODO: Legacy Refactor
    // Load service_subscriptions.
    $additions->service_subscriptions['http'] = array(
      'server' => $additions->web_server_name,
    );
    foreach ($additions as $property => &$value) {
      $node->{$property} = is_numeric($value) ? (int) $value : $value;
    }

    // Load commands for this platform.
    $node->commands = hosting_find_deploy_commands($node);
  }
}