From 7f78c4ef341be333ff8718ebd6e55bc46af511cf Mon Sep 17 00:00:00 2001
From: Alex Arnaud <alex.arnaud@biblibre.com>
Date: Tue, 14 Oct 2014 15:48:06 +0200
Subject: [PATCH] hotline #16902 Fix retrieval of items informations when
 updating record

---
 .../php/classes/classe_notice_integration.php |  4 ++--
 cosmogramme/php/classes/classe_unimarc.php    | 11 ++++-----
 .../php/classes/NoticeIntegrationTest.php     | 23 +++++++++++++++++++
 library/Class/NoticeUnimarc/Writer.php        |  7 ++++++
 4 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/cosmogramme/php/classes/classe_notice_integration.php b/cosmogramme/php/classes/classe_notice_integration.php
index 8e20c29b163..fe3dfa1c6d9 100644
--- a/cosmogramme/php/classes/classe_notice_integration.php
+++ b/cosmogramme/php/classes/classe_notice_integration.php
@@ -613,7 +613,7 @@ class notice_integration {
 			"qualite" => $this->notice["qualite"],
 			"exportable" => $this->notice["exportable"],
 			"cote" => $this->notice["cote"],
-						"unimarc" => $this->notice["unimarc"],
+			"unimarc" => $this->notice['unimarc'],
 			"date_maj" => dateDuJour(2) ];
 	}
 
@@ -648,7 +648,7 @@ class notice_integration {
 
 		// Si la notice de la base est de meilleure qualite on la prend
 		if ($this->statut == static::RECORD_RENEW)
-			$this->notice_sgbd->ouvrirNotice($this->notice["unimarc"], 0);
+			$this->notice_sgbd->ouvrirNotice($this->notice["unimarc_with_items"], 0);
 
 		$this->updateForcedZones($champs_forces, $this->notice["champs_forces"]);
 		$this->notice = $this->notice_sgbd->getNoticeIntegration();
diff --git a/cosmogramme/php/classes/classe_unimarc.php b/cosmogramme/php/classes/classe_unimarc.php
index 6f2f727885c..c0491e71d42 100644
--- a/cosmogramme/php/classes/classe_unimarc.php
+++ b/cosmogramme/php/classes/classe_unimarc.php
@@ -183,11 +183,9 @@ class notice_unimarc extends iso2709_record {
 			}
 		}
 
-		// On supprime les exemplaires
-		$this->delete_field("995");
-		if($this->profil["attributs"][0]["champ_code_barres"] == "997") $this->delete_field("997"); // astrolabe
-		if($this->profil["attributs"][0]["champ_code_barres"] == "852") $this->delete_field("852"); // Moulins
-		$notice["unimarc"] = $this->update();
+		$notice['unimarc_with_items'] = $this->update();
+		$this->delete_items();
+		$notice['unimarc'] = $this->update();
 
 		// Warnings
 		$notice["warnings"] = $warnings;
@@ -1075,8 +1073,7 @@ class notice_unimarc extends iso2709_record {
 
 
 	public function getCote() {
-		// pergame uniquement
-		if ($this->sigb!=1)
+		if (!$this->sigb != Class_IntBib::COM_PERGAME)
 			return false;
 
 		$data = $this->get_subfield('686', 'a');
diff --git a/cosmogramme/tests/php/classes/NoticeIntegrationTest.php b/cosmogramme/tests/php/classes/NoticeIntegrationTest.php
index 898d60ae4a0..2d0f8947731 100644
--- a/cosmogramme/tests/php/classes/NoticeIntegrationTest.php
+++ b/cosmogramme/tests/php/classes/NoticeIntegrationTest.php
@@ -1709,4 +1709,27 @@ class NoticeIntegrationInterestEsperluette extends NoticeIntegrationTestCase {
 	public function deweyShouldContainsEsperluette() {
 		$this->assertEquals('ESPERLUETTE ESPERLUET 2014', $this->notice->getDewey());
 	}
+}
+
+
+
+class NoticeIntegrationAuxAnimauxLaGuerre extends NoticeIntegrationTestCase {
+	public function getProfilDonnees() {
+		$profil = Class_IntProfilDonnees::forNanook()->setIdProfil(110);
+		return $profil->getRawAttributes();
+	}
+
+
+	public function setUp() {
+		parent::setUp();
+
+		$this->loadNotice('unimarc_aux_animaux_la_guerre');
+	}
+
+	/** @test */
+	public function noticeAuxAnimauxLaGuerreCallNumberShouldNotBeEmpty() {
+		$this->loadNotice('unimarc_aux_animaux_la_guerre');
+		$notice = Class_Notice::find(1);
+		$this->assertEquals('RP MATH', $notice->getCote());
+	}
 }
\ No newline at end of file
diff --git a/library/Class/NoticeUnimarc/Writer.php b/library/Class/NoticeUnimarc/Writer.php
index 6f5b139d3c4..5756aa11b48 100644
--- a/library/Class/NoticeUnimarc/Writer.php
+++ b/library/Class/NoticeUnimarc/Writer.php
@@ -236,6 +236,13 @@ class Class_NoticeUnimarc_Writer extends Class_NoticeUnimarc {
 	}
 
 
+	public function delete_items() {
+		$this->delete_field("995");
+		if($this->profil["attributs"][0]["champ_code_barres"] == "997") $this->delete_field("997"); // astrolabe
+		if($this->profil["attributs"][0]["champ_code_barres"] == "852") $this->delete_field("852"); // Moulins
+	}
+
+
 	public function delete_field($label, $index = -1) {
 		if (!func_num_args()) {
 			$this->errors[] = '[delete_field] pas de label pour le champ';
-- 
GitLab