diff --git a/VERSIONS_HOTLINE/59638 b/VERSIONS_HOTLINE/59638 new file mode 100644 index 0000000000000000000000000000000000000000..1f5aced4c8a311ee66a477d1c7e16c9d750af58e --- /dev/null +++ b/VERSIONS_HOTLINE/59638 @@ -0,0 +1 @@ + - 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/cosmogramme/sql/patch/patch_322.php b/cosmogramme/sql/patch/patch_322.php new file mode 100644 index 0000000000000000000000000000000000000000..64e2bd9cff1cc6c568a1d9d193a33e717047490a --- /dev/null +++ b/cosmogramme/sql/patch/patch_322.php @@ -0,0 +1,6 @@ +<?php +try { + Zend_Db_Table_Abstract::getDefaultAdapter() + ->query('delete from newsletter_dispatch where COLLECTED=0 and ended_on is NULL and error is NULL and DATE(created_on)!=CURDATE()'); +} catch(Exception $e) {} +?> \ 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 e755bb98021f3bd4e283f1d3f2338d80ac9a0d62..c308700ca48423ff3467fe4b2597edce7dd3324a 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')) + ], ['url' => '/admin/newsletter/duplicate/id/%s', 'icon' => 'copy', 'label' => $this->_('Dupliquer la lettre d\'information')], @@ -72,7 +79,7 @@ function sendNewsletterClick(event) { $this->_addModelToView($newsletter); - $template = Class_Newsletter_Dispatch::newFrom($newsletter)->getTemplate(); + $template = Class_Newsletter_Dispatch::newVolatileFrom($newsletter)->getTemplate(); $mock_user = new Class_Entity(); $mock_user->setId(0)->setMail(''); diff --git a/tests/application/modules/admin/controllers/NewsletterControllerTest.php b/tests/application/modules/admin/controllers/NewsletterControllerTest.php index c194a39a9e1dc6ac7490ed284ecccff7d61fa89e..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()); } } @@ -868,6 +870,7 @@ class Admin_NewsletterControllerPreviewActionTest extends Admin_NewsletterContro $this->assertXPath('//div//img[@src="zork.jpg"]', $this->_response->getBody()); } + /** @test */ public function noticeShouldBePresent() { $this->assertQueryContentContains('p', 'Martine à la plage', $this->_response->getBody()); @@ -877,6 +880,12 @@ class Admin_NewsletterControllerPreviewActionTest extends Admin_NewsletterContro public function noticeMartineALaPlageUrlShouldBeRechercheViewNotice42() { $this->assertXPath('//a[@href="http://localhost' . BASE_URL . '/recherche/viewnotice/id/42"]'); } + + /** @test */ + public function templateShouldNotCreateNewsletterDispatch() { + $this->assertEmpty(Class_Newsletter_Dispatch::findAll()); + } + } @@ -1463,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"]'); @@ -1508,6 +1523,8 @@ class Admin_NewsletterControllerSendProgressWithWrongNewsletterIdTest extends Ad + + class Admin_NewsletterControllerSendProgressWithErrorAndNothingSentTest extends Admin_NewsletterControllerSendProgressTestCase { @@ -1531,6 +1548,8 @@ class Admin_NewsletterControllerSendProgressWithErrorAndNothingSentTest public function statusShouldContainsNothingSent() { $this->assertContains('aucun mail envoyé', $this->_json->status); } + + } @@ -1565,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()); + } + + } diff --git a/tests/db/UpgradeDBTest.php b/tests/db/UpgradeDBTest.php index 0c8a137fbc369313decb18004cc06d828c7fc6b5..814ff5c886ea04bb44649748f8e462cc3422e3cc 100644 --- a/tests/db/UpgradeDBTest.php +++ b/tests/db/UpgradeDBTest.php @@ -1336,3 +1336,26 @@ class UpgradeDB_321_Test extends UpgradeDBTestCase { $this->assertFieldType('newsletters', 'titre', 'varchar(255)'); } } + +class UpgradeDB_322_Test extends UpgradeDBTestCase { + public function prepare() { + try { + $this->query("insert into newsletter_dispatch (newsletter_id, title, created_on, ended_on, error, collected) values ('1','Title for test', NOW(),NULL,NULL,0), +('1','Title 2 for test', '2017-05-08 14:00:00',NULL,NULL,0)"); + } catch(Exception $e) {} + } + + + /** @test */ + public function newslettersDispatchWithSameDateShouldNotBeDeleted() { + $data = $this->query('select * from newsletter_dispatch where title="Title for test" ;')->fetch(); + $this->assertNotNull($data); + } + + /** @test */ + public function newslettersDispatchShouldBeDeleted() { + $data = $this->query('select * from newsletter_dispatch where title="Title 2 for test" ;')->fetch(); + $this->assertNull($data); + } + +}