Commit 6ffb6450 by Van

Remove event for update

parent ed0001e6
......@@ -30,55 +30,57 @@ class BoltSendEmailForNewContentExtension extends SimpleExtension
*/
public function hookPreSave(StorageEvent $event)
{
$app = $this->getContainer();
if(!$event->getId()) {
$app = $this->getContainer();
// Get contenttype
$contenttype = $event->getContentType();
$aNotificationsContentTypes = $this->getNotifContentTypes();
// Get contenttype
$contenttype = $event->getContentType();
$aNotificationsContentTypes = $this->getNotifContentTypes();
if ( empty($contenttype)
|| empty($aNotificationsContentTypes)
|| !in_array($contenttype, $aNotificationsContentTypes) ) {
return;
}
if ( empty($contenttype)
|| empty($aNotificationsContentTypes)
|| !in_array($contenttype, $aNotificationsContentTypes) ) {
return;
}
// Get the record : Bolt\Storage\Entity\Content
$record = $event->getContent();
// Get the record : Bolt\Storage\Entity\Content
$record = $event->getContent();
// Test if newly published
$contentNewlyPublished = false;
if ( $event->isCreate()
&& $record->getStatus() == 'published') {
$contentNewlyPublished = true;
}
else if ($record->getStatus() == 'published') {
// @todo : check if notification already sent
// use a temporary file or a db table ?
$repo = $app['storage']->getRepository($contenttype);
$oldRecord = $repo->find($record->getId() );
if ( !empty($oldRecord)
&& $oldRecord->getStatus() != 'published') {
// Test if newly published
$contentNewlyPublished = false;
if ( $event->isCreate()
&& $record->getStatus() == 'published') {
$contentNewlyPublished = true;
}
}
else if ($record->getStatus() == 'published') {
// @todo : check if notification already sent
// use a temporary file or a db table ?
$repo = $app['storage']->getRepository($contenttype);
$oldRecord = $repo->find($record->getId() );
if ( !empty($oldRecord)
&& $oldRecord->getStatus() != 'published') {
$contentNewlyPublished = true;
}
}
if ($contentNewlyPublished) {
// Launch the notification
$notify = new Notifications($app, $this->getConfig(), $record, $contenttype);
if ($contentNewlyPublished) {
// Launch the notification
$notify = new Notifications($app, $this->getConfig(), $record, $contenttype);
// Search subscribers
try {
$aSubscribers = $this->getSubscribers($contenttype);
// Search subscribers
try {
$aSubscribers = $this->getSubscribers($contenttype);
// Send email foreach subscriber
$notify->doNotification($aSubscribers);
} catch (\Exception $e) {
$app['logger.system']->error(sprintf("BoltSendEmailForNewContentExtension notifications can't be sent - %s", $e->getMessage() ), ['event' => 'extensions']);
return;
// Send email foreach subscriber
$notify->doNotification($aSubscribers);
} catch (\Exception $e) {
$app['logger.system']->error(sprintf("BoltSendEmailForNewContentExtension notifications can't be sent - %s", $e->getMessage() ), ['event' => 'extensions']);
return;
}
}
}
return;
return;
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment