Problem/Motivation

I'm getting this error when I'm trying to edit a node that was locked by a deleted user: Call to a member function getDisplayName() on null in Drupal\content_lock\ContentLock\ContentLock->displayLockOwner() (line 186 of modules/contrib/content_lock/src/ContentLock/ContentLock.php).
Steps to reproduce the error:

  1. Create a new user.
  2. Edit a node with the new user.
  3. With an admin user delete the previous user. (Try with the option delete the user and keep the content, otherwise you might get another error)
  4. Try to edit the locked content that was being edited by the deleted user.

Proposed resolution

In order to prevent future issues a hook_user_delete() should release all locks from the user that is being deleted.
But for the existing locks, the table content_lock should be truncated or the entries should be deleted from those users.

delete from content_lock where uid = XXX;

or

truncate table content_lock;

Also you can use the devel module to run this, using the interface or a drush command

$uid = 2; // uid from the deleted user
$lock_service = \Drupal::service('content_lock');
$lock_service->releaseAllUserLocks($uid);

Comments

schlaukopf created an issue. See original summary.

schlaukopf’s picture

schlaukopf’s picture

Status: Active » Needs review
schlaukopf’s picture

Issue summary: View changes
tuwebo’s picture

Hello,
I have same issue.
I have applied patch from #2 and it works for me, thanks!

ieguskiza’s picture

Status: Needs review » Reviewed & tested by the community

The patch looks good and solves the issue.

chewie’s picture

I think also missed coverage of case when user is blocked (not just deleted).

joseph.olstad’s picture

We also noticed this. We're using the content lock service provided by the content_lock module in our own custom modules and in this case the historical locks have more meaning (for us) , so this patch is very much needed.

I'd say push this in and open up a followup issue for the case where a user is marked as blocked or inactive as mentioned previously.

chr.fritsch’s picture

Status: Reviewed & tested by the community » Fixed

Thank you. Pushed it, as it is. Plz open a follow-up for disabled users

Status: Fixed » Closed (fixed)

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