diff --git a/cosmogramme/VERSIONS_WIP/92566 b/cosmogramme/VERSIONS_WIP/92566 new file mode 100644 index 0000000000000000000000000000000000000000..a9cac28650b65b714477dd15585f4dd6a1a83574 --- /dev/null +++ b/cosmogramme/VERSIONS_WIP/92566 @@ -0,0 +1 @@ + - ticket #92566 : Cosmogramme : dédoublonnage des périodiques par ISSN \ No newline at end of file diff --git a/cosmogramme/php/classes/classe_notice_integration.php b/cosmogramme/php/classes/classe_notice_integration.php index 90e25cc429caae4f5fcbfe3a5e49a67efc35ce7d..008a83dabf840171ac477d1306fda1013ddd58f5 100644 --- a/cosmogramme/php/classes/classe_notice_integration.php +++ b/cosmogramme/php/classes/classe_notice_integration.php @@ -566,6 +566,7 @@ class notice_integration { 'facettes' => $this->notice['facettes'], 'isbn' => $this->notice['isbn'], 'ean' => $this->notice['ean'], + 'issn' => $this->notice['issn'], 'id_commerciale' => $this->notice['id_commerciale'], 'clef_alpha' => $this->notice['clef_alpha'], 'clef_chapeau' => $this->notice['clef_chapeau'], diff --git a/cosmogramme/php/classes/classe_unimarc.php b/cosmogramme/php/classes/classe_unimarc.php index 45c8a9cc9db750d994fbe95d5e2d890b119e43cd..4d8e025357ccbb9e331490af43179d8d709a2bfd 100644 --- a/cosmogramme/php/classes/classe_unimarc.php +++ b/cosmogramme/php/classes/classe_unimarc.php @@ -149,6 +149,8 @@ class notice_unimarc extends iso2709_record { $trav['isbn10'] = $trav['isbn13'] = $trav['isbn'] = ''; } + $trav['issn'] = $this->getIssn(); + return $trav; } @@ -176,6 +178,7 @@ class notice_unimarc extends iso2709_record { $notice["isbn10"] = $record_identifiers['isbn10']; $notice["isbn13"] = $record_identifiers['isbn13']; $notice["ean"] = $record_identifiers['ean']; + $notice["issn"] = $record_identifiers['issn']; $notice["id_origine"] = $this->getIdOrigine(); $notice["tome_alpha"] = $this->indexation->alphaMaj($this->getTome()); $notice["clef_alpha"] = $this->indexation->getClefAlpha( @@ -1008,8 +1011,9 @@ class notice_unimarc extends iso2709_record { public function getIssn() { - $issn = $this->get_subfield("011", "a"); - return trim($issn[0]); + return ($issn = $this->get_subfield("011", "a")) + ? trim($issn[0]) + : ''; } diff --git a/cosmogramme/sql/patch/patch_392.php b/cosmogramme/sql/patch/patch_392.php new file mode 100644 index 0000000000000000000000000000000000000000..4cd653ed753762d2e41e6e47ff25df22e0c01743 --- /dev/null +++ b/cosmogramme/sql/patch/patch_392.php @@ -0,0 +1,11 @@ +<?php + +$adapter = Zend_Db_Table_Abstract::getDefaultAdapter(); + +try { + $adapter->query( + 'ALTER TABLE `notices` ' + . 'ADD COLUMN `issn` varchar(255) default "",' + . 'ADD KEY `issn` (`issn`)' + ); +} catch(Exception $e) {} diff --git a/cosmogramme/tests/php/classes/KohaPeriodiquesTest.php b/cosmogramme/tests/php/classes/KohaPeriodiquesTest.php index 0286ff14bcf5e7ce0c3019d8fd7a134712e31827..aa9e530cf645174aef5287228255c20b5f92f3de 100644 --- a/cosmogramme/tests/php/classes/KohaPeriodiquesTest.php +++ b/cosmogramme/tests/php/classes/KohaPeriodiquesTest.php @@ -423,6 +423,13 @@ class KohaPeriodiquesLaPagailleAndOkapiTest extends KohaPeriodiquesTestCase { } + /** @test */ + public function perTitleRecordShouldHaveISSN0751_6002() { + $this->assertEquals('0751-6002', + Class_Notice::findFirstBy(['type_doc' => 'per_title'])->getIssn()); + } + + /** @test */ public function perTitleRecordItemTypeShouldBeBibliographic() { $this->assertEquals(Class_Notice::TYPE_BIBLIOGRAPHIC, diff --git a/library/Class/Notice/DoubleFinder.php b/library/Class/Notice/DoubleFinder.php index b45706cc6bc842bb9fa4daeec1595a03afabf97d..352bdb17b7bc643db0b9549b5994c908e3e1d300 100644 --- a/library/Class/Notice/DoubleFinder.php +++ b/library/Class/Notice/DoubleFinder.php @@ -107,6 +107,7 @@ class Class_Notice_DoubleFinder { abstract class Class_Notice_DoubleFinder_Strategy { const FOUND_ON_BARCODE = 'code_barres', + FOUND_ON_ISSN = 'issn', FOUND_ON_ID_ORIGINE = 'id_origine'; protected @@ -361,6 +362,15 @@ class Class_Notice_DoubleFinder_PeriodicTitle extends Class_Notice_DoubleFinder_ public function find($data) { $this->_data = $data; + if (trim($data->getissn()) && + ($record = Class_Notice::findFirstBy(['type' => Class_Notice::TYPE_BIBLIOGRAPHIC, + 'type_doc' => Class_TypeDoc::PERIODIQUE_TITLE, + 'issn' => trim($data->getissn())]))) { + $this->_id = $record->getId(); + $this->_found_on = static::FOUND_ON_ISSN; + return true; + } + if (!$this->_id = $this->_getRecordIdByItem(['id_origine' => $data->getid_origine()])) return false; diff --git a/tests/db/UpgradeDBTest.php b/tests/db/UpgradeDBTest.php index 35e09dca96e359c9433c3df87df6a8ae497106d0..d848b6dbd16164dedf9c7f59d4b58a2a6e4b5f21 100644 --- a/tests/db/UpgradeDBTest.php +++ b/tests/db/UpgradeDBTest.php @@ -3360,3 +3360,18 @@ class UpgradeDB_391_Test extends UpgradeDBTestCase { $this->assertIndex('bib_admin_users', 'disable_newsletter'); } } + + + + +class UpgradeDB_392_Test extends UpgradeDBTestCase { + public function prepare() { + $this->silentQuery('ALTER TABLE notices drop column issn;'); + } + + /** @test */ + public function noticesTableShouldHaveColumnIssnIndex() { + $this->assertFieldType('notices', 'issn', 'varchar(255)'); + $this->assertIndex('notices', 'issn'); + } +} diff --git a/tests/library/Class/Notice/DoubleFinderTest.php b/tests/library/Class/Notice/DoubleFinderTest.php index 5d727556eb5e3dc6a14d469410e497d5dc9090c4..67fb07fdcd2fbaf6e54e43d505c05c396f904a72 100644 --- a/tests/library/Class/Notice/DoubleFinderTest.php +++ b/tests/library/Class/Notice/DoubleFinderTest.php @@ -42,6 +42,7 @@ abstract class DoubleFinderTestCase extends ModelTestCase { ['id' => 1, 'type_doc' => Class_TypeDoc::LIVRE, 'isbn' => '2-85868-161-9', + 'issn' => '', 'clef_alpha' => 'JESUISNEBONHOMME--SARA--EDTHIERRYMAGNIER-2010-1', 'exemplaires' => [ $this->fixture('Class_Exemplaire', ['id' => 1, @@ -53,6 +54,7 @@ abstract class DoubleFinderTestCase extends ModelTestCase { ['id' => 2, 'type_doc' => Class_TypeDoc::DILICOM, 'isbn' => '2-85868-161-9', + 'issn' => '', 'clef_alpha' => 'JESUISNEBONHOMME--SARA--EDTHIERRYMAGNIER-2010-1', 'exemplaires' => [ $this->fixture('Class_Exemplaire', ['id' => 2, @@ -64,12 +66,39 @@ abstract class DoubleFinderTestCase extends ModelTestCase { ['id' => 3, 'type_doc' => Class_TypeDoc::RSS, 'isbn' => '2-85868-161-9', + 'issn' => '', 'clef_alpha' => 'JESUISNEBONHOMME--SARA--EDTHIERRYMAGNIER-2010-1', 'exemplaires' => [ $this->fixture('Class_Exemplaire', ['id' => 3, 'code_barres' => '159', 'id_origine' => '789', 'id_int_bib' => 1])]]); + + + $this->fixture('Class_Notice', + ['id' => 4, + 'type_doc' => Class_TypeDoc::PERIODIQUE_TITLE, + 'isbn' => '', + 'issn' => '0751-6002', + 'clef_alpha' => 'OKAPI--FRAPPATB-963-BAYARDPRESSE-2009-2', + 'exemplaires' => [ $this->fixture('Class_Exemplaire', + ['id' => 4, + 'code_barres' => '93484673', + 'id_origine' => '823', + 'id_int_bib' => 1])]]); + + + $this->fixture('Class_Notice', + ['id' => 5, + 'type_doc' => Class_TypeDoc::PERIODIQUE_TITLE, + 'isbn' => '', + 'issn' => '', + 'clef_alpha' => 'TAGADA', + 'exemplaires' => [ $this->fixture('Class_Exemplaire', + ['id' => 5, + 'code_barres' => '67304', + 'id_origine' => '824', + 'id_int_bib' => 1])]]); } @@ -183,6 +212,57 @@ class DoubleFinderWithExistingIsbnTest extends DoubleFinderWithRecordMatchingTes + +class DoubleFinderWithExistingISSNTest extends DoubleFinderTestCase { + protected $_data = ['type_doc' => Class_TypeDoc::PERIODIQUE_TITLE, + 'issn' => '0751-6002']; + + /** @test */ + public function shouldHaveMatchedISSN() { + $this->assertEquals('issn', $this->_finder->getMatchedCriteria()); + } + + /** @test */ + public function shouldFindRecord() { + $this->assertFound(); + } + + + /** @test */ + public function recordIdShouldBeFour() { + $this->assertEquals(4, $this->_finder->getId()); + } +} + + + + +class DoubleFinderWithNoISSNTest extends DoubleFinderTestCase { + protected $_data = ['type_doc' => Class_TypeDoc::PERIODIQUE_TITLE, + 'issn' => '']; + + /** @test */ + public function shouldNotFindRecord() { + $this->assertNotFound(); + } +} + + + + +class DoubleFinderWithoutExistingISSNTest extends DoubleFinderTestCase { + protected $_data = ['type_doc' => Class_TypeDoc::PERIODIQUE_TITLE, + 'issn' => '6666-6666']; + + /** @test */ + public function shouldNotFindRecord() { + $this->assertNotFound(); + } +} + + + + class DoubleFinderWithExistingAlphaKeyTest extends DoubleFinderWithRecordMatchingTestCase { protected $_data = ['type_doc' => Class_TypeDoc::LIVRE, 'clef_alpha' => 'JESUISNEBONHOMME--SARA--EDTHIERRYMAGNIER-2010-1'];