diff --git a/VERSIONS_HOTLINE/59638 b/VERSIONS_HOTLINE/59638 index 21953bd86b688bfd0ed626cdb63e84d772ce2cbb..1f5aced4c8a311ee66a477d1c7e16c9d750af58e 100644 --- a/VERSIONS_HOTLINE/59638 +++ b/VERSIONS_HOTLINE/59638 @@ -1 +1 @@ - - ticket #59638 : Newsletter envoi version antérieure \ No newline at end of file + - ticket #59638 : Bug newsletter sur l'envoi de version antérieure , modification du message de confirmation avant l'envoi \ No newline at end of file diff --git a/library/Class/Newsletter.php b/library/Class/Newsletter.php index c030c17eac4689748eedb57bb813aa73e5eaf63a..10b5974eebbcd72383e2357f02db585d519d0f56 100644 --- a/library/Class/Newsletter.php +++ b/library/Class/Newsletter.php @@ -103,11 +103,18 @@ class Class_Newsletter extends Storm_Model_Abstract { ->run(); } + public function getDispatchIfNotEnded() { + return (($dispatch = $this->getLastDispatch()) && + $dispatch->isRunnable()) + ? $dispatch : false; + + } + protected function _getOrCreateDispatchToRun() { - return ($dispatch = $this->getLastDispatch()) && $dispatch->isRunnable() - ? $dispatch->resetError() - : Class_Newsletter_Dispatch::newFrom($this); + if ($dispatch = $this->getDispatchIfNotEnded()) + return $dispatch->resetError(); + return Class_Newsletter_Dispatch::newFrom($this); } diff --git a/library/ZendAfi/Controller/Plugin/Manager/Newsletter.php b/library/ZendAfi/Controller/Plugin/Manager/Newsletter.php index 628c2b034a722dc46235992e559d84e635903065..9a341ea9ce06480b3037d23ee1073d40ac03d53f 100644 --- a/library/ZendAfi/Controller/Plugin/Manager/Newsletter.php +++ b/library/ZendAfi/Controller/Plugin/Manager/Newsletter.php @@ -22,6 +22,8 @@ class ZendAfi_Controller_Plugin_Manager_Newsletter extends ZendAfi_Controller_Plugin_Manager_Manager { public function getActions($model) { + $existing_dispatch = $model->getDispatchIfNotEnded(); + return [ ['url' => '/admin/newsletter/edit/id/%s', 'icon' => 'edit', @@ -39,12 +41,14 @@ class ZendAfi_Controller_Plugin_Manager_Newsletter extends ZendAfi_Controller_Pl ['url' => '/admin/newsletter/send/id/%s', 'icon' => 'mail', 'anchorOptions' => ['rel' => 'send'], - 'caption' => function($model) + 'caption' => function($model) use ($existing_dispatch) { Class_ScriptLoader::getInstance()->addJQueryReady(" function sendNewsletterClick(event) { var target = $(event.target).closest('a'); - var answer = confirm(\"".$this->_("Envoyer la lettre d'information ?")."\"); + var answer = confirm(\"". ($existing_dispatch ? + $this->_("Reprendre l'envoi de la lettre d'information: %s ? ",$existing_dispatch->getTitle()) + : $this->_("Envoyer la lettre d'information ?"))."\"); if (answer == false) { event.preventDefault(); return; @@ -53,7 +57,10 @@ function sendNewsletterClick(event) { $(\"a[rel='send']\").click(sendNewsletterClick); ");}, - 'label' => 'Envoyer la lettre d\'information'], + 'label' => ($existing_dispatch ? + $this->_('Reprendre l\'envoi en cours') + : $this->_('Envoyez la lettre d\'information');$label_send_newsletter) + ], ['url' => '/admin/newsletter/duplicate/id/%s', 'icon' => 'copy', 'label' => $this->_('Dupliquer la lettre d\'information')], diff --git a/tests/application/modules/admin/controllers/NewsletterControllerTest.php b/tests/application/modules/admin/controllers/NewsletterControllerTest.php index cc0b03dd785faa875ab4dc0f9c9138e73d20c647..3a8d1cb0df37fbda83ff2472747c55fb4a7892a5 100644 --- a/tests/application/modules/admin/controllers/NewsletterControllerTest.php +++ b/tests/application/modules/admin/controllers/NewsletterControllerTest.php @@ -503,11 +503,6 @@ class Admin_NewsletterControllerSendInProgressActionTest extends Admin_Newslette Class_Batch_SendNewsletters::setCommand($this->_command); Class_Newsletter_Dispatch::setTimeSource(new TimeSourceForTest('2016-07-21 11:21:38')); - $dispatch = Class_Newsletter_Dispatch::newFrom(Class_Newsletter::find(2)); - $dispatch->assertSave(); - - $this->dispatch('/admin/newsletter/send/id/2', true); - $this->_dispatch = Class_Newsletter::find(2)->getDispatchs()[0]; } @@ -519,6 +514,13 @@ class Admin_NewsletterControllerSendInProgressActionTest extends Admin_Newslette /** @test */ public function shouldHaveOnlyOneDispatch() { + $dispatch = Class_Newsletter_Dispatch::newFrom(Class_Newsletter::find(2)); + $dispatch->setCollected(1); + $dispatch->assertSave(); + + $this->dispatch('/admin/newsletter/send/id/2', true); + $this->_dispatch = Class_Newsletter::find(2)->getDispatchs()[0]; + $this->assertEquals(1, Class_Newsletter::find(2)->numberOfDispatchs()); } } @@ -1470,6 +1472,12 @@ class Admin_NewsletterControllerScriptTest extends Admin_NewsletterControllerTes } + /** @test */ + public function sendMailButtonShouldBeHere() { + $this->assertXPathContentContains('//script', 'Envoyer la lettre d\'information'); + } + + /** @test */ public function progressBarNewsletterShouldBeDisplay() { $this->assertXPath('//div[@id="progress_bar_newsletter_1"]'); @@ -1515,6 +1523,8 @@ class Admin_NewsletterControllerSendProgressWithWrongNewsletterIdTest extends Ad + + class Admin_NewsletterControllerSendProgressWithErrorAndNothingSentTest extends Admin_NewsletterControllerSendProgressTestCase { @@ -1538,6 +1548,8 @@ class Admin_NewsletterControllerSendProgressWithErrorAndNothingSentTest public function statusShouldContainsNothingSent() { $this->assertContains('aucun mail envoyé', $this->_json->status); } + + } @@ -1572,6 +1584,16 @@ class Admin_NewsletterControllerSendProgressWithErrorAnd1Of2SentTest public function statusShouldContains1Of2Sent() { $this->assertContains('envoyé à 1 sur 2', $this->_json->status); } + + /** @test */ + public function sendButtonShouldContainsReloadText() { + Class_Newsletter::find(1)->setTitre('Other title')->save(); + $this->dispatch('admin/newsletter/index', true); + $this->assertXPathContentContains('//script', 'Reprendre l\'envoi de la lettre d\'information: Nouveautés classique ?', $this->_response->getBody()); + $this->assertXPath('//img[contains(@title,"Reprendre l\'envoi en cours")]', $this->_response->getBody()); + } + + }