<?php
namespace App\EventSubscriber;
use Pimcore\Mail;
use Pimcore\Model\DataObject\News;
use Pimcore\Model\DataObject\AdvanceCustomNotification;
use Pimcore\Event\Model\DataObjectEvent;
use Pimcore\Model\DataObject\CustomNotification;
use Pimcore\Model\DataObject\Location;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class LocationEventListener
{
public function onPreDelete(DataObjectEvent $event)
{
$object = $event->getObject();
if ($object instanceof Location) {
$customNotification = new CustomNotification\Listing();
$customNotification->filterByLocation($object);
foreach ($customNotification as $custNotification) {
$custNotification->delete();
}
$objectID = $object->getId();
$notifConfig = new AdvanceCustomNotification\Listing();
$notifConfig->addFieldCollection("notificationRule");
$condition = "`notificationRule`.o_id IN (
SELECT src_id FROM object_relations_AdvanceCustomNotification
WHERE dest_id = ? AND type = 'object' AND fieldname = 'location' AND ownertype = 'fieldcollection' AND ownername = 'AdvanceCustomNotification'
)";
$notifConfig->setCondition($condition, [$objectID]);
$notifConfig->load();
$uniqueNotifConfigs = [];
foreach ($notifConfig as $config) {
$uniqueNotifConfigs[$config->getId()] = $config;
}
foreach ($uniqueNotifConfigs as $notification) {
$notification->delete();
}
}
}
}