From 14760044abc20183f2cf68e622d50200b54ceb2f Mon Sep 17 00:00:00 2001
From: Patrick Barroca <pbarroca@afi-sa.fr>
Date: Tue, 1 Oct 2019 13:54:18 +0200
Subject: [PATCH] hotline #96923 : hotfix modifying id_origine breaks
 webservices

---
 VERSIONS_HOTLINE/96923                        |  1 +
 .../php/classes/classe_notice_integration.php |  9 ++------
 .../tests/php/classes/KohaPeriodiquesTest.php |  4 +++-
 .../classes/NoticeIntegrationOrpheeTest.php   | 22 +++++++++++++++----
 library/Class/IntProfilDonnees.php            | 11 +++++++++-
 library/Class/Notice/DoubleFinder.php         |  6 +++++
 6 files changed, 40 insertions(+), 13 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/96923

diff --git a/VERSIONS_HOTLINE/96923 b/VERSIONS_HOTLINE/96923
new file mode 100644
index 00000000000..feddda53d53
--- /dev/null
+++ b/VERSIONS_HOTLINE/96923
@@ -0,0 +1 @@
+ - ticket #96923 : Intégration : SIGB Orphée et Koha : Correction de la prise en charge de l'import des périodiques
\ 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 4f70654a321..65179596755 100644
--- a/cosmogramme/php/classes/classe_notice_integration.php
+++ b/cosmogramme/php/classes/classe_notice_integration.php
@@ -424,17 +424,15 @@ class notice_integration {
     $champ_numero = $number_map[$this->id_article_periodique];
     $unimarc = $this->notice['unimarc'];
     $items = $this->notice['exemplaires'];
-    $id_origine = $this->notice['id_origine'];
 
     foreach($items as $item)
       $this->_traitePeriodiquesKohaItem($unimarc,
                                         unserialize($item['zone995']),
-                                        $champ_numero,
-                                        $id_origine);
+                                        $champ_numero);
   }
 
 
-  protected function _traitePeriodiquesKohaItem($unimarc, $champs, $champ_numero, $id_origine) {
+  protected function _traitePeriodiquesKohaItem($unimarc, $champs, $champ_numero) {
     $this->notice_sgbd->ouvrirNotice($unimarc,
                                      $this->id_profil,
                                      $this->sigb,
@@ -452,9 +450,6 @@ class notice_integration {
 
     $numero = $this->_periodiqueKohaNumeroFrom($numero_value, $complement_titre);
 
-    $this->notice_sgbd->delete_field('001');
-    $this->notice_sgbd->add_zone('001', $id_origine . '-' . $numero);
-
     $this->notice_sgbd->add_field('461', '11', 't' . $this->notice['titre_princ']);
     $this->notice_sgbd->add_field('461', '11', 'v' . $numero);
     if ($complement_titre)
diff --git a/cosmogramme/tests/php/classes/KohaPeriodiquesTest.php b/cosmogramme/tests/php/classes/KohaPeriodiquesTest.php
index e38cfb06231..7c0aa43197d 100644
--- a/cosmogramme/tests/php/classes/KohaPeriodiquesTest.php
+++ b/cosmogramme/tests/php/classes/KohaPeriodiquesTest.php
@@ -23,7 +23,9 @@ require_once 'NoticeIntegrationTest.php';
 
 
 abstract class KohaPeriodiquesTestCase extends NoticeIntegrationTestCase {
-  protected $_storm_default_to_volatile = true;
+  protected
+    $_storm_default_to_volatile = true,
+    $_sigb = Class_IntBib::SIGB_KOHA;
 
   public function getProfilDonnees() {
     return Class_IntProfilDonnees::forKoha()->setIdProfil(113)
diff --git a/cosmogramme/tests/php/classes/NoticeIntegrationOrpheeTest.php b/cosmogramme/tests/php/classes/NoticeIntegrationOrpheeTest.php
index 198907651ad..a7d9d953051 100644
--- a/cosmogramme/tests/php/classes/NoticeIntegrationOrpheeTest.php
+++ b/cosmogramme/tests/php/classes/NoticeIntegrationOrpheeTest.php
@@ -55,13 +55,18 @@ class NoticeIntegrationOrpheeDegreeTest extends NoticeIntegrationTestCase {
 
 /** @see http://forge.afi-sa.fr/issues/96923 */
 class NoticeIntegrationOrpheeSerialWithDoubleSearchNoneTest extends NoticeIntegrationTestCase {
-	public function setUp() {
+  protected
+    $_sigb = Class_IntBib::SIGB_ORPHEE,
+    $_items;
+
+  public function setUp() {
 		parent::setUp();
 
     Class_CosmoVar::setValueOf(Class_Notice_DoubleFinder::VAR_DOUBLE_MODE,
                                Class_CosmoVar::DOUBLE_SEARCH_NONE);
 
     $this->loadNotice('unimarc_orphee_96923');
+    $this->_items = new Storm_Model_Collection(Class_Exemplaire::findAllBy(['id_origine' => 'frOr0939524523']));
 	}
 
 
@@ -78,6 +83,12 @@ class NoticeIntegrationOrpheeSerialWithDoubleSearchNoneTest extends NoticeIntegr
   }
 
 
+  /** @test */
+  public function shouldHaveCreated29Items() {
+    $this->assertEquals(29, Class_Exemplaire::count());
+  }
+
+
   public function numbers() {
     return array_filter(array_map(function($number)
                                   {
@@ -103,8 +114,11 @@ class NoticeIntegrationOrpheeSerialWithDoubleSearchNoneTest extends NoticeIntegr
    * @test
    * @dataProvider numbers
    */
-  public function numberShouldHaveItsItemWithSpecificIdOrigine($number) {
-    $id = 'frOr0939524523-' . $number;
-    $this->assertNotNull(Class_Exemplaire::findFirstBy(['id_origine' => $id]));
+  public function numberShouldHaveItsItem($number) {
+    $this->assertNotNull($this->_items
+                         ->detect(function($item) use($number)
+                                  {
+                                    return $item->getSubfield('6') == $number;
+                                  }));
   }
 }
\ No newline at end of file
diff --git a/library/Class/IntProfilDonnees.php b/library/Class/IntProfilDonnees.php
index a4bf5e1be52..9f541e0b520 100644
--- a/library/Class/IntProfilDonnees.php
+++ b/library/Class/IntProfilDonnees.php
@@ -1155,7 +1155,6 @@ class Class_IntProfilDonnees extends Storm_Model_Abstract {
   }
 
 
-
   public function getProfilePrefs() {
     if(!$this->_profile_prefs)
       $this->_profile_prefs = (new Class_ProfilePrefs())->setDatas($this->toArray());
@@ -1167,4 +1166,14 @@ class Class_IntProfilDonnees extends Storm_Model_Abstract {
     // mmmmm, miam miam
     return $this->getTypeFichier() > 9;
   }
+
+
+  public function isSerialFormatOrphee() {
+    return static::SERIAL_FORMAT_ORPHEE == $this->getIdArticlePeriodique();
+  }
+
+
+  public function isSerialFormatKoha() {
+    return static::SERIAL_FORMAT_KOHA == $this->getIdArticlePeriodique();
+  }
 }
diff --git a/library/Class/Notice/DoubleFinder.php b/library/Class/Notice/DoubleFinder.php
index fa1c28d72d2..1e6eb93d853 100644
--- a/library/Class/Notice/DoubleFinder.php
+++ b/library/Class/Notice/DoubleFinder.php
@@ -66,6 +66,12 @@ class Class_Notice_DoubleFinder {
         && $this->_library->isPergame())
       return new Class_Notice_DoubleFinder_GlobalNoDedupStrategy($library_limit);
 
+    if ($this->_double_mode == Class_CosmoVar::DOUBLE_SEARCH_NONE
+        && Class_TypeDoc::PERIODIQUE == $this->_data->gettype_doc()
+        && $this->_profil
+        && ($this->_profil->isSerialFormatOrphee() || $this->_profil->isSerialFormatKoha()))
+      return new Class_Notice_DoubleFinder_AlphaKeyStrategy($library_limit);
+
     if ($this->_double_mode == Class_CosmoVar::DOUBLE_SEARCH_NONE)
       return new Class_Notice_DoubleFinder_NoDedupStrategy($this->_library->getId());
 
-- 
GitLab