diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 3cbbd82..813c24a 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -18,6 +18,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Guzzle\Http\Exception\BadResponseException; use Guzzle\Http\Exception\RequestException; /** @@ -58,6 +59,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 @@ -1721,14 +1737,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; } /** @@ -1746,8 +1769,13 @@ function install_check_localization_server($uri) { $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; } } @@ -2259,6 +2287,7 @@ function install_check_translations($install_state) { $translations_directory = conf_path() . '/files/translations'; $translations_directory_exists = FALSE; $translation_available = FALSE; + $server_available = FALSE; $online = FALSE; // First attempt to create or make writable the files directory. @@ -2297,15 +2326,27 @@ function install_check_translations($install_state) { // translation server can be reached. In other words, check if we are online // and have an internet connection. foreach ($translation_urls as $translation_url) { - if ($translation_available = install_check_localization_server($translation_url)) { - $online = TRUE; - break; + if ($result = install_check_localization_server($translation_url)) { + switch ($result) { + case ($result === TRUE): + $translation_available = TRUE; + $server_available = TRUE; + $online = TRUE; + break 2; + + case INSTALL_HTTP_NOT_FOUND: + $online = TRUE; + break; + + case INSTALL_HTTP_OFFLINE: + break 2; + } } } - if (!$translation_available) { - if (install_check_localization_server($server_url)) { - $online = TRUE; - } + // No translation file was be found. Check if the server is available. + if ($online && !$translation_available) { + $result = install_check_localization_server($server_url); + $server_available = $result === TRUE; } // If the translations directory does not exists, throw an error. @@ -2348,40 +2389,59 @@ function install_check_translations($install_state) { } } - // 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' => t('Internet'), - 'value' => t('The translation server is offline.'), + 'value' => t('Failed to connect.'), 'severity' => REQUIREMENT_ERROR, - 'description' => t('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' => t('The installer failed to connect to the translation server. Verify your internet connection and verify that your website can contact the translation server at !server_url. You can also install in English and get your language later.', array('!server_url' => $server_url, '!url' => check_url($_SERVER['SCRIPT_NAME']))), ); } else { $requirements['online'] = array( 'title' => t('Internet'), - 'value' => t('The translation server is online.'), + 'value' => t('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' => t('Translation'), - 'value' => t('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' => t('Internet'), + 'value' => t('Failed to contact the translation server.'), 'severity' => REQUIREMENT_ERROR, - 'description' => t('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' => t('The installer failed to connect to the translation server. Verify that your website can contact the translation server at !server_url. This fault may be caused by firewall or proxy settings. You can also install in English and get your language later.', array('!server_url' => $server_url, '!url' => check_url($_SERVER['SCRIPT_NAME']))), ); } else { - $requirements['translation available'] = array( - 'title' => t('Translation'), - 'value' => t('The %language translation is available.', array('%language' => $language)), + $requirements['server available'] = array( + 'title' => t('Internet'), + 'value' => t('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' => t('Translation'), + 'value' => t('The %language translation is not available.', array('%language' => $language)), + 'severity' => REQUIREMENT_ERROR, + 'description' => t('The %language translation file is not available at the translation server. Choose a different language or select English and get your language later.', array('%language' => $language, '!url' => check_url($_SERVER['SCRIPT_NAME']))), + ); + } + else { + $requirements['translation available'] = array( + 'title' => t('Translation'), + 'value' => t('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(