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:
- Create a new user.
- Edit a node with the new user.
- 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)
- 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
Comment #2
schlaukopf commentedComment #3
schlaukopf commentedComment #4
schlaukopf commentedComment #5
tuwebo commentedHello,
I have same issue.
I have applied patch from #2 and it works for me, thanks!
Comment #6
ieguskiza commentedThe patch looks good and solves the issue.
Comment #7
chewie commentedI think also missed coverage of case when user is blocked (not just deleted).
Comment #8
joseph.olstadWe 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.
Comment #10
chr.fritschThank you. Pushed it, as it is. Plz open a follow-up for disabled users