![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/mautic.corals.io/app/bundles/LeadBundle/EventListener/ |
<?php namespace Mautic\LeadBundle\EventListener; use Mautic\CoreBundle\Helper\IpLookupHelper; use Mautic\CoreBundle\Model\AuditLogModel; use Mautic\LeadBundle\Event as Events; use Mautic\LeadBundle\LeadEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class CompanySubscriber implements EventSubscriberInterface { public function __construct( private IpLookupHelper $ipLookupHelper, private AuditLogModel $auditLogModel ) { } public static function getSubscribedEvents(): array { return [ LeadEvents::COMPANY_POST_SAVE => ['onCompanyPostSave', 0], LeadEvents::COMPANY_POST_DELETE => ['onCompanyDelete', 0], ]; } /** * Add a company entry to the audit log. */ public function onCompanyPostSave(Events\CompanyEvent $event): void { $company = $event->getCompany(); if ($details = $event->getChanges()) { $log = [ 'bundle' => 'lead', 'object' => 'company', 'objectId' => $company->getId(), 'action' => ($event->isNew()) ? 'create' : 'update', 'details' => $details, 'ipAddress' => $this->ipLookupHelper->getIpAddressFromRequest(), ]; $this->auditLogModel->writeToLog($log); } } /** * Add a company delete entry to the audit log. */ public function onCompanyDelete(Events\CompanyEvent $event): void { $company = $event->getCompany(); $log = [ 'bundle' => 'lead', 'object' => 'company', 'objectId' => $company->deletedId, 'action' => 'delete', 'details' => ['name', $company->getPrimaryIdentifier()], 'ipAddress' => $this->ipLookupHelper->getIpAddressFromRequest(), ]; $this->auditLogModel->writeToLog($log); } }