You are here

function apps_manifest in Apps 7

Produce the Process Manifest.

Starting with the json manifest and adding data around the current status of the app in this install

@TODO: Cache status data and clear on changes to any module status

Parameters

$server stdClass: object server object returned from apps_servers

Return value

array An array of the process json manifest

1 call to apps_manifest()
apps_apps in ./apps.manifest.inc
Retrieve apps from the server manifest.
1 string reference to 'apps_manifest'
apps_profile_enable_app_modules in ./apps.profile.inc
Install downloaded apps.

File

./apps.manifest.inc, line 414
Handles pulling and processing of app data from the server

Code

function apps_manifest($server) {
  $manifests =& drupal_static(__FUNCTION__);
  require_once DRUPAL_ROOT . '/includes/install.inc';
  if (empty($manifests[$server['name']]) && !isset($manifests[$server['name']]['error'])) {

    // Get the manifest for apps for this server
    $manifest = apps_request_manifest($server);

    //if there is an error with the manifest jump out now
    if (isset($manifest['error'])) {
      return $manifest;
    }
    $modules = system_rebuild_module_data();
    $apps = array();
    foreach ($manifest['apps'] as $machine_name => $app) {
      $current_app_module = isset($modules[$machine_name]) ? $modules[$machine_name] : FALSE;
      $app_info = isset($modules[$machine_name]) ? drupal_parse_info_file(drupal_get_path('module', $machine_name, FALSE) . '/' . APPS_APP_INFO) : array();
      $app['enabled'] = $current_app_module && $current_app_module->status;
      $app['incompatible'] = FALSE;
      $app['installed'] = (bool) $current_app_module;
      $app['installed_version'] = isset($app_info['version']) ? $app_info['version'] : (isset($current_app_module->info['version']) ? $current_app_module->info['version'] : NULL);
      $app['upgradeable'] = $app['installed'] && $app['installed_version'] && version_compare($app['installed_version'], $app['version'], 'lt');
      $app['dep_installed'] = TRUE;
      $app['disabled'] = $current_app_module && empty($current_app_module->status) && $current_app_module->schema_version > SCHEMA_UNINSTALLED;
      $app['featured'] = isset($manifest['featured app']) && $machine_name == $manifest['featured app'];
      $app['server'] = $server;
      $app['dependencies'] = isset($app['dependencies']) ? $app['dependencies'] : array();
      $app['libraries'] = isset($app['libraries']) ? $app['libraries'] : array();
      $app['conflicts'] = isset($app['conflicts']) ? $app['conflicts'] : array();

      // Add info to dependencies
      foreach ($app['dependencies'] as $name_version => $downloadable) {

        // Parse dep versions
        $version = drupal_parse_dependency($name_version);

        // While the version compdability string is stored in $name_version
        // the current version may be in downloadables. Ignore 1.x type versions.
        $version['version'] = NULL;
        if (($space_pos = strpos($downloadable, ' ')) && substr($downloadable, -1) != 'x') {
          $version['version'] = trim(substr($downloadable, $space_pos));
        }
        $name = $version['name'];

        // Check status of modules
        $current = isset($modules[$name]) ? $modules[$name] : FALSE;
        $incompatible = $current ? (bool) drupal_check_incompatibility($version, str_replace(DRUPAL_CORE_COMPATIBILITY . '-', '', $current->info['version'])) : FALSE;
        $installed = (bool) $current;
        $enabled = $current && $current->status;
        $status = $incompatible ? APPS_INCOMPATIBLE : (!$installed ? APPS_INSTALLABLE : ($enabled ? APPS_ENABLED : APPS_DISABLED));
        if ($status == APPS_INCOMPATIBLE) {

          // If any one module is incompatible then the app is incompatible
          $app['incompatible'] = TRUE;
        }
        if ($status == APPS_INSTALLABLE) {

          // If any one module is installable then we are not installed yet
          $app['dep_installed'] = FALSE;
        }

        // Rebuild dep with new data
        $info = array(
          'downloadable' => $downloadable,
          'version' => $version,
          'status' => $status,
          'incompatible' => $incompatible,
          'enabled' => $enabled,
          'installed' => $installed,
        );
        unset($app['dependencies'][$name_version]);
        $app['dependencies'][$version['name']] = $info;
      }
      if (isset($app['libraries'])) {
        $profile = variable_get('install_profile', 'standard');
        $profile_path = drupal_get_path('profile', $profile);
        foreach ($app['libraries'] as $name_version => $downloadable) {

          // While the version compdability string is stored in $name_version
          // the current version may be in downloadables. Ignore 1.x type versions.
          $current_version = NULL;
          if (($space_pos = strpos($downloadable, ' ')) && substr($downloadable, -1) != 'x') {
            $current_version = trim(substr($downloadable, $space_pos));
          }
          $info = array(
            'downloadable' => $downloadable,
            'version' => array(
              'name' => $name_version,
              'version' => $current_version,
            ),
            'status' => APPS_INSTALLABLE,
            'incompatible' => 0,
            'enabled' => 0,
            'installed' => is_dir(DRUPAL_ROOT . "/sites/all/libraries/{$name_version}") || is_dir($profile_path . "/libraries/{$name_version}"),
          );
          $app['libraries'][$name_version] = $info;
        }
      }
      $app['status'] = $app['incompatible'] ? APPS_INCOMPATIBLE : (!$app['installed'] || !$app['dep_installed'] ? APPS_INSTALLABLE : ($app['enabled'] ? APPS_ENABLED : APPS_DISABLED));
      $apps[$machine_name] = $app;
    }

    // Override json apps with our enhanced apps
    apps_add_app_info($apps);
    $manifest['apps'] = $apps;
    $manifests[$server['name']] = $manifest;
  }
  return $manifests[$server['name']];
}