Problem/Motivation

Sub-task of #1862398: [meta] Replace drupal_http_request() with Guzzle.

To test the patch

  1. Checkout latest 8.x and apply the latest patch
  2. Drop database
  3. Remove sites/default/settings.php
  4. Remove directory sites/default/files
  5. Install Drupal via the browser
  6. In the first installation step select a non-English language.
  7. The installation should be completed without errors.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sutharsan’s picture

Component: locale.module » install system
Status: Active » Needs review
FileSize
1.98 KB

Converting the drupal_http_request to Guzzle. No specific feedback on exceptions, as the current code does. This may be improved in a way that install_check_localization_server() can be replaced by diagnostic feedback from install_retrieve_file(). But this should be postponed until #1875792: Standardize Guzzle exception handling has come to a solution.

tstoeckler’s picture

+++ b/core/includes/install.core.inc
@@ -1437,7 +1439,7 @@ function install_download_translation(&$install_state) {
+ * Attempts to get a file using a http request and to store it locally.

That should be "HTTP" now I guess, instead of "http".

+++ b/core/includes/install.core.inc
@@ -1459,14 +1461,21 @@ function install_retrieve_file($uri, $destination) {
+    $data = drupal_container()
+      ->get('http_default_client')
+      ->get($uri, array('Accept' => 'text/plain'))
+      ->send()
+      ->getBody(TRUE);

@@ -1476,12 +1485,17 @@ function install_retrieve_file($uri, $destination) {
+  $request = drupal_container()->get('http_default_client')->head($uri);
+  try {
+    $response = $request->send();

I generally like chaining, but in the former case it feels like a bit much. I guess it's just a matter of taste, but I find the latter example much more readable.

Leaving at needs review, because both issues are very minor.

Sutharsan’s picture

Comments processed.

Status: Needs review » Needs work

The last submitted patch, install-convert-to-guzzle-1887046-3.patch, failed testing.

Sutharsan’s picture

Sutharsan’s picture

Status: Needs work » Needs review
Berdir’s picture

Status: Needs review » Needs work
+++ b/core/includes/install.core.incundefined
@@ -1459,14 +1461,18 @@ function install_retrieve_file($uri, $destination) {
-  if (file_put_contents($path, $result->data) === FALSE) {
+  catch (BadResponseException $e) {
     return FALSE;

@@ -1476,12 +1482,17 @@ function install_retrieve_file($uri, $destination) {
+  catch (BadResponseException $e) {
+    return FALSE;

A curl exception is now a BadRequestException (which BadResponseException extends from), so that's what you should catch.

Sutharsan’s picture

Status: Needs work » Needs review
FileSize
1.01 KB
1.96 KB

BadResponseException changed to RequestException.

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

I think this is good to go. This is so early in the installer that we can't do exception handling and we didn't do so before, this just converts the calls.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

catch’s picture

Status: Fixed » Needs work

I just tried to re-install with an existing database and got this message instead of the usual "you've already installed don't do it again" message:

The service definition "http_default_client" does not exist.

That's not as useful..

Reverted for now to avoid inflating the critical bugs list.

Sutharsan’s picture

@catch, I can't reproduce this error. This is what I've done:
Using Mysql database:
1. Dropped the database (drush sql-drop)
2. Ran the installer in the browser (/install.php) Language: English, Profile: Standard
3. Completed the installation and visited the new website.
4. Attempt to re-install in the browser (/install.php)
Repeated the above with Dutch as installation language.
Dropped the sites/default/files and sites/default/settings.php and repeated all the above steps using SQLight as database.

In all cases I get the usual "Drupal already installed" page.

Sutharsan’s picture

I also couldn't reproduce it with the patch applied to the last commit before #10 (a62c75ed68f2fd742e3a82bbb932c9bff5a2085f). I've tried English + SQLight and Dutch + Mysql. No errors :(
@catch, can you remember your steps?

tstoeckler’s picture

I think what is meant in #11 is that @catch did *not* drop the database before hitting install.php. He expected the usual "You've already installed Drupal, what are you doing here?" message, but instead got a fatal.

Sutharsan’s picture

@tstoecker, that is what I did in step 4 of my description. Going to /core/install.php while already having an installed site. But now I read it back, that was not very clear.

tstoeckler’s picture

Well, but If I read that correctly, you re-installed from the start with the patch already applied. That is what seems to be the problem (that's what I assume, at least). Catch hit install.php on an existing site directly after applying the patch.

Edit: Wrote something other than what I meant...

catch’s picture

Here's the steps (from memory so hopefully I didn't miss anything):

1. Didn't drop database

2. English (British) was autoselected - however note this fails to download with the patch not applied on my localhost.

3. settings.php was filled in etc.

4. Re-install attempted via install.php

Sutharsan’s picture

Status: Needs work » Reviewed & tested by the community

I think I've tried all variations now, but can't reproduce this:

  • Patch applied to a62c75ed68f2fd742e3a82bbb932c9bff5a2085f, patch applied to latest 8.x.
  • Mysql, sqLight.
  • Re-install (without clearing the DB) before and after the patch is applied.
  • Re-install as admin and as anonymous.

Let me be bold, I'm putting it back to RTBC.

Sutharsan’s picture

catch’s picture

Status: Reviewed & tested by the community » Fixed

Hmm I can't reproduce it either, followed up on the other issue though.

Committed/pushed this one.

webchick’s picture

I just tried to install in French and got "The service definition "http_default_client" does not exist." :( It goes away when I roll back this patch.

Sutharsan’s picture

Now I can reproduce too :(

  1. checkout latest 8.x
  2. drop database
  3. remove sites/default/settings.php
  4. remove directory sites/default/files
  5. install via browser
  6. select any language except English
Sutharsan’s picture

The problem lies in the 'http_default_client' service being registered in CoreBundle::build(). This is only called several steps later in the installation (after the database settings form). And therefore not available this early in the installation. Not use how to fix this, either by registering this Guzzle library early in the installation process or by not using this patch and keeping the drupal_http_request(). I guess the first solution is preferred, but I don't not know how to do this.
And how much I hate to say this, I think the quick fix is to roll back this patch again.

Berdir’s picture

Status: Fixed » Needs work

You can also set up a Guzzle HTTP Client yourself.

There is also an issue that will change how the whole thing works, but I'm not exactly sure what happens with the CoreBundle.

Sutharsan’s picture

Priority: Normal » Major
Status: Needs work » Needs review
Issue tags: +Needs manual testing
FileSize
893 bytes

There was this thing in the back of my head ... of course other services are registered too for installation. Adding the http client service did the trick.
The patch needs some more eyes, I copied the registration code from CoreBundle.php.

catch’s picture

Not sure why I couldn't reproduce this again. Patch looks good and what I was expecting but yeah thanks for the 'needs manual testing' tag :)

Status: Needs review » Needs work

The last submitted patch, install-convert-to-guzzle-1887046-24.patch, failed testing.

Sutharsan’s picture

Status: Needs work » Needs review

The bare (base) minimal upgrade tests run fine in my sandbox. Lets give the bot another try.

tstoeckler’s picture

Status: Needs review » Needs work
+++ b/core/includes/install.core.inc
@@ -357,6 +357,16 @@ function install_begin_request(&$install_state) {
     drupal_container($container);
+
+    // Register the Guzzle http client for fetching translation file from a
+    // remote translation server such as localization.drupal.org.
+    $container->register('http_default_client', 'Guzzle\Http\Client')

The $container->register() should be moved up before the call to dupal_container($container), I think. I guess this works because objects are handled as references in PHP, but conceptually this is wrong. Here we're setting the container, and a few lines down down we're fetching it again.

Minor: http -> HTTP, translation file -> translation files,
localization.drupal.org -> localize.drupal.org

Moving to needs work for that, although, since this apparently fixes translation in other languages (I didn't try it out myself) it might (or might not) make sense to commit this as is.

Edit: Missing word.

Sutharsan’s picture

Status: Needs work » Needs review
FileSize
1.19 KB
895 bytes

@tstoeckler, thanks for the comments. All processed.

vijaycs85’s picture

FileSize
34.77 KB
28 KB
23.86 KB

I did below on Windows 7/Firefox-18.0.1

  1. Checkout latest 8.x and apply the latest patch - checked(used patch in #30)
  2. Drop database - checked
  3. Remove sites/default/settings.php - checked
  4. Remove directory sites/default/files - checked
  5. Install Drupal via the browser - checked
  6. In the first installation step select a non-English language. - checked. Selected French
  7. The installation should be completed without errors. - Stopped at step 2 (see steps below)

Step 1:

step-1.png

Step 2:
step-2.png

Seems I have access to translation server:
translation-server.png

Am I missing something here?

Sutharsan’s picture

@vijaycs85, the problem you run into is different than the one we are fixing here. But thanks for testing anyway ;) If you have time, contact me in IRC to debug this one together.

vijaycs85’s picture

FileSize
29.62 KB
23.03 KB
45.62 KB
45.13 KB
22.68 KB
32.36 KB
26.59 KB
23.86 KB

Seems that was my network issue. Though, I can see translation site, Drupal somehow can't access. is it worth mentioning port in help text or would it become too technical/confusing?

I manage to test it in other network and except a warning in step-6 (site information page), no error!!!

Step 1:
step-1.png

Step 2:
step-2-new.png

Step 3:
step-3.png

Step 4:
step-4.png

Step 5:
step-5.png

Step 6:
step-6.png

Step 7:
step-7.png

Step 8:
step-8.png

Sutharsan’s picture

@vijaycs85, the confusion is in the difference between the computer and the server. The computer can access, the server can't. We need to improve this but is a different issue.

thsutton’s picture

Status: Needs work » Needs review

I applied @Sutharsan's patch in #30 to 8.x 2f7db4222b2afc4415b9fad0ad578b142ab8cf3d and found:

  • It fixed the original error about 'drupal_http_request' and I can select a language (even ones with no translation as in #1904214: Installer auto-selects languages that don't have a translation, causing a requirements error).
  • Installation with plain old "English" still works.
  • Selecting another language downloaded the .po file, but resulted in a PHP error later on during the installation:
    PHP Fatal error: Call to a member function get() on a non-object in /Users/thsutton/Sites/drupal8/htdocs/core/includes/bootstrap.inc on line 2481, referer: http://ttt.dev/core/install.php?langcode=fr&profile=minimal
thsutton’s picture

Status: Needs review » Needs work

Forgot to change status.

Sutharsan’s picture

Status: Needs review » Needs work

@thsutton, this error occurs when module_implements() is being called. Can you describe the steps to reproduce this, because I don't see this error. Your description "... later on during the installation ..." makes me think the error is not related to this issue. Can you reproduce the error with the patch reverted (git apply --reverse)?

Sutharsan’s picture

I've created #1912886: Improve installation language requirement descriptions and offline detection to tackle the problem @vijaycs85 had with determining the cause of not being able to download a translation file.

thsutton’s picture

@Sutharsan, the installation with no translation selected completed normally with and without the patch. Steps to reproduce:

  1. git pull (updates to 0a42fa60e0bec915ac82487dc30828ae476e1080)
  2. git apply install-convert-to-guzzle-1887046-30.patch
  3. Select French translation and continue
  4. Select Minimal profile and continue
  5. Enter MySQL database details and continue
  6. Error 500.

Here's the Apache error log from the start of the installation:

<pre>
[error] [client 127.0.0.1] PHP Fatal error:  Class 'Drupal\\menu_link\\MenuLinkStorageController' not found in /Users/thsutton/Sites/drupal8/htdocs/core/includes/menu.inc on line 2687
[error] [client 127.0.0.1] PHP Fatal error:  Call to a member function get() on a non-object in /Users/thsutton/Sites/drupal8/htdocs/core/includes/bootstrap.inc on line 2481, referer: http://drupal8.dev/core/install.php?langcode=fr&profile=minimal
[error] [client 127.0.0.1] File does not exist: /Users/thsutton/Sites/drupal8/htdocs/favicon.ico, referer: http://drupal8.dev/core/install.php?langcode=fr&profile=minimal&op=start&id=1
[error] [client 127.0.0.1] PHP Fatal error:  Class 'Drupal\\menu_link\\MenuLinkStorageController' not found in /Users/thsutton/Sites/drupal8/htdocs/core/includes/menu.inc on line 2687, referer: http://drupal8.dev/core/install.php?langcode=fr&profile=minimal&op=start&id=1
</pre>

I tend to agree that this is unrelated, except for the fact the leaving the language as en (with or without the patch) completes the "installation profile" phase and you can continue with configuring the site and get a working install. :-)

Sutharsan’s picture

@thsutton, I still can't reproduce. It may be environment dependent, although I don't think it is likely: php 5.3.15, mysql 5.5.27 I don't get the 'MenuLinkStorageController' error either. This error is weird though, as if the auto loader failed.
Did you clean the sites/default/files directory before re-install
If you revert the #8 patch (git apply -R http://drupal.org/files/install-convert-to-guzzle-8.patch) to D8 HEAD, can you still reproduce the error?

stjin’s picture

Priority: Major » Normal

I installed the #30 patch as described above (language dutch). It works like a charm! Thanks.

hass’s picture

Priority: Normal » Major

Current DEV cannot installed if you select a language other than English. This looks still major to me.

yannickoo’s picture

Had the same problem when trying to install in German language but with patch from #30 it works fine!

tstoeckler’s picture

Status: Needs work » Reviewed & tested by the community

I think that is sufficient testing that this actually does fix the problem. Code looks good as well. Let's do this!

stjin’s picture

Yes the code does indeed fix the problem. I applied the patch then did a clean install (dutch), and it worked.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for all the manual testing.

Committed/pushed to 8.x.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

danilocgsilva’s picture

Assigned: Unassigned » danilocgsilva
Status: Closed (fixed) » Needs work

Just downloaded the 20 April dev version and faced this issue. Patch #30 doesn't worked for me: Hunk #1 FAILED at 356

Berdir’s picture

Status: Needs work » Closed (fixed)

Open a new bug report if you have a problem. This has been committed long ago.

Berdir’s picture

Issue summary: View changes

Test instructions added