diff --git a/VERSIONS_HOTLINE/29043 b/VERSIONS_HOTLINE/29043 new file mode 100644 index 0000000000000000000000000000000000000000..b0b210089e1e321c27ca349939e969643a3832e5 --- /dev/null +++ b/VERSIONS_HOTLINE/29043 @@ -0,0 +1 @@ + - ticket #29043 : Correction de la prise en compte du décodage des accents pour les fichiers code barres de suppression d'exemplaires \ No newline at end of file diff --git a/cosmogramme/php/classes/classe_jsredirect.php b/cosmogramme/php/classes/classe_jsredirect.php index d5bb914113a1e6723f6d2ec3c4c1c5e29a955879..9f80467f8aa9506abad41e8c18bad2bef5bdf15c 100644 --- a/cosmogramme/php/classes/classe_jsredirect.php +++ b/cosmogramme/php/classes/classe_jsredirect.php @@ -16,14 +16,14 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class JSRedirect { public function render($url) { - if ((0!== strpos($url, URL_BASE)) && (strleft($url,4) != "http")) + if ((0!== strpos($url, URL_BASE)) && (substr($url, 0, 4) != "http")) $url=URL_BASE."php/".$url; - return + return '<script>' .'document.location="'.$url.'"' .'</script>'; diff --git a/cosmogramme/php/classes/classe_notice_ascii.php b/cosmogramme/php/classes/classe_notice_ascii.php index 6f712f6eaee7a5c8e848e212adf6da2ff26a2699..bf8cd4e982da586ab68d742242544ecc1a2b3b3a 100644 --- a/cosmogramme/php/classes/classe_notice_ascii.php +++ b/cosmogramme/php/classes/classe_notice_ascii.php @@ -134,7 +134,7 @@ class notice_ascii // ---------------------------------------------------------------- public function getExemplaire() { - $ex["code_barres"]=strleft(trim($this->enreg["code_barres"]),20); + $ex["code_barres"]=substr(trim($this->enreg["code_barres"]), 0, 20); $ex["cote"]=$this->enreg["cote"]; $ex["activite"]=$this->enreg["activite"]; if( !$ex["activite"] ) $ex["activite"]="non disponible"; diff --git a/cosmogramme/php/classes/classe_unimarc.php b/cosmogramme/php/classes/classe_unimarc.php index 7d1d7bc364e0cfc1625abbe9febf79b3ce05c387..65b5ac0c879cb355ab7178791e9c2bef894a2cbc 100644 --- a/cosmogramme/php/classes/classe_unimarc.php +++ b/cosmogramme/php/classes/classe_unimarc.php @@ -719,7 +719,7 @@ class notice_unimarc extends iso2709_record { if ($this->controle_codes_barres == 1) return utf8_encode(addslashes($code_barres)); - $cab = trim(strleft($code_barres, 20)); + $cab = substr(trim($code_barres), 0, 20); if (is_numeric($code_barres)) return $cab; diff --git a/cosmogramme/tests/php/classes/microbib_delete_items.txt b/cosmogramme/tests/php/classes/microbib_delete_items.txt new file mode 100644 index 0000000000000000000000000000000000000000..c191e6903016dc373f086faabb79fefc01647784 --- /dev/null +++ b/cosmogramme/tests/php/classes/microbib_delete_items.txt @@ -0,0 +1,13 @@ +02Ç9270194 +0147560194 +0145870194 +0145890194 +0145900194 +0145910194 +0307760194 +0002450021 +0002430021 +0190610194 +0313010194 +0313000194 +0243170194 diff --git a/library/Class/Cosmogramme/FileParser.php b/library/Class/Cosmogramme/FileParser.php index a3988eb74cc00520e89311da194740ce9545f68b..8f6b818d7f665cf81d7af5a30e76df1de8635e1d 100644 --- a/library/Class/Cosmogramme/FileParser.php +++ b/library/Class/Cosmogramme/FileParser.php @@ -42,7 +42,7 @@ abstract class Class_Cosmogramme_FileParser { self::FORMAT_CSV => 'Csv', self::FORMAT_MARC21 => 'Marc']; - protected $_file_handle, $_position, $_file_size; + protected $_file_handle, $_position, $_file_size, $_profil; protected $_errors = []; @@ -69,7 +69,7 @@ abstract class Class_Cosmogramme_FileParser { $this->_buffer = ''; $this->_file_size = $fileSystem->filesize($file); - + $this->_profil = $profil; return true; } @@ -158,6 +158,14 @@ abstract class Class_Cosmogramme_FileParser_Ascii extends Class_Cosmogramme_File $fileSystem = $this->getFileSystem(); $data = trim($fileSystem->fgets($this->_file_handle)); $data = str_getcsv($data, $this->_separator); + + $decoder = new Class_NoticeUnimarc_Writer(); + + foreach($data as $index => $value) { + $data[$index] = $decoder->decode_accents($value, + $this->_profil->getAccents()); + } + $this->_position = $fileSystem->ftell($this->_file_handle); $ret = new Class_Cosmogramme_FileParser_Record($data); diff --git a/library/Class/NoticeUnimarc/Writer.php b/library/Class/NoticeUnimarc/Writer.php index daebecdb3b01c924bef9faa7646326979a8102b3..7cb0544ddd34cc6e86bf4f77cfad7da81188d38f 100644 --- a/library/Class/NoticeUnimarc/Writer.php +++ b/library/Class/NoticeUnimarc/Writer.php @@ -261,7 +261,7 @@ class Class_NoticeUnimarc_Writer extends Class_NoticeUnimarc { $this->inner_data[$label] = []; foreach($contents as $content) { $new_content = ($this->type_accents > 0) - ? $this->decode_accents($content) + ? $this->decode_accents($content, $this->type_accents) : $content; if ($export_accents == 1) $new_content = $this->ISO_encode($content); @@ -367,13 +367,13 @@ class Class_NoticeUnimarc_Writer extends Class_NoticeUnimarc { } - public function decode_accents($chaine) { - switch ($this->type_accents) { - case 0: return $chaine; // Utf8 - case 1: return $this->ISO_decode($chaine); // Iso standard - case 2: return $this->ansi_decode($chaine); // Windows - case 4: return $this->marc21_decode($chaine); // marc21 - default: return $chaine; + public function decode_accents($chaine, $type_accents) { + switch ($type_accents) { + case Class_IntProfilDonnees::ENCODING_UTF8: return $chaine; + case Class_IntProfilDonnees::ENCODING_ISO2709: return $this->ISO_decode($chaine); + case Class_IntProfilDonnees::ENCODING_WINDOWS_ANSI: return $this->ansi_decode($chaine); + case Class_IntProfilDonnees::ENCODING_MARC21: return $this->marc21_decode($chaine); + default: return $chaine; } } diff --git a/tests/library/Class/Cosmogramme/Integration/PhaseDeleteItemsTest.php b/tests/library/Class/Cosmogramme/Integration/PhaseDeleteItemsTest.php index f3271d174039029a6ffe7dcd9eab618023873f95..d9256b5a23ce4d2274bb140f1d81f8a57707f0db 100644 --- a/tests/library/Class/Cosmogramme/Integration/PhaseDeleteItemsTest.php +++ b/tests/library/Class/Cosmogramme/Integration/PhaseDeleteItemsTest.php @@ -21,7 +21,8 @@ require_once('cosmogramme/php/fonctions/variables.php'); -class PhaseDeleteItemsTest extends Class_Cosmogramme_Integration_PhaseTestCase { + +abstract class PhaseDeleteItemsTestCase extends Class_Cosmogramme_Integration_PhaseTestCase { protected $_phase; public function setUp() { @@ -30,7 +31,6 @@ class PhaseDeleteItemsTest extends Class_Cosmogramme_Integration_PhaseTestCase $this->_phase = $this->_buildPhase('DeleteItem')->run(); } - protected function _prepareFixtures() { $this->fixture('Class_IntProfilDonnees', ['id' => 102, @@ -59,6 +59,20 @@ class PhaseDeleteItemsTest extends Class_Cosmogramme_Integration_PhaseTestCase 'traite' => 'non', 'fichier' => 'barcodes_deleted.txt', 'pointeur_reprise' => 0]); + } + + + protected function _getPreviousPhase() { + return (new Class_Cosmogramme_Integration_Phase(1)) + ->beCron(); + } +} + + + +class PhaseDeleteItemsTest extends PhaseDeleteItemsTestCase { + protected function _prepareFixtures() { + parent::_prepareFixtures(); $this->fixture('Class_Notice', ['id' => 2, @@ -84,15 +98,49 @@ class PhaseDeleteItemsTest extends Class_Cosmogramme_Integration_PhaseTestCase } - protected function _getPreviousPhase() { - return (new Class_Cosmogramme_Integration_Phase(1)) - ->beCron(); - } - - /** @test */ public function newPhaseShouldBe1Dot1() { $this->assertTrue($this->_phase->isId(1.1)); } +} + + + +class PhaseDeleteItemsFromANSIFileTest extends PhaseDeleteItemsTestCase { + protected function _prepareFixtures() { + parent::_prepareFixtures(); + Class_IntProfilDonnees::find(102) + ->setAccents(Class_IntProfilDonnees::ENCODING_WINDOWS_ANSI) + ->setFormat(Class_IntProfilDonnees::FORMAT_TABBED_ASCII) + ->setAttributs([['type_doc' => [], + 'champ_cote' => ''], + [], + Class_IntProfilDonnees::FORMAT_TABBED_ASCII => ['champs' => 'code_barres']]); + + Class_Cosmogramme_Integration::find(2) + ->setFichier('barcodes_deleted_ansi.txt'); + + $this->fixture('Class_Notice', + ['id' => 2, + 'clef_alpha' => 'TINTIN', + 'exemplaires' => [ + $this->fixture('Class_Exemplaire', + ['id' => 3, + 'id_int_bib' => 2, + 'code_barres' => '02Ç9270194']), + $this->fixture('Class_Exemplaire', + ['id' => 4, + 'id_int_bib' => 2, + 'code_barres' => 'X897']) + ] + ]); + } + + + /** @test */ + public function firstItemShouldBeDeleted() { + Class_Exemplaire::clearCache(); + $this->assertNull(Class_Exemplaire::find(3)); + } } \ No newline at end of file diff --git a/tests/library/Class/Cosmogramme/Integration/barcodes_deleted_ansi.txt b/tests/library/Class/Cosmogramme/Integration/barcodes_deleted_ansi.txt new file mode 100644 index 0000000000000000000000000000000000000000..8eb15b157d7525ffc303a6449a94c8665d6ae171 --- /dev/null +++ b/tests/library/Class/Cosmogramme/Integration/barcodes_deleted_ansi.txt @@ -0,0 +1,2 @@ +02Ç9270194 +0147560194