Revision User enabled getting php error if the previous user is an Anonymous

Created on 14 December 2021, almost 3 years ago
Updated 10 September 2024, 2 months ago

Problem/Motivation

When the previous user is an Anonymous user getting php error as below

The website encountered an unexpected error. Please try again later.
Error: Call to a member function getEmail() on null in Drupal\content_moderation_notifications\Notification->sendNotification() (line 146 of modules/contrib/content_moderation_notifications/src/Notification.php).

Drupal\content_moderation_notifications\Notification->sendNotification(Object, Array) (Line: 92)

Drupal\content_moderation_notifications\Notification->processEntity(Object) (Line: 29)

content_moderation_notifications_entity_update(Object)

call_user_func_array('content_moderation_notifications_entity_update', Array) (Line: 403)

Drupal\Core\Extension\ModuleHandler->invokeAll('entity_update', Array) (Line: 201)

Drupal\Core\Entity\EntityStorageBase->invokeHook('update', Object) (Line: 800)

Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('update', Object) (Line: 530)

Drupal\Core\Entity\EntityStorageBase->doPostSave(Object, 1) (Line: 685)

Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object, 1) (Line: 455)

Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 801)

Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 339)

Drupal\Core\Entity\EntityBase->save() (Line: 270)

Drupal\node\NodeForm->save(Array, Object)

call_user_func_array(Array, Array) (Line: 113)

Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)

Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 602)

Drupal\Core\Form\FormBuilder->processForm('node_page_edit_form', Array, Object) (Line: 321)

Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)

Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)

Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)

call_user_func_array(Array, Array) (Line: 123)

Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 578)

Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)

Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)

Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)

Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)

Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)

Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)

Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 49)

Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 47)

Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)

Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)

Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 717)

Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

step 1 :Create a user and login into admin and remember to enable notification to revision user
step 2: modify any of the article
step 3 delete the newly created user and choose the option to keep the content and make owner as Anonymous user
step 4: edit the previously edited article and save the article will end with php error as above

Proposed resolution

Add a validation to Revision user data before calling the getEmail() function.

Remaining tasks

Nil

User interface changes

Nil

API changes

Nil

Data model changes

Nil

🐛 Bug report
Status

Needs review

Version

3.3

Component

Code

Created by

🇮🇳India Abdul Vahab M

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇬🇧United Kingdom AndyF

    I'm experiencing the same problem with I suspect the same cause: the revision user no longer exists.

    step 3 delete the newly created user and choose the option to keep the content and make owner as Anonymous user

    I tried everything I could to reproduce the errors, followed the steps you provided but still no errors were shown to me.

    I don't think the issue presents when you use the UI (because node_user_cancel() will update the revision uid to 0). However if you just bluntly run drush ev '\Drupal\user\Entity\User::load(123)->delete();' using the UID of the author of the latest revision of a node, then you won't be able to update the node and save.

  • 🇬🇧United Kingdom AndyF

    In case it helps, I cleaned things up by running

    UPDATE {node_revision}
    LEFT JOIN {users}
    ON {node_revision}.revision_uid = {users}.uid
    SET revision_uid = 0
    WHERE uid IS NULL
    

    Thanks!

  • Status changed to Needs review 5 months ago
  • 🇺🇦Ukraine Tyapchyc

    Hello @rob-holmes, @jhedstrom

    Could you please check this?

    Thank you

Production build 0.71.5 2024