diff --git a/VERSIONS_HOTLINE/#16538_biblio_records_url_in_newsletters b/VERSIONS_HOTLINE/#16538_biblio_records_url_in_newsletters new file mode 100644 index 0000000000000000000000000000000000000000..82def46315914dc7bfa6e6c04550408b88913ab7 --- /dev/null +++ b/VERSIONS_HOTLINE/#16538_biblio_records_url_in_newsletters @@ -0,0 +1 @@ +- ticket #16538: correction des urls des notices dans une newsletter \ No newline at end of file diff --git a/library/Class/Batch/SendNewsletters.php b/library/Class/Batch/SendNewsletters.php index 9333dbdf885d77334d0456e1f6893cf701a761ae..00b2a2446a7dce636fb30ed215c3a293721f6a89 100644 --- a/library/Class/Batch/SendNewsletters.php +++ b/library/Class/Batch/SendNewsletters.php @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with AFI-OPAC 2.0; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Class_Batch_SendNewsletters extends Class_Batch_Abstract { protected $_newsletter; - + public function __construct($newsletter) { $this->_newsletter = $newsletter; @@ -36,9 +36,23 @@ class Class_Batch_SendNewsletters extends Class_Batch_Abstract { } + public function getExecParamsAsArray() { + return [$_SERVER['HTTP_HOST'], + $_SERVER['SERVER_NAME'], + BASE_URL, + $this->_newsletter->getId()]; + } + + + public function getExecParams() { + return '"' . implode('" "', $this->getExecParamsAsArray()) . '"'; + } + + public function run() { exec("/usr/bin/php -f ".realpath(dirname(__FILE__))."/../../../scripts/sendNewsletter.php " - .$this->_newsletter->getId().' "'.$_SERVER['HTTP_HOST'].'"'." > /dev/null &"); + .$this->getExecParams() + ." > /dev/null &"); return $this; } } diff --git a/scripts/sendNewsletter.php b/scripts/sendNewsletter.php index 55c3d2f2f8e8f8fc1bd9730ba1d452cede1a9d92..4d7a0404be4ede061cc7d08ddb161550d53a8929 100644 --- a/scripts/sendNewsletter.php +++ b/scripts/sendNewsletter.php @@ -16,13 +16,13 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with AFI-OPAC 2.0; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -define("BASE_URL", "/"); +define("BASE_URL", $argv[3]); +$_SERVER['SERVER_NAME'] = $argv[2]; +$_SERVER['HTTP_HOST'] = $argv[1]; - - -set_include_path('.' +set_include_path('.' . PATH_SEPARATOR .realpath(dirname(__FILE__)). '/../library' . PATH_SEPARATOR .realpath(dirname(__FILE__)). '/../library/storm/zf/library' . PATH_SEPARATOR .realpath(dirname(__FILE__)). '/../library/storm/src' @@ -31,14 +31,13 @@ set_include_path('.' . PATH_SEPARATOR . realpath(dirname(__FILE__)).'/../application/modules' . PATH_SEPARATOR . realpath(dirname(__FILE__)).'/application/modules' ); -$newsletter_id=$argv[1]; -$_SERVER['HTTP_HOST']=$argv[2]; + include_once "local.php"; include_once "fonctions/fonctions.php"; require_once "Zend/Loader.php"; require_once "startup.php"; setupOpac(); -$news=(Class_Newsletter::find($newsletter_id)); -$news->generateMails(20); + +Class_Newsletter::find($argv[4])->generateMails(20); ?> \ No newline at end of file diff --git a/tests/library/Class/NewsletterMailingTest.php b/tests/library/Class/NewsletterMailingTest.php index 0d7eb8ad760f5c0b75f94208fa9da3d494ec5109..0d35b3b0c4420c213090cb9ec646dc740aaabf45 100644 --- a/tests/library/Class/NewsletterMailingTest.php +++ b/tests/library/Class/NewsletterMailingTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with AFI-OPAC 2.0; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'ModelTestCase.php'; @@ -24,7 +24,7 @@ require_once 'ModelTestCase.php'; abstract class NewsletterMailingTestCase extends ModelTestCase { public function setup() { parent::setup(); - + Class_PanierNotice::beVolatile(); Class_Catalogue::beVolatile(); @@ -48,7 +48,7 @@ abstract class NewsletterMailingTestCase extends ModelTestCase { 'auteur_principal' => 'Stieg Larsson', 'annee' => 2005, 'url_vignette' => 'http://afi-sa.fr/millenium.png']); - + $this->potter = $this->fixture('Class_Notice', ['id' => 987, 'titre_principal' => "Harry Potter à l'école des sorciers", @@ -62,11 +62,11 @@ abstract class NewsletterMailingTestCase extends ModelTestCase { $this->rdubois = $this->fixture('Class_Users', ['id' => 1, 'login' => 'rdub', - 'password' => 'pwd', + 'password' => 'pwd', 'prenom' => 'Rémy', 'nom' => 'Dubois', 'mail' => 'rdubois@afi-sa.fr']); - + $this->mduchamp = $this->fixture('Class_Users', ['id' => 2, 'login' => 'duchamp', @@ -116,7 +116,7 @@ abstract class NewsletterMailingTestCase extends ModelTestCase { Storm_Test_ObjectWrapper::onLoaderOfModel('Class_NewsletterSubscription') ->whenCalled('clearCache') - ->answers(true) + ->answers(true) ->whenCalled('countDistributionProgress') ->with(1) @@ -136,7 +136,7 @@ abstract class NewsletterMailingTestCase extends ModelTestCase { ->whenCalled('resetSendFlagForNewsletter') ->with(1) ->answers(true) - + ->beStrict(); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Notice') @@ -145,13 +145,13 @@ abstract class NewsletterMailingTestCase extends ModelTestCase { $this->mock_transport = new MockMailTransport(); Zend_Mail::setDefaultTransport($this->mock_transport); - + $this->animations->generateMails(20); $this->mail = $this->mock_transport->sent_mail; } - + protected function getReceivers() { if ($this->user_model->methodCallCount('getNewslettersReceivers')>1) return []; @@ -170,8 +170,15 @@ class NewsletterMailingAnimationsTestSendMail extends NewsletterMailingTestCase parent::setup(); $this->animations->generateMails(20); $this->mail = $this->mock_transport->sent_mail; + $this->batch_send = new Class_Batch_SendNewsletters($this->animations); + } + + + /** @test */ + public function batchSendParamsShouldBeAsExpected() { + $this->assertEquals('"'.$_SERVER['HTTP_HOST'].'" "'.$_SERVER['SERVER_NAME'].'" "'.BASE_URL.'" "1"', $this->batch_send->getExecParams()); } - + /** @test */ public function floShouldBeExpeditor() {