Hello.

Will be short.

I see "Recoverable fatal error: Argument 1 passed to Drupal\Core\Session\AccountSwitcher::switchTo() must implement interface Drupal\Core\Session\AccountInterface, null given".

How to reproduce?

  1. Create a user
  2. Subscriber user to any newsletter
  3. Delete user from drupal (the site still has user uid in DB as subscriber)
  4. Try to send a newsletter by cron.

Going to provide a patch.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Ruslan P created an issue. See original summary.

Ruslan Piskarov’s picture

Ruslan Piskarov’s picture

Status: Patch (to be ported) » Reviewed & tested by the community
Ruslan Piskarov’s picture

Assigned: Ruslan Piskarov » Unassigned
Ruslan Piskarov’s picture

I think in the feature will be better to implement the functionality -> then a user is deleting from a site, unsubscribe a user from each newsletter.
However, my hot patch works well, too.

Ruslan Piskarov’s picture

Status: Reviewed & tested by the community » Needs review
jonathanshaw’s picture

$current_subscriber = User::load($this->uid);
if (is_object($current_subscriber)) {
  \Drupal::service('account_switcher')->switchTo($current_subscriber);
}

Could this be simplified to:

if ($current_subscriber = User::load($this->uid)) {
  \Drupal::service('account_switcher')->switchTo($current_subscriber);
}

?

That's basically what you did for the other hunk:

-    if ($this->uid) {
+    if ($this->uid && User::load($this->uid)) {
I think in the feature will be better to implement the functionality -> then a user is deleting from a site, unsubscribe a user from each newsletter.

Simplenews subscribers can be anonymous users, so I'm not sure this should be the automatic behavior. It's very easy to implement using hooks if a site wants to do that, probably not necessary to force it to be that way. It'd be harder to allow sites to prevent it than it is to allow sites to do it themselves.

Ruslan Piskarov’s picture

Hello @jonathanshaw .

I agree with you. Attaching a new patch.

Ruslan Piskarov’s picture

Issue summary: View changes
jonathanshaw’s picture

Issue tags: +Needs tests

Great! Sorry Ruslan, I forgot to say: the maintainers are probably going to want a test for this before they commit it.

AdamPS’s picture

Status: Needs review » Needs work

Confirm that normal policy for this module is that tests are needed - in the long run it's the best way to get a stable module.

There can be exceptions for example if you are fixing a small bug in a certain feature, and there are no existing tests to adapt.

Ruslan Piskarov’s picture

Ok, will create test when will have time. Thank you. I don't have currency the project which uses simplenews.

AdamPS’s picture

Status: Needs work » Postponed (maintainer needs more info)

In simplenews_user_delete() there is code to delete the subscriber so maybe this is now fixed?