From d4ee020ca0382fe5559703359dbd133bcb2c9a5a Mon Sep 17 00:00:00 2001
From: Laurent Laffont <llaffont@afi-sa.fr>
Date: Tue, 19 Feb 2019 15:02:43 +0100
Subject: [PATCH] hotline #87090 WS Carthame : filter barcodes sent by WS to
 get only real barcodes

---
 VERSIONS_HOTLINE/87090                                   | 1 +
 .../WebService/SIGB/Carthame/RecordResponseReader.php    | 5 +++++
 tests/library/Class/WebService/SIGB/CarthameTest.php     | 9 +++++++++
 3 files changed, 15 insertions(+)
 create mode 100644 VERSIONS_HOTLINE/87090

diff --git a/VERSIONS_HOTLINE/87090 b/VERSIONS_HOTLINE/87090
new file mode 100644
index 00000000000..0d8fd576f4c
--- /dev/null
+++ b/VERSIONS_HOTLINE/87090
@@ -0,0 +1 @@
+ - ticket #87090 : Web services SIGB Carthame : contournement des erreurs du web service qui peut renvoyer plusieurs valeurs différentes pour le code barres exemplaire.
\ No newline at end of file
diff --git a/library/Class/WebService/SIGB/Carthame/RecordResponseReader.php b/library/Class/WebService/SIGB/Carthame/RecordResponseReader.php
index 4027ca00b07..9811a3935d5 100644
--- a/library/Class/WebService/SIGB/Carthame/RecordResponseReader.php
+++ b/library/Class/WebService/SIGB/Carthame/RecordResponseReader.php
@@ -23,6 +23,7 @@ class Class_WebService_SIGB_Carthame_RecordResponseReader {
   const STATUT_RESERVE = 3;
   const STATUT_PRETE = 4;
   const STATUT_EXCLU = 6;
+  const BARCODE_MIN_LEN = 4;
 
   /** @var Class_WebService_XMLParser */
   protected $_xml_parser;
@@ -67,6 +68,10 @@ class Class_WebService_SIGB_Carthame_RecordResponseReader {
 
 
   public function endSFa($data) {
+    //@see http://forge.afi-sa.fr/issues/87090
+    if (strlen(trim($data)) < static::BARCODE_MIN_LEN)
+      return;
+
     $this->_current_exemplaire->setCodeBarre((string)$data);
   }
 
diff --git a/tests/library/Class/WebService/SIGB/CarthameTest.php b/tests/library/Class/WebService/SIGB/CarthameTest.php
index 9adac9a53bc..77470fd4484 100644
--- a/tests/library/Class/WebService/SIGB/CarthameTest.php
+++ b/tests/library/Class/WebService/SIGB/CarthameTest.php
@@ -134,10 +134,18 @@ class CarthameKtmNoticeAlbatorTest extends CarthameTestCase {
     $copies = $this->albator->getExemplaires();
     $this->assertEquals('Disponible', $copies[0]->getDisponibilite());
   }
+
+
+  /** @test */
+  public function secondCopyBarCodeShouldBe88446464646() {
+    $copies = $this->albator->getExemplaires();
+    $this->assertEquals('88446464646', $copies[1]->getCodeBarre());
+  }
 }
 
 
 
+
 abstract class CarthameOperationTestCase extends CarthameTestCase {
   public function setUp() {
     parent::setUp();
@@ -988,6 +996,7 @@ class CarthameTestFixtures {
             <SFv>Quetigny</SFv>
             <SFo>3</SFo>
             <SFq>20111111</SFq>
+            <SFA>T</SFA>
           </F941>
         </Unimarc>
       </Notice>
-- 
GitLab