diff --git a/application/Espo/Modules/Crm/EntryPoints/SubscribeAgain.php b/application/Espo/Modules/Crm/EntryPoints/SubscribeAgain.php new file mode 100644 index 0000000000..d0a0af6da9 --- /dev/null +++ b/application/Espo/Modules/Crm/EntryPoints/SubscribeAgain.php @@ -0,0 +1,113 @@ +getEntityManager()->getEntity('EmailQueueItem', $queueItemId); + + if (!$queueItem) { + throw new NotFound(); + } + + $campaign = null; + $target = null; + + $massEmailId = $queueItem->get('massEmailId'); + if ($massEmailId) { + $massEmail = $this->getEntityManager()->getEntity('MassEmail', $massEmailId); + if ($massEmail) { + $campaignId = $massEmail->get('campaignId'); + if ($campaignId) { + $campaign = $this->getEntityManager()->getEntity('Campaign', $campaignId); + } + + $targetType = $queueItem->get('targetType'); + $targetId = $queueItem->get('targetId'); + + if ($targetType && $targetId) { + $target = $this->getEntityManager()->getEntity($targetType, $targetId); + + if ($massEmail->get('optOutEntirely')) { + $emailAddress = $target->get('emailAddress'); + if ($emailAddress) { + $ea = $this->getEntityManager()->getRepository('EmailAddress')->getByAddress($emailAddress); + if ($ea) { + $ea->set('optOut', false); + $this->getEntityManager()->saveEntity($ea); + } + } + } + + $link = null; + $m = array( + 'Account' => 'accounts', + 'Contact' => 'contacts', + 'Lead' => 'leads', + 'User' => 'users' + ); + if (!empty($m[$target->getEntityType()])) { + $link = $m[$target->getEntityType()]; + } + if ($link) { + $targetListList = $massEmail->get('targetLists'); + + foreach ($targetListList as $targetList) { + $this->getEntityManager()->getRepository('TargetList')->updateRelation($targetList, $link, $target->id, array( + 'optedOut' => false + )); + } + echo $this->getLanguage()->translate('subscribedAgain', 'messages', 'Campaign'); + echo '

'; + echo '' . $this->getLanguage()->translate('Unsubscribe again', 'labels', 'Campaign') . ''; + } + } + } + } + + } +} + diff --git a/application/Espo/Modules/Crm/EntryPoints/Unsubscribe.php b/application/Espo/Modules/Crm/EntryPoints/Unsubscribe.php index bd02448e53..0d85f6cddd 100644 --- a/application/Espo/Modules/Crm/EntryPoints/Unsubscribe.php +++ b/application/Espo/Modules/Crm/EntryPoints/Unsubscribe.php @@ -101,6 +101,8 @@ class Unsubscribe extends \Espo\Core\EntryPoints\Base )); } echo $this->getLanguage()->translate('unsubscribed', 'messages', 'Campaign'); + echo '

'; + echo '' . $this->getLanguage()->translate('Subscribe again', 'labels', 'Campaign') . ''; } } } @@ -110,7 +112,6 @@ class Unsubscribe extends \Espo\Core\EntryPoints\Base $campaignService = $this->getServiceFactory()->create('Campaign'); $campaignService->logOptedOut($campaignId, $queueItemId, $target, $queueItem->get('emailAddress'), null, $queueItem->get('isTest')); } - } } diff --git a/application/Espo/Modules/Crm/Resources/i18n/en_US/Campaign.json b/application/Espo/Modules/Crm/Resources/i18n/en_US/Campaign.json index 19214f0fae..c247b01494 100644 --- a/application/Espo/Modules/Crm/Resources/i18n/en_US/Campaign.json +++ b/application/Espo/Modules/Crm/Resources/i18n/en_US/Campaign.json @@ -56,13 +56,16 @@ "soft": "soft", "Unsubscribe": "Unsubscribe", "Mass Emails": "Mass Emails", - "Email Templates": "Email Templates" + "Email Templates": "Email Templates", + "Unsubscribe again": "Unsubscribe again", + "Subscribe again": "Subscribe again" }, "presetFilters": { "active": "Active" }, "messages": { - "unsubscribed": "You have been unsubscribed from our mailing list." + "unsubscribed": "You have been unsubscribed from our mailing list.", + "subscribedAgain": "You are subscribed again." }, "tooltips": { "targetLists": "Targets that should receive messages.",