You are here

function l10n_update_build_projects in Localization update 7

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

Rebuild project list

Parameters

$refresh: TRUE: Refresh project list.

Return value

array Array of project objects to be considered for translation update.

5 calls to l10n_update_build_projects()
l10n_update_admin_import_form in ./l10n_update.admin.inc
Translation update form.
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_modules_uninstalled in ./l10n_update.module
Implements hook_modules_uninstalled().
l10n_update_project_refresh in ./l10n_update.project.inc
Refresh projects after enabling modules

File

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

Code

function l10n_update_build_projects($refresh = FALSE) {
  module_load_include('inc', 'l10n_update');

  // Get all stored projects, including disabled ones
  $current = l10n_update_get_projects($refresh, 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_update('l10n_update_project')
    ->fields(array(
    'status' => 0,
  ))
    ->execute();
  $default_server = l10n_update_default_server();
  foreach ($projects as $name => $data) {

    // For dev releases, remove the '-dev' part and trust the translation server
    // to fall back to the latest stable release for that branch.
    if (isset($data['info']['version']) && strpos($data['info']['version'], '-dev')) {
      if (preg_match("/^(\\d+\\.x-\\d+\\.).*\$/", $data['info']['version'], $matches)) {

        // Example matches: 7.x-1.x-dev, 7.x-1.0-alpha1+5-dev => 7.x-1.x
        $data['info']['version'] = $matches[1] . 'x';
      }
      elseif (preg_match("/^(\\d+\\.).*\$/", $data['info']['version'], $matches)) {

        // Example match: 7.33-dev => 7.x (Drupal core)
        $data['info']['version'] = $matches[1] . 'x';
      }
    }
    $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']);
      }
    }

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

    // @todo Use db_merge() to avoid problems with saving existing projects.
    try {
      drupal_write_record('l10n_update_project', $project, $update);
    } catch (Exception $e) {
      watchdog('l10n_update', 'Could not insert a project into the l10n_update_project table, possibly because it already exists.', NULL, WATCHDOG_INFO);
    }
    $projects[$name] = $project;
  }
  return $projects;
}