commit 1634451656bd7b27a32297f37762ac9c6e4398f6 Author: Erik Stielstra Date: Fri Feb 15 13:36:30 2013 +0100 #3 diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index bf9169f..9341c71 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1531,7 +1531,7 @@ function install_check_localization_server($uri) { } /** - * Gets the core release version for localization. + * Gets the core release version and release alternatives for localization. * * @todo Modify description. * In case core has a development version we fall back to the latest stable @@ -1540,81 +1540,118 @@ function install_check_localization_server($uri) { * for stable releases. * * @return array - * Array of releases each is an associative array containing: + * Array of release data. Each array element is an associative array with: * "core": Core compatibility version. e.g.. 8.x * "version": Release version. e.g. 8.1 */ -function install_get_localization_release() { - $extra_text = $extra_number = ''; +function install_get_localization_release($version = VERSION) { $releases = array(); + $matches = array(); + $info = _install_get_version_info($version); - // Examples of supported versions: - // 8.0-unstable1, 8.0-alpha2, 8.0-beta3, 8.0-rc4 - // 8.0, 8.0-dev - list($version, $extra) = explode('-', VERSION); - list($major, $minor) = explode('.', $version); - - // Extra may contain an index number. E.g. dev, alpha2, rc1 - if ($extra) { - $matches = array(); - preg_match('/([a-z])+([0-9]*)/', $extra, $matches); - $extra_text = $matches[1]; - $extra_number = $matches[2]; - } - - // Stable point releases (no 'rc', 'beta', etc.): - // 8.2 -> 8.2 (no fallback, use current release) - // 8.2 -> 8.1 - if (empty($extra)) { + // Regular stable releases (no 'rc', 'beta', etc.): + // Release alternative: Current release, no fallback. + // Release alternative: Previous minor release. E.g. 8.2 falls back to 8.1. + if (empty($info['extra_text'])) { $releases[] = array( - 'core' => "$major.x", - 'version' => "$major.$minor", + 'core' => $info['major'] . '.x', + 'version' => $version, ); - if ($minor >= 1) { + if ($info['minor'] >= 1) { $releases[] = array( - 'core' => "$major.x", - 'version' => "$major." . $minor - 1, + 'core' => $info['major'] . '.x', + 'version' => $info['major'] . '.' . ($info['minor'] - 1), ); } } else { - // Dev releases: - // 8.2-dev -> 8.1 - // 8.0-dev -> none (falls back to 7.0, see final fallback below). - if ($extra_text == 'dev') { - if ($minor >= 1) { - $releases[] = array( - 'core' => "$major.x", - 'version' => "$major." . $minor - 1, - ); - } - } - // Release candidate releases: - // 8.0-rc2 -> 8.0-rc1 - // 8.0-rc1 -> none (falls back to 7.0, see final fallback below). - elseif ($extra_text == 'rc') { - if ($extra_number >= 2) { + switch ($info['extra_text']) { + // Dev releases: + // Release alternative: Previous point release. E.g. 8.2 falls back to + // 8.1. + case'dev': + if ($info['minor'] >= 1) { + $releases[] = array( + 'core' => $info['major'] . '.x', + 'version' => $info['major'] . '.' . ($info['minor'] - 1), + ); + } + break; + + // Release candidate releases: + // Release alternative: Previous release candidate. E.g. 8.0-rc2 falls + // back to 8.0-rc1. + case 'rc': $releases[] = array( - 'core' => "$major.x", - 'version' => "$major.$minor-rc" . $extra_number - 1, + 'core' => $info['major'] . '.x', + 'version' => $version, ); - } + if ($info['extra_number'] >= 2) { + $releases[] = array( + 'core' => $info['major'] . '.x', + 'version' => $info['major'] . '.' . $info['minor'] . '-rc' . ($info['extra_number'] - 1), + ); + } + break; } - // Other releases (unstable, alpha, beta) only fall back to the final - // fallback. } - // All releases have a final fallback in the first previous major release. - // E.g. 8.1 falls back to 7.0 + // All releases may a fallback to the previous major release. E.g. 8.1 falls + // back to 7.0. $releases[] = array( - 'core' => $major - 1 . '.x', - 'version' => $major - 1 . '.0', + 'core' => $info['major'] - 1 . '.x', + 'version' => $info['major'] - 1 . '.0', ); return $releases; } /** + * Extract version information from a drupal core version string. + * + * Examples of supported versions: 8.0, 8.1, 8.0-dev, 8.0-unstable1, 8.0-alpha2, + * 8.0-beta3, 8.0-rc4. + * + * @param string $version + * Version info string. E.g. "8.0-alpha2" + * + * @return array + * Associative array of version info: + * "major": Major version. E.g. "8" + * "minor": Minor version. E.g. "0" + * "extra": Extra version info. E.g. "alpha2" + * "extra_text": The text part of "extra". E.g. "alpha" + * "extra_number": The number part of "extra". E.g. "2" + */ +function _install_get_version_info($version) { + $info = array(); + + preg_match('/ + ( + ([0-9]+) # Major release number. + \. # . + ([0-9]+) # Minor release number. + ) # + ( # + - # - separator for "extra" verion information. + ( # + ([a-z]+) # Release extra text. E.g. "alpha". + ([0-9]*) # Release extra number (no separator between text and number). + ) # + | # OR no "extra" information. + ) + /sx', $version, $matches); + + $info['major'] = $matches[2]; + $info['minor'] = $matches[3]; + $info['extra'] = isset($matches[5]) ? $matches[5] : ''; + $info['extra_text'] = isset($matches[6]) ? $matches[6] : ''; + $info['extra_number'] = isset($matches[7]) ? $matches[7] : ''; + + return $info; +} + +/** * Indicates that there are no profiles available. */ function install_no_profile_error() { @@ -1761,7 +1798,7 @@ function install_import_translations(&$install_state) { language_delete('en'); // Set up a batch to import translations for the newly added language. - _install_prepare_import(); + _install_prepare_import($langcode); module_load_include('fetch.inc', 'locale'); if ($batch = locale_translation_batch_fetch_build(array(), array($langcode))) { return $batch; @@ -1771,23 +1808,40 @@ function install_import_translations(&$install_state) { /** * Tells the translation import process that Drupal core is installed. + * + * @param string $langcode + * Language code used for the translation. */ -function _install_prepare_import() { +function _install_prepare_import($langcode) { + $matches = array(); global $install_state; - $release = install_get_localization_release(); - db_insert('locale_project') - ->fields(array( - 'name' => 'drupal', - 'project_type' => 'module', - 'core' => $release['core'], - 'version' => $release['version'], - 'server_pattern' => $install_state['server_pattern'], - 'status' => 1, - )) - ->execute(); - module_load_include('compare.inc', 'locale'); - locale_translation_check_projects_local(array('drupal'), array($install_state['parameters']['langcode'])); + // Get the version number from the translation file located in the + // translations directory. We pick the first file which matches the + // installation language. This does not necessarily result in the right file + // so we check if at least the major version number is available. + $files = locale_translate_get_interface_translation_files(array('drupal'), array($langcode)); + $file = reset($files); + $filename = $file->filename; + preg_match('/drupal-([0-9a-z\.-]+)\.' . $langcode . '\.po/', $filename, $matches); + if ($version = $matches[1]) { + $info = _install_get_version_info($version); + if ($info['major']) { + $core = $info['major'] . '.x'; + db_insert('locale_project') + ->fields(array( + 'name' => 'drupal', + 'project_type' => 'module', + 'core' => $core, + 'version' => $version, + 'server_pattern' => $install_state['server_pattern'], + 'status' => 1, + )) + ->execute(); + module_load_include('compare.inc', 'locale'); + locale_translation_check_projects_local(array('drupal'), array($install_state['parameters']['langcode'])); + } + } } /** @@ -1953,16 +2007,19 @@ function install_check_translations($install_state) { } // Build URLs for the translation file and the translation server. - $release = install_get_localization_release(); + $releases = install_get_localization_release(); $langcode = $install_state['parameters']['langcode']; - $variables = array( - '%project' => 'drupal', - '%version' => $release['version'], - '%core' => $release['core'], - '%language' => $langcode, - ); - $translation_url = strtr($install_state['server_pattern'], $variables); - $elements = parse_url($translation_url); + $translation_urls = array(); + foreach ($releases as $release) { + $variables = array( + '%project' => 'drupal', + '%version' => $release['version'], + '%core' => $release['core'], + '%language' => $langcode, + ); + $translation_urls[] = strtr($install_state['server_pattern'], $variables); + } + $elements = parse_url(reset($translation_urls)); $server_url = $elements['scheme'] . '://' . $elements['host']; // Build the language name for display. @@ -1971,11 +2028,14 @@ function install_check_translations($install_state) { // Check if the desirered translation file is available and if the translation // server can be reached, or in other words if we have an internet connection. - if ($translation_available = install_check_localization_server($translation_url)) { - $online = TRUE; - $server_available = TRUE; + foreach ($translation_urls as $translation_url) { + if ($translation_available = install_check_localization_server($translation_url)) { + $online = TRUE; + $server_available = TRUE; + break; + } } - else { + if (!$translation_available) { if ($server_available = install_check_localization_server($server_url)) { $online = TRUE; }