diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index 74be642..898ab6d 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -12,6 +12,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
+use Guzzle\Http\Exception\BadResponseException;
use Guzzle\Http\Exception\RequestException;
/**
@@ -52,6 +53,21 @@
const INSTALL_TASK_RUN_IF_NOT_COMPLETED = 3;
/**
+ * HTTP request result: file not found.
+ */
+const INSTALL_HTTP_NOT_FOUND = 'not found';
+
+/**
+ * HTTP request result: CURL response error. Possibly no internet connection.
+ */
+const INSTALL_HTTP_OFFLINE = 'offline';
+
+/**
+ * HTTP request result: translation file could not be downloaded.
+ */
+const INSTALL_HTTP_NOT_DOWNLOADED = 'not downloaded';
+
+/**
* Installs Drupal either interactively or via an array of passed-in settings.
*
* The Drupal installation happens in a series of steps, which may be spread
@@ -1539,14 +1555,21 @@ function install_retrieve_file($uri, $destination) {
try {
$request = Drupal::httpClient()->get($uri, array('Accept' => 'text/plain'));
$data = $request->send()->getBody(TRUE);
- if (empty($data)) {
- return FALSE;
- }
+ }
+ catch (BadResponseException $e) {
+ // HTTP 4xx and 5xx errors.
+ return INSTALL_HTTP_NOT_FOUND;
}
catch (RequestException $e) {
- return FALSE;
+ // Curl errors, no HTTP response, probably offline.
+ return INSTALL_HTTP_OFFLINE;
+ }
+ if (file_put_contents($path, $data)) {
+ return TRUE;
+ }
+ else {
+ return INSTALL_HTTP_NOT_DOWNLOADED;
}
- return file_put_contents($path, $data) !== FALSE;
}
/**
@@ -1564,8 +1587,13 @@ function install_check_localization_server($uri) {
$response = $request->send();
return TRUE;
}
+ catch (BadResponseException $e) {
+ // HTTP 4xx and 5xx errors.
+ return INSTALL_HTTP_NOT_FOUND;
+ }
catch (RequestException $e) {
- return FALSE;
+ // Curl errors, no HTTP response, probably offline.
+ return INSTALL_HTTP_OFFLINE;
}
}
@@ -1961,13 +1989,23 @@ 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;
- }
- else {
- if ($server_available = install_check_localization_server($server_url)) {
- $online = TRUE;
+ if ($translations_directory_exists && $readable && $writable) {
+ $result = install_check_localization_server($translation_url);
+ switch ($result) {
+ case ($result === TRUE):
+ $translation_available = TRUE;
+ $server_available = TRUE;
+ $online = TRUE;
+ break;
+
+ case INSTALL_HTTP_NOT_FOUND:
+ $online = TRUE;
+ $result = install_check_localization_server($server_url);
+ $server_available = $result === TRUE;
+ break;
+
+ case INSTALL_HTTP_OFFLINE:
+ break;
}
}
@@ -1988,7 +2026,7 @@ function install_check_translations($install_state) {
// If the translations directory is not readable, throw an error.
if (!$readable) {
$requirements['translations directory readable'] = array(
- 'title' => st('Translations directory'),
+ 'title' => st('Translations directory'),
'value' => st('The translations directory is not readable.'),
'severity' => REQUIREMENT_ERROR,
'description' => st('The installer requires read permissions to %translations_directory at all times. If you are unsure how to grant file permissions, consult the online handbook.', array('%translations_directory' => $translations_directory, '@handbook_url' => 'http://drupal.org/server-permissions')),
@@ -1997,7 +2035,7 @@ function install_check_translations($install_state) {
// If translations directory is not writable, throw an error.
if (!$writable) {
$requirements['translations directory writable'] = array(
- 'title' => st('Translations directory'),
+ 'title' => st('Translations directory'),
'value' => st('The translations directory is not writable.'),
'severity' => REQUIREMENT_ERROR,
'description' => st('The installer requires write permissions to %translations_directory during the installation process. If you are unsure how to grant file permissions, consult the online handbook.', array('%translations_directory' => $translations_directory, '@handbook_url' => 'http://drupal.org/server-permissions')),
@@ -2005,50 +2043,67 @@ function install_check_translations($install_state) {
}
else {
$requirements['translations directory writable'] = array(
- 'title' => st('Translations directory'),
+ 'title' => st('Translations directory'),
'value' => st('The translations directory is writable.'),
);
}
}
- // If the translations server can not be contacted, throw an error.
+ // If we failed to complete the http request, throw an error.
if (!$online) {
$requirements['online'] = array(
'title' => st('Internet'),
- 'value' => st('The translation server is offline.'),
+ 'value' => st('Failed to connect.'),
'severity' => REQUIREMENT_ERROR,
- 'description' => st('The installer requires to contact the translation server to download a translation file. Check your internet connection and verify that your website can reach the translation server at !server_url.', array('!server_url' => $server_url)),
+ 'description' => st('The installer requires to contact the translation server to download a translation file. Verify your internet connection and verify that your website can contact the translation server at !server_url.', array('!server_url' => $server_url)),
);
}
else {
$requirements['online'] = array(
'title' => st('Internet'),
- 'value' => st('The translation server is online.'),
+ 'value' => st('The internet connection is working.'),
);
- // If translation file is not found at the translation server, throw an
- // error.
- if (!$translation_available) {
- $requirements['translation available'] = array(
- 'title' => st('Translation'),
- 'value' => st('The %language translation is not available.', array('%language' => $language)),
+ // If the translations server can not be contacted, throw an error.
+ if (!$server_available) {
+ $requirements['server available'] = array(
+ 'title' => st('Internet'),
+ 'value' => st('Failed to contact the translation server.'),
'severity' => REQUIREMENT_ERROR,
- 'description' => st('The %language translation file is not available at the translation server. Choose a different language or select English and translate your website later.', array('%language' => $language, '!url' => check_url($_SERVER['SCRIPT_NAME']))),
+ 'description' => st('The installer requires to contact the translation server to download a translation file. Verify that your website can contact the translation server at !server_url. This fault may be caused by firewall or proxy settings.', array('!server_url' => $server_url)),
);
}
else {
- $requirements['translation available'] = array(
- 'title' => st('Translation'),
- 'value' => st('The %language translation is available.', array('%language' => $language)),
+ $requirements['server available'] = array(
+ 'title' => st('Internet'),
+ 'value' => st('The translation server is online.'),
);
+ // If translation file is not found at the translation server, throw an
+ // error.
+ if (!$translation_available) {
+ $requirements['translation available'] = array(
+ 'title' => st('Translation'),
+ 'value' => st('The %language translation is not available.', array('%language' => $language)),
+ 'severity' => REQUIREMENT_ERROR,
+ 'description' => st('The %language translation file is not available at the translation server. Choose a different language or select English and translate your website later.', array('%language' => $language, '!url' => check_url($_SERVER['SCRIPT_NAME']))),
+ );
+ }
+ else {
+ $requirements['translation available'] = array(
+ 'title' => st('Translation'),
+ 'value' => st('The %language translation is available.', array('%language' => $language)),
+ );
+ }
}
}
if ($translations_directory_exists && $readable && $writable && $translation_available) {
- $translation_downloaded = install_retrieve_file($translation_url, $translations_directory);
+ $result = install_retrieve_file($translation_url, $translations_directory);
+
+ $translation_downloaded = $result === TRUE;
if (!$translation_downloaded) {
$requirements['translation downloaded'] = array(
- 'title' => st('Translation'),
+ 'title' => st('Translation'),
'value' => st('The %language translation could not be downloaded.', array('%language' => $language)),
'severity' => REQUIREMENT_ERROR,
'description' => st('The %language translation file could not be downloaded. Choose a different language or select English and translate your website later.', array('%language' => $language, '!url' => check_url($_SERVER['SCRIPT_NAME']))),