You are here

function l10n_update_build_projects in Localization update 6

Same name and namespace in other branches
  1. 7.2 l10n_update.compare.inc \l10n_update_build_projects()
  2. 7 l10n_update.project.inc \l10n_update_build_projects()

Rebuild project list

Return value

array

3 calls to l10n_update_build_projects()
l10n_update_admin_import_form_submit in ./l10n_update.admin.inc
Submit handler for Update form.
l10n_update_get_projects in ./l10n_update.module
Get stored list of projects
l10n_update_project_refresh in ./l10n_update.project.inc
Refresh projects after enabling/disabling modules

File

./l10n_update.project.inc, line 30
Library for querying Drupal projects

Code

function l10n_update_build_projects() {
  module_load_include('inc', 'l10n_update');

  // Get all stored projects, including disabled ones
  $current = l10n_update_get_projects(NULL, TRUE);

  // Now get the new project list, just enabled ones
  $projects = l10n_update_project_list();

  // Mark all previous projects as disabled and store new project data
  db_query("UPDATE {l10n_update_project} SET status = 0");
  $default_server = l10n_update_default_server();
  if (module_exists('update')) {
    $projects_info = update_get_available(TRUE);
  }
  foreach ($projects as $name => $data) {
    if (isset($projects_info[$name]['releases']) && $projects_info[$name]['project_status'] != 'not-fetched') {

      // Find out if a dev version is installed.
      if (preg_match("/^[0-9]+\\.x-([0-9]+)\\..*-dev\$/", $data['info']['version'], $matches)) {
        foreach ($projects_info[$name]['releases'] as $project_release) {
          if ($project_release['version_major'] == $matches[1] && (!isset($project_release['version_extra']) || $project_release['version_extra'] != 'dev')) {
            $release = $project_release;
            break;
          }
        }
      }
      elseif (preg_match("/HEAD/", $data['info']['version'], $matches)) {

        // Pick latest available release.
        $release = array_shift($projects_info[$name]['releases']);
      }
      if (!empty($release['version'])) {
        $data['info']['version'] = $release['version'];
      }
      unset($release);
    }
    $data += array(
      'version' => isset($data['info']['version']) ? $data['info']['version'] : '',
      'core' => isset($data['info']['core']) ? $data['info']['core'] : DRUPAL_CORE_COMPATIBILITY,
      // The project can have its own l10n server, we use default if not
      'l10n_server' => isset($data['info']['l10n server']) ? $data['info']['l10n server'] : NULL,
      // A project can provide the server url to fetch metadata, or the update url (path)
      'l10n_url' => isset($data['info']['l10n url']) ? $data['info']['l10n url'] : NULL,
      'l10n_path' => isset($data['info']['l10n path']) ? $data['info']['l10n path'] : NULL,
      'status' => 1,
    );
    $project = (object) $data;

    // Unless the project provides a full l10n path (update url), we try to build one
    if (!isset($project->l10n_path)) {
      $server = NULL;
      if ($project->l10n_server || $project->l10n_url) {
        $server = l10n_update_server($project->l10n_server, $project->l10n_url);
      }
      else {

        // Use the default server
        $server = l10n_update_server($default_server['name'], $default_server['server_url']);
      }
      if ($server) {

        // Build the update path for this project, with project name and release replaced
        $project->l10n_path = l10n_update_build_string($project, $server['update_url']);
      }
    }

    // If no server name is given, fall back to the server's host name.
    if (empty($project->l10n_server)) {
      $elements = parse_url($project->l10n_path);
      $project->l10n_server = $elements['host'];
    }

    // Create / update project record
    $update = empty($current[$name]) ? array() : array(
      'name',
    );
    drupal_write_record('l10n_update_project', $project, $update);
    $projects[$name] = $project;
  }
  return $projects;
}