diff --git a/VERSIONS_HOTLINE/109494 b/VERSIONS_HOTLINE/109494 new file mode 100644 index 0000000000000000000000000000000000000000..f82b7af96d372d7f9146c3b872b7c53c215cf9d5 --- /dev/null +++ b/VERSIONS_HOTLINE/109494 @@ -0,0 +1 @@ + - ticket #109494 : PNB Dilicom : Correction d'une erreur lors de l'export des prèts quand l'album dilicom a été supprimé \ No newline at end of file diff --git a/library/Class/Loan/Pnb.php b/library/Class/Loan/Pnb.php index ed31add32bd8cf4344791660dbf657d571b20b2d..cc0ad7ba59336882b9632c20ea0e71da53a5b014 100644 --- a/library/Class/Loan/Pnb.php +++ b/library/Class/Loan/Pnb.php @@ -152,7 +152,10 @@ class Class_Loan_Pnb extends Storm_Model_Abstract { public function getItem() { - foreach(Class_Album_Item::findAllBy(['album_id' => $this->getAlbum()->getId()]) + if (!$album = $this->getAlbum()) + return; + + foreach(Class_Album_Item::findAllBy(['album_id' => $album->getId()]) as $item) if ($item->getOrderLineId() == $this->getOrderLineId()) return $item; diff --git a/library/Trait/AlbumDelegator.php b/library/Trait/AlbumDelegator.php index 76f4a3d8f28259a0cd7fd0d2744272a76781be16..bccec7d059ad18f0067f1a110907f0a1d64dede2 100644 --- a/library/Trait/AlbumDelegator.php +++ b/library/Trait/AlbumDelegator.php @@ -25,7 +25,7 @@ */ trait Trait_AlbumDelegator { public function getNoticeOPACId() { - return $this->getAlbum()->getNoticeId(); + return $this->_withAlbumGet('notice_id'); } @@ -40,42 +40,44 @@ trait Trait_AlbumDelegator { public function getTitle() { - return $this->getAlbum()->getTitre(); + return $this->_withAlbumGet('titre', ''); } public function getMainAuthor() { - return $this->getAlbum()->getMainAuthorName(); + return $this->_withAlbumGet('main_author_name', ''); } public function getFirstEditor() { - return $this->getAlbum()->getFirstEditor(); + return $this->_withAlbumGet('first_editor', ''); } public function getFirstCollection() { - return $this->getAlbum()->getFirstCollection(); + return $this->_withAlbumGet('first_collection', ''); } public function getYear() { - return $this->getAlbum()->getAnnee(); + return $this->_withAlbumGet('annee', ''); } public function getFirstKind() { - return $this->getFirstLabelFromAlbumCodif('Class_CodifGenre', $this->getAlbum()->getGenre()); + return $this->getFirstLabelFromAlbumCodif('Class_CodifGenre', + $this->_withAlbumGet('genre', '')); } public function getFirstSection() { - return $this->getFirstLabelFromAlbumCodif('Class_CodifSection', $this->getAlbum()->getSections()); + return $this->getFirstLabelFromAlbumCodif('Class_CodifSection', + $this->_withAlbumGet('sections')); } public function getCategory() { - return $this->getAlbum()->getCategoryLabel(); + return $this->_withAlbumGet('category_label', ''); } @@ -85,4 +87,11 @@ trait Trait_AlbumDelegator { ? '' : $labels->first(); } + + + protected function _withAlbumGet($attribute, $default=null) { + return ($album = $this->getAlbum()) + ? $album->callGetterByAttributeName($attribute) + : $default; + } } diff --git a/tests/scenarios/PnbDilicom/PnbDilicomTest.php b/tests/scenarios/PnbDilicom/PnbDilicomTest.php index 11d9150e6ffdaed002add1f7cf94b96f77e613c7..a93bb251042e13dc04fa26620b9ffe1f5c201606 100644 --- a/tests/scenarios/PnbDilicom/PnbDilicomTest.php +++ b/tests/scenarios/PnbDilicom/PnbDilicomTest.php @@ -3862,7 +3862,7 @@ class PnbDilicomAdminAlbumControllerExportLoansCsvTest extends PnbDilicomAdminAl 'loan_link' => 'https://pnb-dilicom.centprod.com/v2//XXXXXXXX.do', 'order_line_id' => '82377a045ce56ef0a072a8b']); - $this->dispatch('admin/album/dilicom-export-loans-csv', true); + $this->dispatch('admin/album/dilicom-export-loans-csv'); } @@ -3898,6 +3898,29 @@ class PnbDilicomAdminAlbumControllerExportLoansCsvTest extends PnbDilicomAdminAl +class PnbDilicomAdminAlbumControllerExportLoansCsvWithMissingAlbumTest + extends PnbDilicomAdminAlbumControllerTestCase { + + public function setUp() { + parent::setUp(); + + Class_Album::find(23)->delete(); + $this->dispatch('admin/album/dilicom-export-loans-csv'); + } + + + /** @test */ + public function filenameShouldBeDilicomLoansCsv() { + $this->assertContains(['name' => 'Content-Type', + 'value' => 'text/csv; name="dilicom_loans_csv.csv"', + 'replace' => true], + $this->_response->getHeaders()); + } +} + + + + class PnbDilicomAdminIndexControllerTest extends AbstractControllerTestCase { protected $_storm_default_to_volatile = true;