Problem/Motivation

I have noticed If I try to cancel a user account which has more then 10 content I get a php error. "TypeError: Argument 1 passed to _node_mass_update_helper() must implement interface Drupal\node\NodeInterface, null given, called in /var/www/html/web/core/modules/node/node.admin.inc on line 135 in _node_mass_update_helper()"

I have started to debug the problem and the problem is that the action call the _user_cancel() method directly.
I see you try to follow the login of user_cancel() method.
- invoke user_cancel hook
- call _user_cancel method.

The problem is that node_user_cancel()(user_cancel hook) call node_mass_update method which create a new batch process with _node_mass_update_batch_process if a user has then 10 content.
The user_cancel() method call _user_cancel in batch which will delete node revisions.
The Batch API will execute the "methods" in FIFO order, so it will execute _node_mass_update_batch_process then _user_cancel.

If the _node_mass_update_batch_process run after _user_cancel it will fail with php error above because the revision isn't available, so it cannot load nodes.

Steps to reproduce

- Create a authenticated user
- Create more then 10 nodes with this account
- Create a user list with views and set the vbo_cancel_user_action action
- Login with user 1
- go to previously views page
- try to cancel the user account(with "Delete the account and make its content belong to the Anonymous user. Reassign its groups to the super administrator". option) which has more then 10 content

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

segi created an issue. See original summary.

segi’s picture

Issue summary: View changes
segi’s picture

Currently I don't know which way the best to fix this bug. I'm open for suggestions.

segi’s picture

Issue summary: View changes
graber’s picture

Did you try to cancel that user without using VBO?

VBO's action just calls core methods (_user_cancel() function exactly) for each selected account so seems strange..

segi’s picture

Yes, I try to cancel the user account on /admin/people and it has worked.
The only difference what I noticed is that you call directly _user_cancel() method the core calls it in user_cancel() method as a batch operation. I think the problem here is method execution order. There is a hook_user_cancel method which calls node_mass_update() which call node_mass_update method where the first param is a set of node revision idea. The node_mass_update checks this parameter and if it contains more then 10 element create a batch operation.
My theory is that if we call more times batch_set under an execution the drupal will execute it in the same order as it was added to batch.
So firstly _node_mass_update_batch_process then _user_cancel(), but in VBO you overpass the order with calling directly _user_cancel() method.
The _user_cancel() deletes the node revisions so when batch execute the _node_mass_update_batch_process operation the revisions won't be available, so it cannot load nodes.

I hope this explanation was clear. :)

segi’s picture

I didn't find better solution then put back the batch process from user_cancel, but it looks like working.

bbeversdorf’s picture

I had the same issue with the latest (4.2.0) too. Here is an updated version of the patch that works for me.

bbeversdorf’s picture

StatusFileSize
new2.05 KB
bbeversdorf’s picture

StatusFileSize
new1.4 KB
graber’s picture

Sorry, seems I completely missed updates to this issue a year ago. Not sure how calling a batch process within a batch process may behave.. did you test this with multiple users that have more than 10 content each?

graber’s picture

Version: 8.x-3.x-dev » 4.2.x-dev
Status: Active » Needs review

  • Graber committed 2aeba46 on 4.2.x
    Issue #3216584 by segi, bbeversdorf: Unable to cancel a user account if...
graber’s picture

Status: Needs review » Fixed

Ok, tested as described and all works fine. Thanks!

Status: Fixed » Closed (fixed)

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