2.x Update 9204 fails on some roles

Created on 27 June 2023, almost 2 years ago

Problem/Motivation

Update hook #9204 attempts to remove the 'bypass group access' permission from all roles defined on the site. This currently fails when $role->get('permissions') returns NULL rather than an empty array, due to array_diff() requiring an array as input.

Steps to reproduce

This is difficult. The problem occurs for me on a site in a multisite hosting environment that provides a number of modules not being used on the site in question. But, apparently, one role defined in one of these modules is being picked up by $config_factory->listAll('user.role.') even though the module is not enabled. When update 9204 gets to that role, $role->get('permissions') returns NULL because $role->data[] is an empty array and has no 'permissions' key to get. This causes array_diff() to fail because it expects an array instead of NULL as the first parameter.

I don't know why this role is being picked up by listAll('user.role.'). It doesn't appear in the roles UI (/admin/people/roles), but it does show up in the config factory method. Perhaps this is an issue for Core as well.

I also can't do anything about this errant role: it's code I can't touch. So, I need a solution to get the update script to handle this scenario. Fortunately that's an easy fix (see below).

Since I don't know how specifically this role is getting into my configuration (from one or more uninstalled modules), I can't explain how to reproduce the problem from a "clean" install. It's present on a "clean" install of the hosted Drupal build for the multisite environment I'm working in. (I have tested on a bare bones installation, which the only thing I've done is enabled the Group module: no Group-dependent modules and not even any Groups defined.)

Proposed resolution

The problem can be easily solved by checking whether $role->get('permissions') returns a result, and only run array_diff in that case. This should be a pretty robust solution because it's simply checking for a condition that would fail anyway, and then skipping it. It will not impact any roles that have permissions to be processed for removal of 'bypass group access'.

Remaining tasks

None (unless you want to remove or update the log message generated whenever a role is skipped).

User interface changes

None

API changes

None

Data model changes

None

πŸ› Bug report
Status

Active

Version

2.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States daletrexel Minnesota, USA

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

Comments & Activities

Production build 0.71.5 2024