'page.update:after' => function ($newPage, $oldPage) {
if($newPage->intendedTemplate() == 'termin') {
// check if it makes sense to send an e-mail at all
if($newPage->isListed()
and $newPage->inFuture()
and $newPage->participantCount() > 0) {
// date or address have changed
if($oldPage->date()->value() != $newPage->date()->value()
or $oldPage->address()->value() != $newPage->address()->value()) {
// e-mails to all participants of this event (skipped the fetching of participants and their booking)
foreach($participants as $participant) {
$this->site()->sendCustomEmail('termin-aenderung', $participant['email'], $newPage->autoid(), $participant['name']);
}
}
}
}
}
You are getting the page from it’s auto id. Maybe the problem is in that plugin.
A way around it could be to pass the &newPage Object directly to the email method. This is also a performance optimisazion because in your code the page data is loaded for every single participant.
Arghh… why I didn’t think about that here… You are absolutely right! Thanks a lot @moeli!
I use autoID to ensure nothing breaks in the relation between events (i.e. an event slug changes or this kind of stuff and need it at some points) but of course it makes no sense to use this here since I have the correct page object already at hand
Now the e-mails contain the updated data (and is a little faster too)