Problem/Motivation

Scheduled task remains in database with "reschedule" state after scheduled_email handler on webform has been deleted.

It blocks other scheduled tasks to be run via cron from webform_schedules_email module.
Watchdog registering an expectation

Drupal\Component\Plugin\Exception\PluginNotFoundException: Plugin ID 'scheduled_email' was not found. in Drupal\Core\Plugin\DefaultLazyPluginCollection->initializePlugin() (line 79 of /var/lib/tugboat/stm/web/core/lib/Drupal/Core/Plugin/DefaultLazyPluginCollection.php).

On deleting schedules_email handler all existing pending actions should be "unscheduled" accordingly with
https://git.drupalcode.org/project/webform/-/blob/6.1.x/modules/webform_...

Rescheduling is happening in ScheduleEmailWebformHandler::updateHandler() in
https://git.drupalcode.org/project/webform/-/blob/6.1.x/modules/webform_...

This method is triggered by Webform::save() in
https://git.drupalcode.org/project/webform/-/blob/6.1.x/src/Entity/Webfo...

Steps to reproduce

1. Create webform
1.1 Add field of type date
1.2 Add scheduled_email handler with "Send on:" date field from previous step +1 days
1.3 Do test submission
1.4 You should see 1 scheduled email on "Email/Handlers" tab
2. Clone webform
2.1 Do test submission
2.2 You should see 1 scheduled email on "Email/Handlers" tab
3. Remove scheduled_email handler from webform created in step 1
4. Run cron
5. Check db log

Proposed resolution

Delete pending webform_schedules_email tasks on handler deleting.

Issue fork webform-3259195

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

andr1yun created an issue. See original summary.

andriyun’s picture

Status: Active » Needs review

Please review proposed MR

jrockowitz’s picture

Status: Needs review » Needs work

The change makes sense. I think the update hook could be a little simpler, and not have to load or delete individual records. Keep in mind that some websites have 100,000+ submissions

  • Get a list of distinct webform ids and handler ids from the webform_scheduled_email table, sorted by webform id and handler id.
  • Loop thru the records
  • Check if the webform id and handler id exist.
  • If the handler id does not exist, delete all records from the webform_scheduled_email table associated with the webform id and handler id.
jrockowitz’s picture

Status: Needs work » Needs review

  • jrockowitz committed c304f52 on 6.1.x authored by andr1yun
    Issue #3259195 by andr1yun, jrockowitz: Plugin ID 'scheduled_email' was...
jrockowitz’s picture

Status: Needs review » Fixed

  • jrockowitz committed c304f52 on 6.x authored by andr1yun
    Issue #3259195 by andr1yun, jrockowitz: Plugin ID 'scheduled_email' was...

  • jrockowitz committed c304f52 on 6.2.x authored by andr1yun
    Issue #3259195 by andr1yun, jrockowitz: Plugin ID 'scheduled_email' was...

Status: Fixed » Closed (fixed)

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