mirror of
https://github.com/pretix/pretix.git
synced 2026-09-30 19:04:43 +00:00
[wip] Add migration to activate plugin, add plugin active check before run (23243588)
This commit is contained in:
+29
@@ -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),
|
||||
]
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user