Your software
My Mautic version is: 5.0.0
My PHP version is: 8.1.2
My question
The log output confirms that the event is being triggered, but the isNew()
condition is evaluating as false
, meaning the contact is not considered “new” by Mautic at the point when this event is fired.
public static function getSubscribedEvents()
{
return [
LeadEvents::LEAD_POST_SAVE => 'onContactSave',
];
}
public function onContactSave(LeadEvent $event)
{
$logFile = '/var/www/html/mautic/var/logs/Plugin_log.txt';
file_put_contents($logFile, 'onContactSave triggered' . PHP_EOL, FILE_APPEND);
$lead = $event->getLead();
file_put_contents($logFile, 'Lead ID: ' . $lead->getId() . PHP_EOL, FILE_APPEND);
if ($event->isNew()) {
file_put_contents($logFile, 'New contact created: ' . $lead->getName() . PHP_EOL, FILE_APPEND); // Log when the new contact is detected
} else {
file_put_contents($logFile, 'This is not a new contact.' . PHP_EOL, FILE_APPEND); // Log if the contact is not new
}