diff --git a/VERSIONS_HOTLINE/98102 b/VERSIONS_HOTLINE/98102 new file mode 100644 index 0000000000000000000000000000000000000000..302dcb13e6d5553bd2d7e82fefe607171fcfa267 --- /dev/null +++ b/VERSIONS_HOTLINE/98102 @@ -0,0 +1 @@ + - ticket #98102 : Notices d'album : le bouton "générer" pour la vignette force le retéléchargement de cette vignette pour les ressources numériques externes \ No newline at end of file diff --git a/application/modules/admin/controllers/RecordsController.php b/application/modules/admin/controllers/RecordsController.php index 46d37d8622075d17c5c76ec7e6b6a77c6d9fb8bc..4b3decc3a51aab0646f19327bc7e612a8b2f5101 100644 --- a/application/modules/admin/controllers/RecordsController.php +++ b/application/modules/admin/controllers/RecordsController.php @@ -27,25 +27,34 @@ class Admin_RecordsController extends ZendAfi_Controller_Action { return $this->_redirectToReferer(); } - if ($album = $record->getAlbum()){ - $album->createThumbnail(); - $url_vignette = $album->getThumbnailUrl(); + $this->_resetRecordThumbnail($record); - $record->setUrlVignette($url_vignette); - $record->setUrlImage(($poster = $album->getPoster()) ? $poster : $url_vignette); - $record->save(); + $this->_helper->notify($this->_('Vignette réinitialisée pour "%s"', $record->getTitrePrincipal())); + $this->_redirectToReferer(); + } - $this->_helper->notify($this->_('Vignette réinitialisée pour "%s"', $record->getTitrePrincipal())); - return $this->_redirectToReferer(); + + protected function _resetRecordThumbnail($record) { + if (!$album = $record->getAlbum()) { + $record + ->setUrlImage('') + ->setUrlVignette('') + ->fetchUrlLocalVignette(); + + return $this; } - $record - ->setUrlImage('') - ->setUrlVignette('') - ->fetchUrlLocalVignette(); + Class_WebService_BibNumerique_Vignette::getInstance()->updateAlbum($album); + foreach($album->getErrors() as $error) + $this->_helper->notify($error); - $this->_helper->notify($this->_('Vignette réinitialisée pour "%s"', $record->getTitrePrincipal())); - $this->_redirectToReferer(); + $album->createThumbnail(); + $url_vignette = $album->getThumbnailUrl(); + + $record->setUrlVignette($url_vignette); + $record->setUrlImage(($poster = $album->getPoster()) ? $poster : $url_vignette); + $record->save(); + return $this; } diff --git a/tests/application/modules/admin/controllers/RecordsControllerTest.php b/tests/application/modules/admin/controllers/RecordsControllerTest.php index c7620d438ef0a16b2dc110b694599422d0cfe7b6..0f6dec9d55acbddb7cd838cf60902c46b5cf312a 100644 --- a/tests/application/modules/admin/controllers/RecordsControllerTest.php +++ b/tests/application/modules/admin/controllers/RecordsControllerTest.php @@ -107,6 +107,7 @@ class RecordsControllerResetThumbnailTest extends RecordsControllerTestCase { + class RecordsControllerResetAlbumThumbnailTest extends RecordsControllerTestCase { public function setUp() { parent::setUp(); @@ -126,6 +127,14 @@ class RecordsControllerResetAlbumThumbnailTest extends RecordsControllerTestCase $album->index(); $id = $album->getNoticeId(); + Class_WebService_BibNumerique_Vignette::setInstance( + $this->mock() + ->whenCalled('updateAlbum') + ->willDo(function($album) + { + $album->addError('Error downloading thumbnail'); + })); + $this->dispatch('/admin/records/reset-thumbnail/id/' . $id, true); Class_Notice::clearCache(); @@ -133,6 +142,20 @@ class RecordsControllerResetAlbumThumbnailTest extends RecordsControllerTestCase } + /** @test */ + public function albumVignetteShouldHaveBeenUpdated() { + $this->assertTrue(Class_WebService_BibNumerique_Vignette::getInstance() + ->methodHasBeenCalledWithParams('updateAlbum', + [Class_Album::find(5)])); + } + + + /** @test */ + public function responseShouldNotifyErrorDownloadingThumbnail() { + $this->assertFlashMessengerContentContains('Error downloading thumbnail'); + } + + /** @test */ public function urlImageShouldPotter() { $this->assertContains('/userfiles/album/5/thumb_potter.png', $this->_notice->getUrlImage()); @@ -159,6 +182,7 @@ class RecordsControllerResetAlbumThumbnailTest extends RecordsControllerTestCase + class RecordsControllerResetThumbnailUnknowRecordTest extends RecordsControllerTestCase { public function setUp() { parent::setUp(); @@ -180,6 +204,7 @@ class RecordsControllerResetThumbnailUnknowRecordTest extends RecordsControllerT + class RecordsControllerThumbnailTest extends RecordsControllerTestCase { public function setUp() { parent::setUp();