Skip to content
Snippets Groups Projects
Commit 6609dd4d authored by Ghislain Loas's avatar Ghislain Loas
Browse files

Merge branch 'hotline_198577_newsletter_header_list-unsubscribe' into 'master'

[RTko] hotline 198577 add List-Unsubscribe to newsletter email header

See merge request !4967
parents 9692885d 5b2ea389
Branches
Tags
1 merge request!4967[RTko] hotline 198577 add List-Unsubscribe to newsletter email header
Pipeline #32057 passed with stage
in 20 minutes and 37 seconds
- correctif #198577 : Lettres d'informations : Amélioration de la diffusion des courriels de lettres d'information en rajoutant une entête List-Unsubscribe.
\ No newline at end of file
......@@ -100,6 +100,14 @@ class Class_Newsletter_Dispatch extends Storm_Model_Abstract {
}
public function getUnsubscribeUrl(): string
{
return ($newsletter = $this->getNewsletter())
? $newsletter->getUnsubscribeUrl()
: '';
}
public function sendBy($recipient_size) {
$this->collectRecipients();
......@@ -134,7 +142,7 @@ class Class_Newsletter_Dispatch extends Storm_Model_Abstract {
Class_Newsletter_DispatchUser::newInstance(['dispatch_id' => $this->getId(),
'user_id' => $model->getId(),
'mail' => $model->getMail()])
->save();
->save();
Class_Newsletter_DispatchUser::clearCache();
};
......
......@@ -37,7 +37,7 @@ class Newsletter_DispatchUserLoader extends Storm_Model_Loader {
class Class_Newsletter_DispatchUser extends Storm_Model_Abstract {
protected $_table_name = 'newsletter_dispatch_user';
protected $_table_name = 'newsletter_dispatch_user';
protected $_loader_class = 'Newsletter_DispatchUserLoader';
protected $_belongs_to = ['dispatch' => ['model' => 'Class_Newsletter_Dispatch'],
......
......@@ -20,25 +20,116 @@
*/
class Class_Newsletter_Template extends Class_Entity {
class Class_Newsletter_Template
{
protected string $_titre = '';
protected string $_expediteur = '';
protected string $_body_html = '';
protected string $_newsltetter_id = '';
protected string $_body_text = '';
protected string $_unsubscribe_url = '';
public function setTitre(string $titre): self
{
$this->_titre = $titre;
return $this;
}
public function setBodyText(string $text): self
{
$this->_body_text = $text;
return $this;
}
public function setBodyHtml(string $html): self
{
$this->_body_html = $html;
return $this;
}
public function setExpediteur(string $adress): self
{
$this->_expediteur = $adress;
return $this;
}
public function setNewsletterId(string $id): self
{
$this->_newsletter_id = $id;
return $this;
}
public function getTitre(): string
{
return $this->_titre;
}
public function getBodyText(): string
{
return $this->_body_text;
}
public function getNewsletterId(): string
{
return $this->_newsletter_id;
}
public function getBodyHTML(): string
{
return $this->_body_html;
}
public function getExpediteur(): string
{
return $this->_expediteur;
}
public function getUnsubscribeUrl(): string
{
return $this->_unsubscribe_url;
}
public function setUnsubscribeUrl(string $url): self
{
$this->_unsubscribe_url = $url;
return $this;
}
public static function newFrom(Class_Newsletter_Dispatch $dispatch) : self {
return (new static())
->setTitre($dispatch->getTitle())
->setBodyText($dispatch->getBodyText())
->setBodyHTML($dispatch->getBodyHtml())
->setExpediteur($dispatch->getSender())
->setNewsletterId($dispatch->getNewsletterId());
->setNewsletterId($dispatch->getNewsletterId())
->setUnsubscribeUrl($dispatch->getUnsubscribeUrl());
}
public function mailFor($dispatch_user) {
$mail = new ZendAfi_Mail();
$mail
$mail = (new ZendAfi_Mail)
->setSubject($this->getTitre())
->setBodyText($this->fillTemplate($dispatch_user, $this->getBodyText()))
->setBodyHTML($this->fillTemplate($dispatch_user, $this->getBodyHTML()))
->setFrom($this->getExpediteur());
if ( $unsubscribe_url = $this->getUnsubscribeUrl())
$mail->addHeader('List-Unsubscribe', $this->fillTemplate($dispatch_user, $unsubscribe_url));
return $mail;
}
......
......@@ -107,8 +107,8 @@ class Class_Newsletter_TemplateHelper {
return $this->_body_html_cache;
return $this->_body_html_cache = $this->_renderNewsletterWith('_getContentAsHTML',
'renderHtml',
'_getUnsubscribeHTML');
'renderHtml',
'_getUnsubscribeHTML');
}
......
......@@ -234,6 +234,15 @@ class NewsletterMailingAnimationsSendMailTest extends NewsletterMailingTestCase
}
/** @test */
public function mailHeaderListUnsubscribeShouldBePresent()
{
$this->assertContains('/newsletter/unsubscribe/newsletter/1/user/2/hash/'
. $this->_hashForUser(Class_Users::find(2)),
reset($this->mails[0]->getHeaders()['List-Unsubscribe']) ?? 'fail');
}
/** @test */
public function bodyTextShouldBeDecouverteCuisineDuMonde() {
$this->assertContains('Découverte des cuisines du monde',
......
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