Problem/Motivation

We get a fatal error after running the UserIntegrity sensor when there is no role assigned to users.
Fatal error: Recoverable fatal error: Argument 1 passed to Drupal\monitoring\Plugin\monitoring\SensorPlugin\UserIntegritySensorPlugin::getUserChanges() must be of the type array, null given

This is something that is very strange to happen but could be accidental. So we should avoid this.

Steps to reproduce:
- Run the sensor.
- Remove the administrator rol to admin.
- Run the sensor again.

Proposed resolution

This is happening because $current_users = $this->processUsers($this->loadCurrentUsers($role_ids)); is empty and then we trying to assert some values so we should verify if the variable is empty or not.

Comments

giancarlosotelo created an issue. See original summary.

giancarlosotelo’s picture

Status: Active » Needs review
StatusFileSize
new1.67 KB
new2.52 KB

I am adding a test only patch with just deleting the user and running the sensor, then the exception appears.

But I dont know if is the best solution just checking if we have current users with the id.

The last submitted patch, 2: 2581775-2ONLYTEST.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 2: 2581775-2.patch, failed testing.

The last submitted patch, 2: 2581775-2ONLYTEST.patch, failed testing.

The last submitted patch, 2: 2581775-2.patch, failed testing.

Status: Needs work » Needs review

giancarlosotelo queued 2: 2581775-2.patch for re-testing.

The last submitted patch, 2: 2581775-2ONLYTEST.patch, failed testing.

berdir’s picture

Status: Needs review » Needs work

Deleting a user is a valid use case, that we need to account for.

Patch looks good. I'm just wondering if we should explicitly list that user as deleted in the table, without any other data.

giancarlosotelo’s picture

We are creating new tables here #2581701: Add a second table to UserIntegrity sensor : "Users with privileged access" so what about creating a new table for deleted users?

miro_dietiker’s picture

New table is one thing... But things fall apart with too many tables... I also thought about putting both "new" and "deleted" data into the first table with an extra column...

But i'm not sure how much data we have from that deleted user and if it fits the first table well...
Possibly a separate table is best indeed.

giancarlosotelo’s picture

Status: Needs work » Needs review
Issue tags: +Need tests
StatusFileSize
new49.88 KB
new3.83 KB
new2.42 KB

Rebase and I am attaching a screenshot with the new table. I am not sure if there is another way to list the deleted users. So some feedback needed then I will add tests and probably a linkeable wid(?).

It would be better if I create a followup for the table? because this issue is about the fatal error, but somehow is related to the new table.

miro_dietiker’s picture

Status: Needs review » Needs work

As discussed the deleted users should be identified by comparing our sensor array containing the expected situation... not just list all the deleted users. :-)

giancarlosotelo’s picture

StatusFileSize
new4.9 KB

Changed the approach using the sensor array and tests.

giancarlosotelo’s picture

Status: Needs work » Needs review
miro_dietiker’s picture

Title: Fatal error: Recoverable fatal error: Argument 1 passed to Drupal\monitoring\Plugin\monitoring\SensorPlugin\UserIntegritySensorPlugin::getUserChanges() must be of the type array, null given » Fatal error when deleting a user. Add verbose table of deleted users.
Status: Needs review » Fixed
Issue tags: -Need tests
Related issues: +#2603272: Use Drupal's format date API in all the SensorPlugins

Thx, works for me. Committed. Retitling.

Fixing of the date for Drupal's API will happen here #2603272: Use Drupal's format date API in all the SensorPlugins

Status: Fixed » Closed (fixed)

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