From c79644e0022be7e5dee73151c044ec77c04f51a4 Mon Sep 17 00:00:00 2001 From: Phin Wolkwitz Date: Tue, 22 Sep 2026 18:58:07 +0200 Subject: [PATCH] [wip] Add migration to activate plugin, add plugin active check before run (23243588) --- ..._plugin_for_events_with_scheduled_mails.py | 29 +++++++++++++++++++ src/pretix/plugins/sendmail/signals.py | 2 ++ 2 files changed, 31 insertions(+) create mode 100644 src/pretix/plugins/sendmail/migrations/0013_activate_plugin_for_events_with_scheduled_mails.py diff --git a/src/pretix/plugins/sendmail/migrations/0013_activate_plugin_for_events_with_scheduled_mails.py b/src/pretix/plugins/sendmail/migrations/0013_activate_plugin_for_events_with_scheduled_mails.py new file mode 100644 index 000000000..7a62e643f --- /dev/null +++ b/src/pretix/plugins/sendmail/migrations/0013_activate_plugin_for_events_with_scheduled_mails.py @@ -0,0 +1,29 @@ +from django.db import migrations +from django.db.models import Exists, OuterRef + + +def activate_plugin(apps, schema_editor): + Event = apps.get_model("pretixbase", "Event") + ScheduledMail = apps.get_model("sendmail", "ScheduledMail") + events = ( + Event.objects + .exclude(plugins__icontains="pretix.plugins.sendmail") + .filter( + Exists( + ScheduledMail.objects.filter(event=OuterRef('pk')).exclude(state=ScheduledMail.STATE_COMPLETED) + ) + ) + ) + for event in events: + event.enable_plugin('pretix.plugins.sendmail') + event.save(update_fields=['plugins']) + + +class Migration(migrations.Migration): + dependencies = [ + ("sendmail", "0012_remove_cross_event_scheduled_mails"), + ] + + operations = [ + migrations.RunPython(activate_plugin), + ] diff --git a/src/pretix/plugins/sendmail/signals.py b/src/pretix/plugins/sendmail/signals.py index 76626097f..bdc512a28 100644 --- a/src/pretix/plugins/sendmail/signals.py +++ b/src/pretix/plugins/sendmail/signals.py @@ -150,6 +150,8 @@ class SendmailPluginRuleLogEntryType(EventLogEntryType): @receiver(periodic_task) def sendmail_run_rules(sender, **kwargs): + if "pretix.plugins.sendmail" not in sender.get_plugins(): + return # do not send scheduled mails if this plugin is disabled with scopes_disabled(): mails = ScheduledMail.objects.all()