If I want to delete a user account with the first three setting

Disable the account and keep its content.
Disable the account and unpublish its content.
Delete the account and make its content belong to the guest user.

I get following Fatal error:

The website encountered an unexpected error. Please try again later.
Recoverable fatal error: Object of class Drupal\Core\Field\FieldItemList could not be converted to string in Drupal\Core\Database\Statement->execute() (line 59 of core/lib/Drupal/Core/Database/Statement.php).
Drupal\Core\Database\Statement->execute(Array, Array) (Line: 624)
Drupal\Core\Database\Connection->query('DELETE FROM {comment_notify_user_settings}
WHERE uid = :db_condition_placeholder_0', Array, Array) (Line: 87)
Drupal\Core\Database\Driver\mysql\Connection->query('DELETE FROM {comment_notify_user_settings}
WHERE uid = :db_condition_placeholder_0', Array, Array) (Line: 55)
Drupal\Core\Database\Query\Delete->execute() (Line: 61)
comment_notify_delete_user_notification_setting(Object) (Line: 256)
comment_notify_user_cancel(Array, Object, 'user_cancel_block')
call_user_func_array('comment_notify_user_cancel', Array) (Line: 402)
......

But with the last option "Delete the account and its content" its no problem to delete the account.

After unistalling the module I dont have the problem

I reinstalled the module and there were also following notices:

Notice: Trying to get property of non-object in comment_notify_form_user_form_alter() (line 215 of modules/contrib/comment_notify/comment_notify.module).
comment_notify_form_user_form_alter(Array, Object, 'user_form') (Line: 501)
Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object, 'user_form') (Line: 819)
Drupal\Core\Form\FormBuilder->prepareForm('user_form', Array, Object) (Line: 272)
Drupal\Core\Form\FormBuilder->buildForm('user_form', Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)
......

Notice: Trying to get property of non-object in comment_notify_form_user_form_alter() (line 231 of modules/contrib/comment_notify/comment_notify.module).
comment_notify_form_user_form_alter(Array, Object, 'user_form') (Line: 501)
Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object, 'user_form') (Line: 819)
Drupal\Core\Form\FormBuilder->prepareForm('user_form', Array, Object) (Line: 272)
Drupal\Core\Form\FormBuilder->buildForm('user_form', Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
.....

As long i dont want to keep content of users its not a problem ;-)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MartinMa created an issue. See original summary.

kmonahan’s picture

I encountered the same fatal error when canceling user accounts but retaining the content, whether the cancellation was done by an admin or by allowing users to cancel their own accounts. Issue seems to be that $account->uid does not return the account ID integer but rather the Field Item object for the uid field. Changing to $account->id() fixes the issue for me.

kmonahan’s picture

Status: Needs work » Needs review
id.conky’s picture

Have this issue too, #2 worked, but better to add type to $account function argument, like this: \Drupal\user\Entity\User $account

gnuget’s picture

I had to modify a bit #2 because it seems that when an account is deleted (not canceled) the hook_user_cancel() is not triggered and the settings weren't deleted.

That is why the "Delete the account and its content" option was apparently working.

Tests and patch.

David.

The last submitted patch, 5: 2884595-5-test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • gnuget committed da54d1d on 8.x-1.x
    Issue #2884595 by gnuget, kmonahan, MartinMa: Can delete user only with...
gnuget’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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