Undefined variable $addresses AddressAdjusterBase.php:38

Created on 14 May 2024, about 1 month ago
Updated 6 June 2024, 21 days ago

Problem/Motivation

During cron runs since a couple of days I get the error

Undefined variable $addresses AddressAdjusterBase.php:38

When going to admin/reports/updates/settings I receive a different error message with the same cause:

TypeError: implode(): Argument #1 ($array) must be of type array, string given in implode() (line 106 of modules/contrib/symfony_mailer/src/Plugin/EmailAdjuster/AddressAdjusterBase.php).

Steps to reproduce

Set up a mailer policy for i. e. update notifications without any recipients (in my case by default the policy has two recipients but via config_split β†’ they are removed on the test environment.

Proposed resolution

Initialize the $addresses array before using it.

Remaining tasks

Decide whether it makes sense to call

  $addresses = [];
  // empty foreach loop
  $email->setAddress(static::NAME, $addresses);

or if it makes more sense to unset the addresses instead:

  $addresses = [];
  // empty foreach loop
  if (empty($addresses)) {
    $email->setAddress(static::NAME, NULL);
  }
πŸ› Bug report
Status

Needs work

Version

1.4

Component

Code

Created by

πŸ‡¦πŸ‡ΉAustria mvonfrie

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

Merge Requests

Comments & Activities

  • Issue created by @mvonfrie
  • Pipeline finished with Success
    about 1 month ago
    Total: 165s
    #172441
  • πŸ‡¦πŸ‡ΉAustria mvonfrie

    Addition: Removing the recipients to prevent sending updates was the only way when Drupal used swiftmailer, as the update manager only has two options for the email notification threshold: all updates or only security updates, but no option to not send a notification.

    After applying the MR on my site and looking into the policy I found the "skip sending" adjuster which is the correct way of not sending notifications on the test environment. But still there might be other use cases where the recipients are evaluated dynamically (or defined by users) and can be none, so the code still should handle that properly.

  • Status changed to Needs work 21 days ago
  • πŸ‡¬πŸ‡§United Kingdom AdamPS

    I believe the steps to reproduce are wrong. If you want no recipients then you don't add the adjuster. If you add the adjuster but don't set any address, then you get an error like "You must set at least one To address." On your site where you have the problem, then if you tried to edit the policy then you would also see the same error.

    The address adjuster should never have config without any addresses, and it enforces this. If you edit the config programmatically to create illegal config then that is not the fault of this module.

    Skip sending is entirely different - it blocks the email entirely which is not the same as having no "To" address (in which case you could still have a "Bcc").

Production build 0.69.0 2024