diff --git a/VERSIONS_HOTLINE/38194 b/VERSIONS_HOTLINE/38194 new file mode 100644 index 0000000000000000000000000000000000000000..ee8e9f23dc2ca1c6fa1f34e6212955c9a6ff0c05 --- /dev/null +++ b/VERSIONS_HOTLINE/38194 @@ -0,0 +1 @@ + - ticket #38194 : Cosmogramme : Correction de la perte des facettes de tags lors d'un réimport de notice \ 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 3461921ed94aef8351d62e04608af62c47acefb1..3cd826c265880721cee1921be7012020a7531e19 100644 --- a/cosmogramme/php/classes/classe_notice_integration.php +++ b/cosmogramme/php/classes/classe_notice_integration.php @@ -672,7 +672,7 @@ class notice_integration { if ($this->statut == static::RECORD_UPDATE) return $id_notice; - $this->traiteFacettes(); + $this->traiteFacettes($id_notice); $existing_notice ->updateAttributes($this->noticeToDBEnreg()) @@ -810,20 +810,15 @@ class notice_integration { } - public function traiteFacettes() { - global $sql; - + public function traiteFacettes($id_notice=null) { $facettes = []; - $notice_facettes = isset($this->notice["facettes"]) - ? $this->notice["facettes"] - : ''; - // Virer les facettes sauf les tags - foreach(explode(' ', $notice_facettes) as $facet) { - $tp=substr($facet, 0, 1); - if($tp =="Z") - $facettes []= $facet; - } + // Tags + if ($id_notice) + foreach (Class_CodifTags::findForRecord($id_notice) as $tag) + $facettes[] = $tag->asFacet(); + + // Doc type if($type_doc = $this->notice['infos_type_doc']) { if($code_type_doc = $type_doc['code']){ $facettes[] = 'T'.$code_type_doc; @@ -861,7 +856,6 @@ class notice_integration { $facettes[]="P".$indice; } - // Thesaurus if($thesauri=$this->notice["thesauri"]) { diff --git a/cosmogramme/sql/patch/patch_289.php b/cosmogramme/sql/patch/patch_289.php new file mode 100644 index 0000000000000000000000000000000000000000..c27728decea795115442cdc157813d850f2626ce --- /dev/null +++ b/cosmogramme/sql/patch/patch_289.php @@ -0,0 +1,7 @@ +<?php +$adapter = Zend_Db_Table::getDefaultAdapter(); + +try { + $adapter->query('ALTER TABLE codif_tags ADD FULLTEXT notices (notices)'); +} catch(Exception $e) {} +?> diff --git a/cosmogramme/tests/php/classes/NoticeIntegrationDedupTest.php b/cosmogramme/tests/php/classes/NoticeIntegrationDedupTest.php index 263b45d1ffed2bb12d69c7412081defd84dde4d3..173896368a1a50f024b4930cb3d0c2a9ced43ee7 100644 --- a/cosmogramme/tests/php/classes/NoticeIntegrationDedupTest.php +++ b/cosmogramme/tests/php/classes/NoticeIntegrationDedupTest.php @@ -78,6 +78,58 @@ class NoticeIntegrationDedupWithoutIsbnTest extends NoticeIntegrationTestCase { } +/** @see http://forge.afi-sa.fr/issues/38194 */ +class NoticeIntegrationDedupSameUnimarcLoadedTest extends NoticeIntegrationTestCase { + public function getProfilDonnees() { + return Class_IntProfilDonnees::forALOES()->setIdProfil(113) + ->getRawAttributes(); + } + + + public function setUp() { + parent::setUp(); + + VariableCache::getInstance() + ->setValeurCache(['filtrer_fulltext' => 1, + 'mode_doublon'=> 0, + 'tracer_accents_iso'=>1, + 'non_exportable'=> 'electre;decitre;gam;zebris', + 'controle_codes_barres'=> 0, + 'unimarc_zone_titre' => '200$a;461$t', + 'unicite_code_barres' => 0, + 'champs_sup' => '', + 'ean_345' => '']); + + $this->loadNotice('unimarc_dernier_des_hommes'); + + $record = Class_Notice::findFirstBy([]); + $this->tag = $this->fixture('Class_CodifTags', + ['id' => 1, + 'code_alpha' => 'CDC', + 'notices' => ';' . $record->getId() . ';']); + $record->updateFacette($this->tag->asFacet()) + ->save(); + + $this->onLoaderOfModel('Class_CodifTags') + ->whenCalled('findForRecord')->with(1)->answers([$this->tag]); + + $this->loadNotice('unimarc_dernier_des_hommes'); + } + + + /** @test */ + public function shouldHaveOnlyOneRecord() { + $this->assertEquals(1, Class_Notice::count()); + } + + + /** @test */ + public function recordShouldHaveTagFacet() { + $this->assertContains('Z1', Class_Notice::findFirstBy([])->getFacettes()); + } +} + + /** @see http://forge.afi-sa.fr/issues/29226 */ class NoticeIntegrationDedupCaliceWithoutIsbnTest extends NoticeIntegrationTestCase { diff --git a/library/Class/CodifTags.php b/library/Class/CodifTags.php index 6e253fab3eaf3916a0aaac52c1103dbf07cc56f8..0a1356ca6ba198edb209a02978dade5c3e2db7a8 100644 --- a/library/Class/CodifTags.php +++ b/library/Class/CodifTags.php @@ -16,13 +16,25 @@ * * 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 Class_CodifTagsLoader extends Storm_Model_Loader { + public function findForRecord($id) { + return Class_CodifTags::findAll('select * from codif_tags where MATCH(notices) AGAINST( "+;' . (int)$id . ';" IN BOOLEAN MODE)'); + } +} + + + class Class_CodifTags extends Storm_Model_Abstract { - const CODE_FACETTE='Z'; + use Trait_Facetable; + + const CODE_FACETTE = 'Z'; + const SEPARATOR = ';'; + protected $_table_name = 'codif_tags'; protected $_table_primary = 'id_tag'; -} -?> \ No newline at end of file + protected $_loader_class = 'Class_CodifTagsLoader'; +} \ No newline at end of file diff --git a/tests/db/UpgradeDBTest.php b/tests/db/UpgradeDBTest.php index ee5358183e16f6d9d170bb570d583ad7537e18ab..82d8af7d28c6e1d9ea8b691b81923b52ed63fcd0 100644 --- a/tests/db/UpgradeDBTest.php +++ b/tests/db/UpgradeDBTest.php @@ -110,6 +110,23 @@ abstract class UpgradeDBTestCase extends PHPUnit_Framework_TestCase { $this->fail($message); } + + + protected function assertIndex($table, $name, $type, $message='') { + try { + foreach($this->query(sprintf('show keys in `%s`', $table))->fetchAll() as $row) { + if ($name == $row['Key_name'] && $type == $row['Index_type']) + return true; + } + } catch (Exception $e) {} + + $message = $message + ? $message + : sprintf('Failed asserting that "%s" table CONTAINS an index "%s" of type "%s".', + $table, $name, $type); + + $this->fail($message); + } } @@ -477,4 +494,20 @@ class UpgradeDB_288_Test extends UpgradeDBTestCase { public function bibCSiteShouldContainsColumnClosedOnHolidays() { $this->assertColumn('bib_c_site', 'closed_on_holidays'); } +} + + + +class UpgradeDB_289_Test extends UpgradeDBTestCase { + public function prepare() { + try { + $this->query('ALTER TABLE codif_tags DROP INDEX notices'); + } catch(Exception $e) {} + } + + + /** @test */ + public function fulltextIndexShouldExists() { + $this->assertIndex('codif_tags', 'notices', 'FULLTEXT'); + } } \ No newline at end of file