Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support hook_post_update_X(). #1603

Merged
merged 2 commits into from
Oct 6, 2015
Merged

Support hook_post_update_X(). #1603

merged 2 commits into from
Oct 6, 2015

Conversation

jhedstrom
Copy link
Member

// Apply post update hooks.
$post_updates = \Drupal::service('update.post_update_registry')->getPendingUpdateFunctions();
if ($post_updates) {
$operations[] = ['drupal_flush_all_caches', []];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm.

  1. I'm not sure why this needs to be added. I fear that we are going to clear caches twice. Does Drupal UI do that?
  2. We always clear caches in a separate process now which can be skipped via an option. You can replace drupal_flush_all_caches() with drush_drupal_cache_clear_all().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the patch that just landed calls that function between hook_update_N implementations and the new hook:

    if ($post_updates) {
      // Now we rebuild all caches and after that execute the hook_post_update()
      // functions.
      $operations[] = ['drupal_flush_all_caches', []];
      foreach ($post_updates as $function) {
        $operations[] = ['update_invoke_post_update', [$function]];
      }
    }

I will re-work to use drush_drupal_cache_clear_all().

@weitzman
Copy link
Member

weitzman commented Sep 9, 2015

It would be unicorn awesome if we had tests for updb. Just saying.

@greg-1-anderson
Copy link
Member

I have a question of the opposite bent: is it now necessary for use to invariably clear the cache prior to a post-update operation?

Referring to https://www.drupal.org/node/2538108 again, imagine that there is some hook 8001, that makes a schema change, and a follow-on hook 8002 that needs to run as a post-update operation, with all hook options. If hook 8001 makes some change that invalidates caches, then it would be necessary to clear the caches before running hook 8002, or the results of the post-update hook would be unpredictable.

Also, the reason we allowed cache-clearing to be skipped via an option is to allow users to do multiple cache-clearing operations back-to-back, followed by one manual cache-clear at the end. I'm not sure that it is always safe to do that in the case of updatedb, though.

The bugaboo about updatedb functional tests and cache invalidation is that it's hard to know that you've really covered all contingencies; however, I agree that it would be super awesome to have at least one test that adequately covered one use case that was sufficiently complex (and no more so).

Something like:

  1. Provide a 'demo' module in three versions:
    a. A base 8.x-1.0 version with no update hooks that initializes some data.
    b. An 8.x-1.1 version with an 8001 update hook, and an 8002 post-update hook
    c. An 8.x-1.2 version with an 8003 update hook.
  2. Run two tests, starting with a fresh D8 base install for each one:
    a. Stepwise update:
    - Install base version, test data
    - Update to 8.x-1.1, run updatedb, test data
    - Update to 8.x-1.2, run updatedb, test data
    b. Skipped update:
    - Install base version, test data
    - Update to 8.x-1.2, run updatedb, test data

I think it would be best to just have the three "versions" in three different folders and "update" them via a filesystem copy, not via the pm code. The module should provide an API function that could be called from the test to verify the data; the verify function can be different in each "version".

Not sure what the best update_N function should be; ideally, something that actually used Drupal APIs to set up and alter its schema would be best.

@jhedstrom
Copy link
Member Author

It would be unicorn awesome if we had tests for updb. Just saying.

With the db dumps in D8 for testing, we may be able to extend core's UpdatePathTestBase just enough to test our own updates. We can pick that up in #1453.

@jhedstrom
Copy link
Member Author

Oh, just realized #1453 is closed.

@weitzman
Copy link
Member

weitzman commented Oct 4, 2015

@jhedstrom - Feel free to merge this when satisfied

@jhedstrom
Copy link
Member Author

Sorry, was on vacation--doing final review now.

jhedstrom added a commit that referenced this pull request Oct 6, 2015
@jhedstrom jhedstrom merged commit eab44eb into master Oct 6, 2015
@jhedstrom jhedstrom deleted the post-update-hooks branch October 6, 2015 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants