Improve upgrade path from 8.x-1.x to 2.0.x

Created on 19 April 2023, about 1 year ago
Updated 24 May 2023, about 1 year ago

Problem/Motivation

With current update path from 8.x-1.5 to 2.0.0 you need to use 2 steps to upgrade from 8.x-1.x to 2.0.x which is already mentioned in release notes of 2.0.0 release.

  1. First people need to add and enable flexible_permissions module on projects with group 8.x-1.x.
  2. Only then it is possible to upgrade from group 8.x-1.5 to 2.0.0 without breaking your site.

For people who already use a composer workflow to manage their group related Drupal projects this upgrade process could be improved very simple by adding an extra hook_update_N() as first update hook to group 2.0.x module.

Steps to reproduce

  1. Setup Drupal 9 project with group 8.x-1.5 module via composer.
  2. Update this project via composer from group 8.x-1.5 to 2.0.0 this will download flexible_permissions module via composer.
  3. Run drush updb command to trigger all group 2.0.0 related updates without previously enabling flexible_permissions module.
  4. Updated site will now throw following error.
The website encountered an unexpected error. Please try again later.
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: The service "group_permission.calculator" has a dependency on a non-existent service "flexible_permissions.chain_calculator". in Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass->processValue() (line 86 of /home/public_html/staging/vendor/symfony/dependency-injection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php).

Proposed resolution

Add following hook_update_N() to group.install file:

/**
 * Install required flexible_permissions contrib module.
 */
function group_update_9200() {
  \Drupal::service('module_installer')->install(['flexible_permissions'], TRUE);
}

Remaining tasks

Check if this also work for people who do not use composer workflow to manage their Drupal group related projects.

User interface changes

No user interface changes.

API changes

No API changes.

Data model changes

No data model changes.

📌 Task
Status

Fixed

Version

2.0

Component

Code

Created by

🇩🇪Germany IT-Cru Munich

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @IT-Cru
  • Status changed to Needs review about 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    9,622 pass
  • 🇧🇪Belgium kristiaanvandeneynde Antwerp, Belgium

    Out of curiosity, what would happen if you run this update hook without having flexible_permissions in your code base. A quick glance at ModuleInstaller does not seem to show any code checking whether the module is actually there. Trying to make sure non-Composer workflows don't get even more problems if I were to commit this patch.

  • 🇩🇪Germany IT-Cru Munich

    @kristiaanvandeneynde I will try to test manual update process together with my patch without downloaded flexible_permissions module tomorrow morning on my way to office or in the evening on my way back to home and give here some feedback. I think currently it will throw some exception error from module_installer service.

  • 🇧🇪Belgium kristiaanvandeneynde Antwerp, Belgium

    Cool, thanks!

  • 🇩🇪Germany markdc Hamburg

    Applied the patch and ran composer update. flexible_permissions is not downloaded as a dependency.

    Ran drush updb and got this as IT-Cru expected:

    Module   Update ID   Type            Description                           
     -------- ----------- --------------- -------------------------------------- 
      group    9200        hook_update_n   9200 - Install required               
                                           flexible_permissions contrib module.  
     -------- ----------- --------------- -------------------------------------- 
    
    
     Do you wish to run the specified pending updates? (yes/no) [yes]:
     > y
    
    >  [notice] Update started: group_update_9200
    >  [warning] Undefined array key "flexible_permissions" ModuleInstaller.php:125
    >  [warning] Attempt to read property "info" on null ModuleInstaller.php:125
    >  [warning] Trying to access array offset on value of type null ModuleInstaller.php:125
    >  [warning] Undefined array key "flexible_permissions" ModuleInstaller.php:128
    >  [warning] Attempt to read property "info" on null ModuleInstaller.php:128
    >  [warning] Trying to access array offset on value of type null ModuleInstaller.php:128
    >  [error]  Unable to install modules flexible_permissions due to missing modules flexible_permissions. 
    >  [error]  Update failed: group_update_9200 
     [error]  Update aborted by: group_update_9200 
     [error]  Finished performing updates. 
  • 🇩🇪Germany IT-Cru Munich

    Results of my tests with my added update hook group_update_9200().

    1. Upgrade test - Manual downloaded group without flexible_permissions module

    Here I only downloaded group module 2.0.0 from d.o and replaced existing 8.x-1.5 one WITHOUT manual downloading of flexible_permissions module.

    drush updb
     [error]  Group requires this module.
     (Currently using Unresolved dependency flexible_permissions (Missing)
    ) 
     [error]  Group Node requires this module.
     (Currently using Unresolved dependency flexible_permissions (Missing)
    ) 
    
     Requirements check reports errors. Do you wish to continue? (yes/no) [yes]:
     > n
    
    
    In UpdateDBCommands.php line 51:
                  
      Cancelled.  
                  
    
    Failed to run drush updb: exit status 1
    

    This results in a broken website with following error, but not from my update hook because of previous internal dependency checks.

    drush status
    
    In CheckExceptionOnInvalidReferenceBehaviorPass.php line 86:
                                                                                                                                     
      The service "group_permission.calculator" has a dependency on a non-existent service "flexible_permissions.chain_calculator".  
                                                                                                                                     
    
    Failed to run drush status: exit status 1
    

    2. Upgrade test - Manual downloaded group and flexible_permissions modules

    Here I downloaded group 2.0.0 from d.o and replaced existing 8.x-1.5 one and manual downloaded flexible_permissions 1.0.0 module.

    drush updb                                    
     -------- ----------- --------------- ----------------------------------------------------------------------------------- 
      Module   Update ID   Type            Description                                                                        
     -------- ----------- --------------- ----------------------------------------------------------------------------------- 
      group    9200        hook_update_n   9200 - Install required flexible_permissions contrib module.                       
      group    9201        hook_update_n   9201 - Update class name and handler class names for group_content_type.           
      group    9202        hook_update_n   9202 - Update class name and handler class names for group_content.                
      group    9203        hook_update_n   9203 - Update group_content DB table, fields and indexes.                          
      group    9204        hook_update_n   9204 - Remove the 'bypass group access' permission from all roles.                 
      group    9205        hook_update_n   9205 - Convert group roles with the 'administer group' permission to admin roles.  
      group    9206        hook_update_n   9206 - Convert synchronized group roles to new scope and target_role structure.    
      group    9207        hook_update_n   9207 - Convert default group roles to new scope and target_role structure.         
      group    9208        hook_update_n   9208 - Convert user created group roles to new scope and target_role structure.    
      group    9209        hook_update_n   9209 - Remove label and description from relationship types.                       
      group    9210        hook_update_n   9210 - Introduce the group_config_wrapper entity type.                             
     -------- ----------- --------------- ----------------------------------------------------------------------------------- 
    
    
     Do you wish to run the specified pending updates? (yes/no) [yes]:
     > y
    
    >  [notice] Update started: group_update_9200
    >  [notice] Update completed: group_update_9200
    >  [notice] Update started: group_update_9201
    >  [notice] Update completed: group_update_9201
    >  [notice] Update started: group_update_9202
    >  [notice] Update completed: group_update_9202
    >  [notice] Update started: group_update_9203
    >  [notice] Update completed: group_update_9203
    >  [notice] Update started: group_update_9204
    >  [notice] Update completed: group_update_9204
    >  [notice] Update started: group_update_9205
    >  [notice] Update completed: group_update_9205
    >  [notice] Update started: group_update_9206
    >  [notice] Update completed: group_update_9206
    >  [notice] Update started: group_update_9207
    >  [notice] Update completed: group_update_9207
    >  [notice] Update started: group_update_9208
    >  [notice] Update completed: group_update_9208
    >  [notice] Update started: group_update_9209
    >  [notice] Update completed: group_update_9209
    >  [notice] Update started: group_update_9210
    >  [notice] Update completed: group_update_9210
     [success] Finished performing updates.
    

    3. Upgrade test - Update group module via composer

    Here I change my group entry in composer.json from "drupal/group": "^1.0" to "drupal/group": "^1.0 || ^2.0".

    composer update drupal/group
    Gathering patches for root package.
    Loading composer repositories with package information
    Updating dependencies
    Lock file operations: 1 install, 1 update, 0 removals
      - Locking drupal/flexible_permissions (1.0.0)
      - Upgrading drupal/group (1.5.0 => 2.0.0)
    Writing lock file
    Installing dependencies from lock file (including require-dev)
    Package operations: 1 install, 1 update, 0 removals
    Gathering patches for root package.
    Gathering patches for dependencies. This might take a minute.
      - Installing drupal/flexible_permissions (1.0.0): Extracting archive
      - Upgrading drupal/group (1.5.0 => 2.0.0): Extracting archive
    

    And than I run drush updb command without any issues.

    drush updb                                    
     -------- ----------- --------------- ----------------------------------------------------------------------------------- 
      Module   Update ID   Type            Description                                                                        
     -------- ----------- --------------- ----------------------------------------------------------------------------------- 
      group    9201        hook_update_n   9201 - Update class name and handler class names for group_content_type.           
      group    9202        hook_update_n   9202 - Update class name and handler class names for group_content.                
      group    9203        hook_update_n   9203 - Update group_content DB table, fields and indexes.                          
      group    9204        hook_update_n   9204 - Remove the 'bypass group access' permission from all roles.                 
      group    9205        hook_update_n   9205 - Convert group roles with the 'administer group' permission to admin roles.  
      group    9206        hook_update_n   9206 - Convert synchronized group roles to new scope and target_role structure.    
      group    9207        hook_update_n   9207 - Convert default group roles to new scope and target_role structure.         
      group    9208        hook_update_n   9208 - Convert user created group roles to new scope and target_role structure.    
      group    9209        hook_update_n   9209 - Remove label and description from relationship types.                       
      group    9210        hook_update_n   9210 - Introduce the group_config_wrapper entity type.                             
     -------- ----------- --------------- ----------------------------------------------------------------------------------- 
    
    
     Do you wish to run the specified pending updates? (yes/no) [yes]:
     > y
    
    >  [notice] Update started: group_update_9201
    >  [notice] Update completed: group_update_9201
    >  [notice] Update started: group_update_9202
    >  [notice] Update completed: group_update_9202
    >  [notice] Update started: group_update_9203
    >  [notice] Update completed: group_update_9203
    >  [notice] Update started: group_update_9204
    >  [notice] Update completed: group_update_9204
    >  [notice] Update started: group_update_9205
    >  [notice] Update completed: group_update_9205
    >  [notice] Update started: group_update_9206
    >  [notice] Update completed: group_update_9206
    >  [notice] Update started: group_update_9207
    >  [notice] Update completed: group_update_9207
    >  [notice] Update started: group_update_9208
    >  [notice] Update completed: group_update_9208
    >  [notice] Update started: group_update_9209
    >  [notice] Update completed: group_update_9209
    >  [notice] Update started: group_update_9210
    >  [notice] Update completed: group_update_9210
     [success] Finished performing updates.
    

    @ kristiaanvandeneynde: So with my update hook upgrade is only broken, when flexible_permissions module wasn't downloaded by developer / site builder/maintainer. When it was manual or via composer downloaded flexible_permissions module gets enabled during upgrade.

    @markdc: Which exact composer update command do you use, that dependency of drupal/flexible_permissions module wasn't resolved by composer itself and how your drupal/group entry in composer.json was set?

  • Status changed to RTBC about 1 year ago
  • heddn Nicaragua

    I just tested this as well with a 2.x upgrade. Adding this as the first module to enable gives us access to it in later updates and during a final cache clear. I tested using drush deploy and using drush updb

  • 🇩🇪Germany Tomefa Dresden

    Test the patch also and the drush updb work as expected to the end.
    But still when accessing the Website or running drush cr, this error appear:

    The service "group_permission.checker" has a dependency on a non-existent service "group_permission.chain_calculator". Did you mean one of these: "flexible_permissions.chain_calculator", "group_permission.hash_generator", "group_permission.calculator", "group_permission.individual_calculator", "group_permission.synchronized_calculator"?

  • 🇩🇪Germany IT-Cru Munich

    @Tomefa: When I see it right in group.services.yml file this seems to be from 8.x-1.x services definitions. Are all your instances have new code base from group 2.0.x or 3.0.x?

  • 🇩🇪Germany Tomefa Dresden

    @it-cru: checked the file and it's group 2.0.1 that i used.
    But still the same error message, the problem appear on drush cr also. Probably the database have still the information of the old entries for this services and cannot be update.

  • 🇩🇪Germany IT-Cru Munich

    @Tomefa: Sounds a little bit like this. In my test cases cache_discovery was managed via Drupal's chainedfast caching backend and was stored in APCu and Memcached.

  • 🇩🇪Germany Tomefa Dresden

    Actually, i was using the module Group outsider in that decorate the group_permission.checker with the problematic "group_permission.chain_calculator" service.

    With group 2.x, this extra module is not anymore necessary (see ticket https://www.drupal.org/project/group/issues/2884662 ).

    Solution was to uninstall this extra module in a hook update, and now with this patch, it is working as expected.

  • Status changed to Fixed about 1 year ago
  • 🇧🇪Belgium kristiaanvandeneynde Antwerp, Belgium

    Pushed, will release alongside at least one extra bugfix as to keep the version numbers in sync with 3.0.x, which did not get this patch for obvious reasons.

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

Production build 0.69.0 2024