Continuing the quest to a cleaner upgrade path.

Quite a few issues with this one:

  • It uses some API functions that it shouldn't. The most worrisome one is user_role_grant_permissions() which relies on user_permission_get_modules() in Drupal 7.
  • filter_update_7003() creates the new filter table based on field_schema(), which it shouldn't do because field_schema() can change, but the update function shouldn't
  • We rename the 'filters' table twice
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

Title: Clean-up the upgrade path: filter » Clean up the Filter module upgrade path
Damien Tournoud’s picture

Status: Active » Needs review

First shot at this. This patch:

  • Removes the double renaming of the filters table (filters to filter to d6_upgrade_filter)
  • Removes two useless schema change on the {filter} table: in filter_update_7000() and filter_update_7009()
  • Embeds the table schema definition in filter_update_7003()
  • Combines filter_update_7003() and filter_update_7004(): there is no reason to do two passes on the {filter} table first to migrate the delta then to migrate the settings.

The rest of the upgrade path (filter_update_7005() and filter_update_7008()) is somewhat trickier, so I hope to get this trivial part first.

Damien Tournoud’s picture

Now with patch.

sun’s picture

Damien, is it really worth to fiddle with this? The filter* tables cannot contain much data either way, so those updates may not be perfect, but who cares, as long as they work?

I'm just trying to make sense of this - my gut feeling tells me that especially both your and my time would be much better spent on critical and major issues instead of beautifying unattractive functions that are invoked only once...? If I'm missing something important, please let me know.

Status: Needs review » Needs work

The last submitted patch, 898546-cleanup-upgrade-filter.patch, failed testing.

Damien Tournoud’s picture

Status: Needs work » Needs review
FileSize
9.28 KB

@sun, as I said in #2, this first part is rather easy. The harder part is filter_update_7005() and filter_update_7008(). I published that first step so that all the other crap can be out of the way.

I want all the core update functions to be so clean you can eat of them.

This version should actually pass.

Damien Tournoud’s picture

Now complete with filter_update_7005() and filter_update_7008() fixed to not use API functions.

  • We now have a _update_user_role_grant_permissions() helper function to grant permissions to a role during update
  • I kept user_roles() in the update functions, because this is safe as long as user_update_7007() has been run, and we already have an explicit dependency between filter_update_7005() and user_update_7007()
Damien Tournoud’s picture

Priority: Normal » Critical

Critical because of the use of user_role_grant_permissions() which depends on the list of modules currently loaded.

sun’s picture

+++ modules/user/user.install
@@ -360,6 +360,31 @@ function user_update_dependencies() {
+function _update_user_role_grant_permissions($rid, array $permissions, $module) {

Can we move this function into includes/update.inc?

Powered by Dreditor.

Damien Tournoud’s picture

@sun: I'm not convinced it makes more sense in update.inc then in user.install, because we will require several of those utility functions to fix the upgrade path of Drupal 7:

David_Rothstein’s picture

Priority: Critical » Normal

As far as I know there is nothing immediately broken here, so I'm downgrading from critical. Because filter.module is a required core module, it is always guaranteed to be enabled, and it is therefore safe to use user_role_grant_permissions() and other API functions.

That said, it is probably better not to (for the sake of setting a good example for other modules)...

And I also remember seeing a patch from @chx somewhere that would force all modules to act as disabled during the upgrade; if that gets in, then I guess we would absolutely need to do this.

chx’s picture

Priority: Normal » Critical
Status: Needs review » Reviewed & tested by the community

user_role_grant_permissions call user_permission_get_modules(). We do not call modules as they can be disabled.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Eric_A’s picture

   // user_update_7006 relies on filter_update_7002.
   // TODO: move user_update_7006 down below in the upgrade process.
   $dependencies['user'][7006] = array(
-    'filter' => 7002,
+    'filter' => 7003,

It appears that first comment needs updating...?

David_Rothstein’s picture

Priority: Critical » Normal
Status: Fixed » Needs work

Yes, there is that, plus a couple other small things I noticed. I'll see if I can whip up a quick patch.

But in terms of the larger changes, I think this could still use a little more discussion:

First of all, again, this is NOT a critical issue. user_role_grant_permissions() is broken when called for a disabled module's permissions, but the filter module can never be disabled, so there isn't a problem with it. Nevertheless, it does make sense to use the separate helper function here for consistency, since most other modules have to anyway.

But I am much less sure about this idea of never using any API functions at all - that I don't understand. Some we can't use, but lower-level ones such as filter_formats() and filter_permission_name(), I don't understand why the patch removed them? I think we should consider putting them back.

David_Rothstein’s picture

Status: Needs work » Needs review
FileSize
4.73 KB

Here is a quick patch for the smaller issues. It should be mostly self-explanatory, except maybe for the cache clearing in _update_user_role_grant_permissions()... that is introduced simply because user_role_grant_permissions() has it, and if we are going to have two separate functions, we need to keep the behavior of those two as closely in sync as possible.

I think we should still discuss adding back filter_formats() and filter_permission_name() in the update functions, but I haven't done that in this patch.

thedavidmeister’s picture

Priority: Normal » Minor
Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll, +Novice

looks RTBC to me if someone can do a re-roll.

However, I'm bumping down to minor as the latest patch is almost purely code sniffs on once-off code, which as @sun said in #4, is a low priority here.

Sivaji_Ganesh_Jojodae’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
3.76 KB

Patch #16 re-rolled.

owenpm3’s picture

Status: Needs review » Reviewed & tested by the community
David_Rothstein’s picture

Status: Reviewed & tested by the community » Needs work

Doesn't look like the latest patch was tested manually... this won't work at all since the _update_user_role_grant_permissions() function no longer exists (it was changed to _update_7000_user_role_grant_permissions() a long time ago...)

Frankly I'm shocked that the automated tests didn't catch this; I guess we don't have any tests that deal with the Contact module update path :(

snehi’s picture

Status: Needs work » Needs review
FileSize
3.77 KB
724 bytes

Done as suggested by @David.

  • Dries committed 8e51c3b on 8.3.x
    - Patch #898546 by Damien Tournoud: clean up the Filter module upgrade...

  • Dries committed 8e51c3b on 8.3.x
    - Patch #898546 by Damien Tournoud: clean up the Filter module upgrade...

  • Dries committed 8e51c3b on 8.4.x
    - Patch #898546 by Damien Tournoud: clean up the Filter module upgrade...

  • Dries committed 8e51c3b on 8.4.x
    - Patch #898546 by Damien Tournoud: clean up the Filter module upgrade...
amit0212’s picture

Assigned: Unassigned » amit0212

See the Patch

Patch

  • Dries committed 8e51c3b on 9.1.x
    - Patch #898546 by Damien Tournoud: clean up the Filter module upgrade...
apaderno’s picture

Assigned: amit0212 » Unassigned