drush-ops/drush — pull request #399 by davereid (2014-01-22 01:11:05+00:00)
Title: Running drush updatedb causes an incomplete module implements cache

### Steps to reproduce:
1. Install the token module on a clean Drupal 7 site.
2. Add `var_export(module_implements('module_implements_alter'));` to the bottom of the update_main_prepare() function in commands/core/drupal/update_7.inc
3. Run drush updatedb

### Expected results:
`array(0 => 'token')`

### Actual results:
`array()`

### Reason

The [update_main_prepare()](http://api.drush.org/api/drush/commands!core!drupal!update_7.inc/function/update_main_prepare/6.x) function calls two functions, [drupal_maintenance_theme()](https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drupal_maintenance_theme/7) and [update_check_requirements()[(https://api.drupal.org/api/drupal/update.php/function/update_check_requirements/7) before it calls drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL). Those two functions eventually cause a module hook to get invoked, which hits module_invoke_all() before all the modules have been fully loaded by the full bootstrap. This means that for the rest of the command execution, any modules that implement hook_module_implements_alter() will never get called.

I can see this code flow in update_main_prepare() was copied from update.php in core. The way that update.php gets away with doing this is it calls those functions before a full bootstrap only on the first hit of update.php. This request never hits drupal_page_footer(), which would have caused the 'bad' module_implements cache to be written to the database from memory, because update.php never calls it. Once you've gone past the first page in update.php, it doesn't call any of those functions, until _after_ it has performed a full bootstrap.

This also explains why I have hooks go missing only when running drush updatedb, but then they work completely fine on the next request.

### Solution

I think the easy fix is to clear the module_implements() cache again before running the full bootstrap in update_main_prepare().