To reproduce:

1. Set up your filesystem so the webserver owns the files (easiest way to test this).
2. Download the contrib theme release from https://www.drupal.org/node/2398343 and install it on a Drupal 8 site (use the patch from #2042447: Install a module user interface does not install modules (or themes) if you want to install it with the Update Manager).
2. Go to admin/theme/update. It correctly tells you there's a newer version and lets you download the files.
3. But nothing happens after that. It essentially makes it look like you're finished and has a success message on the screen, but never takes you to the next screen (as Drupal 7 does) to actually replace your existing copy of the theme with the downloaded new copy.

Part of this is fixed by #2042447: Install a module user interface does not install modules (or themes) but the fundamental problem here can be seen from comparing update_manager_download_batch_finished(), which is a batch "finished" callback, between Drupal 7 and Drupal 8:

https://api.drupal.org/api/drupal/modules!update!update.manager.inc/function/update_manager_download_batch_finished/7 (Drupal 7)
https://api.drupal.org/api/drupal/core!modules!update!update.manager.inc/function/update_manager_download_batch_finished/8 (Drupal 8)

The code in Drupal 7 does a drupal_goto() which works to send the user to the next step; the blind replacement of that with a RedirectResponse in Drupal 8 does nothing since there's no mechanism for batch finished callbacks to return a response object and have it used.

This may require changes to the batch API to fix, to give batch finished callbacks some way to (conditionally) set a redirect.

This is a critical bug since updating existing modules and themes is one of the main purposes of the Update Manager module, and especially because people use this to perform security updates (which makes it even worse to have this fail but not be clear in the administrative interface about the fact that it failed).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

catch’s picture

David_Rothstein’s picture

Demoting doesn't really make sense to me; this is critical for at least one (and possibly two) reasons at https://www.drupal.org/node/45111 - what does the other issue have to do with issue priorities?

If this functionality were moved to contrib, it would be an equally critical bug there. In the meantime, demoting it just means developers will be less likely to work on fixing it (though I don't think that will be a problem in practice here).

Anyway, let's see if we can fix it...

David_Rothstein’s picture

Status: Active » Needs review
FileSize
3.07 KB

Here is how I would fix it (entirely within the batch API)... It seems like the ability to control the redirect from a batch 'finished' callback is a useful feature that worked in Drupal 7 but has gone missing in Drupal 8?

This patch works for me when applied on top of the one from #2042447: Install a module user interface does not install modules (or themes). (The code added in that issue should in theory allow tests to be written for this one too.)

tjaoht’s picture

I'm using Drupal 8.0.0-beta7

I had to apply both patches from #3 and then add this:

use \RecursiveIteratorIterator;
use \RecursiveDirectoryIterator;

underneath

namespace Drupal\Core\FileTransfer;

in /core/lib/Drupal/Core/FileTransfer/Local.php (around line 8)

Otherwise I get errors when installing a module due to the use of RecursiveIteratorIterator and RecursiveDirectoryIterator being used inside the Drupal\Core\FileTransfer namespace.

dawehner’s picture

FileSize
9.66 KB

Tried to write a test, but its failing for some reason in some odd way at the moment, more later.

I agree making the return statement a redirect, is a great way to add this API back.

Status: Needs review » Needs work

The last submitted patch, 5: 2426969-5.patch, failed testing.

webchick’s picture

Issue tags: +revisit July 1 2015

We spoke about this on our branch maintainer call today. While there's no way to know when we're going to hit the "~5 critical issue" threshold, the DA is in the process of planning a D8 Accelerate sprint from July 2 - 8. So July 1 is a logical date to revisit this and any other "fix it or nix it" issues. (If we still have a ridiculous number of criticals at that point, we'll move the evaluation date.)

Status: Needs work » Needs review

joelpittet queued 5: 2426969-5.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 5: 2426969-5.patch, failed testing.

joelpittet’s picture

Status: Needs work » Needs review
FileSize
9.66 KB

re-roll of #5

Status: Needs review » Needs work

The last submitted patch, 10: updating_existing-2426969-10.patch, failed testing.

David_Rothstein’s picture

Title: Updating existing modules or themes with the Update Manager does nothing (files are downloaded but no next steps are provided) » Dynamic redirects are no longer possible in the batch API (breaks updating existing modules or themes with the Update Manager)
Component: update.module » batch system
Issue tags: -revisit July 1 2015

I'll take a look and see if I can figure out the failing tests.

In the meantime, moving this to the batch API queue since the code to fix this is entirely in the batch API - it needs fixing and review there regardless of the Update Manager. (We should still write an Update Manager test for this once #2042447: Install a module user interface does not install modules (or themes) is committed, though.)

David_Rothstein’s picture

This should do it, I think. Expecting two failures from the tests-only patch.

No interdiff from #10 because I also moved the new test to its own method, and cleaned up the commented-out code, etc. But here are the two essential changes:

     // Displaying the page triggers batch 1.
     $this->drupalGet('batch-test/finish-redirect');
     $this->assertBatchMessages($this->_resultMessages('batch_1'), 'Batch for step 2 performed successfully.');
     $this->assertEqual(batch_test_stack(), $this->_resultStack('batch_1'), 'Execution order was correct.');
-    $this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
+    $this->assertText('Test page text.', 'Custom redirection after batch execution displays the correct page.');
     $this->assertUrl(Url::fromRoute('test_page_test.test_page'));

This was just asserting the wrong thing. We are trying to force a redirect to the custom "test page" in this case, so we need to assert the text that appears on that page.

 function _batch_test_finished_1_finished($success, $results, $operations) {
   _batch_test_finished_helper(1, $success, $results, $operations);
-  return new RedirectResponse(Url::fromRoute('test_page_test.test_page')->toString());
+  return new RedirectResponse(Url::fromRoute('test_page_test.test_page', [], ['absolute' => TRUE])->toString());
 }

This I don't entirely understand why it's necessary, but absolute URLs seem to be the way to go here to make the tests pass. (And interestingly, the Update Manager itself is already using an absolute URL in its batch finished callback - that's how I got the idea to try it here.)

The last submitted patch, 13: update-manager-batch-fix-2426969-13-TESTS-ONLY.patch, failed testing.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

Read through the code, tests and comments and everything seems to be in order.

This resolves dynamic redirects from the Batch API as the title suggests with RedirectResponse objects being returned from the finished callback.

Of course it would be nice to have an OOP batch api, but this fixes the bug;)

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

The tests and the docs look good and this is fixing a regression from Drupal 7. I think this is worth fixing regardless of what happens to the update UI.

This issue addresses a major bug and is allowed per https://www.drupal.org/core/beta-changes. Committed e59a45f and pushed to 8.0.x. Thanks!

  • alexpott committed e59a45f on 8.0.x
    Issue #2426969 by David_Rothstein, joelpittet, dawehner: Dynamic...
David_Rothstein’s picture

Since this was committed before #2042447: Install a module user interface does not install modules (or themes) it went in without tests for the Update Manager. I created a new issue with a patch for the tests at #2548511: Write tests for the Update Manager downloading and applying updates for a module now (seems pretty important to get that in so this problem can't regress).

Status: Fixed » Closed (fixed)

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