From aa6fe112068668e33f39d7c714a69b1b8d46f193 Mon Sep 17 00:00:00 2001 From: Rogan Hamby Date: Tue, 21 Nov 2017 18:50:34 -0500 Subject: [PATCH] LP#1731960-preserving book bag entries with new values during bib merge The asset.merge_record_assets() removes bib records from containers when merging and deleting the record as appropriate but bib containers with the btype of 'bookbag' (used as reading lists) should instead be updated to the new bib record. Includes Pgtap test. Signed-off-by: Rogan Hamby Signed-off-by: Cesar Velez Signed-off-by: Kathy Lussier Conflicts: Open-ILS/src/sql/Pg/999.functions.global.sql --- Open-ILS/src/sql/Pg/999.functions.global.sql | 6 +++ .../t/lp1731960_test_preserving_bookbag_entries.pg | 59 ++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 Open-ILS/src/sql/Pg/t/lp1731960_test_preserving_bookbag_entries.pg diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql index 44157c120b..521e96585e 100644 --- a/Open-ILS/src/sql/Pg/999.functions.global.sql +++ b/Open-ILS/src/sql/Pg/999.functions.global.sql @@ -1220,6 +1220,12 @@ BEGIN SET merge_date = NOW(), merged_to = target_record WHERE id = source_record; + -- replace book bag entries of source_record with target_record + UPDATE container.biblio_record_entry_bucket_item + SET target_biblio_record_entry = target_record + WHERE bucket IN (SELECT id FROM container.biblio_record_entry_bucket WHERE btype = 'bookbag') + AND target_biblio_record_entry = source_record; + -- Finally, "delete" the source record DELETE FROM biblio.record_entry WHERE id = source_record; diff --git a/Open-ILS/src/sql/Pg/t/lp1731960_test_preserving_bookbag_entries.pg b/Open-ILS/src/sql/Pg/t/lp1731960_test_preserving_bookbag_entries.pg new file mode 100644 index 0000000000..5c16d8e009 --- /dev/null +++ b/Open-ILS/src/sql/Pg/t/lp1731960_test_preserving_bookbag_entries.pg @@ -0,0 +1,59 @@ +BEGIN; + +SELECT plan(2); + +---------------------------------- +-- +-- Setup Test environment and data +-- +---------------------------------- + +-- test records to dedupe and containers: +-- bib 60500 (source) +-- bib 60501 (target) +-- + +-- create bib 60,500 +INSERT into biblio.record_entry (id, marc, last_xact_id) + VALUES (60500, + $$ +01938cam a2200337Ii 4500827439320170831142031.0170522s2017 mauaf e 000 1 eng d9781328791825(hardcover)1328791823(hardcover)(OCoLC)987617974823/.91223Tolkien, J. R. R.(John Ronald Reuel),1892-1973,author.Beren and Lúthien /by J.R.R. Tolkien ; edited by Christopher Tolkien ; with illustrations by Alan Lee.First U.S. edition.Boston :Houghton Mifflin Harcourt,2017.288 pages, 9 unnumbered leaves of plates :illustrations (some color) ;22 cm. + $$, + 'PGTAP' + ); + + +-- create bib 60,501 +INSERT into biblio.record_entry (id, marc, last_xact_id) + VALUES (60001, + $$ +01938cam a2200337Ii 4500827439220170831142031.0170522s2017 mauaf e 000 1 eng d9781328791825(hardcover)1328791823(hardcover)(OCoLC)987617974823/.91223Tolkien, J. R. R.(John Ronald Reuel),1892-1973,author.Beren and Lúthien /by J.R.R. Tolkien ; edited by Christopher Tolkien ; with illustrations by Alan Lee.First U.S. edition.Boston :Houghton Mifflin Harcourt,2017.288 pages, 9 unnumbered leaves of plates :illustrations (some color) ;22 cm.texttxtrdacontentunmediatednrdamediavolumerdacarrierBeren was a mortal man, but Lúthien was an immortal elf. Her father, a great elvish lord, in deep opposition to Beren, imposed on him an impossible task that he must perform before he might wed Lúthien. To show something of the process whereby this legend of Middle-earth evolved over the years, Christopher Tolkien has told the story in his father's own words by giving, first, its original form, and then passages in prose and verse from later texts that illustrate the narrative as it changed. Presented together for the first time, they reveal aspects of the story, both in event and in narrative immediacy, that were afterwards lost.--From publisher's description.Middle Earth (Imaginary place)Fiction.ElvesFiction.Quests (Expeditions)Fiction.Good and evilFiction.Fantasy fiction.lcgftTolkien, Christopher,editor.Lee, Alan,illustrator.Tolkien, J. R. R.(John Ronald Reuel),1892-1973.Silmarillion. + $$, + 'PGTAP' + ); + +INSERT INTO container.biblio_record_entry_bucket (id, owner, name, btype) + VALUES + (101, 1, 'Bookbag Bucket', 'bookbag'); + +INSERT INTO container.biblio_record_entry_bucket_item (id, bucket, target_biblio_record_entry) + VALUES + (101, 101, 60500); + +----------------------------------- +-- Test asset.merge_record_assets() +----------------------------------- + +SELECT is(asset.merge_record_assets(60501, 60500), 0, 'Record assets merged!'); + +-- check if bucket 101's entry 101 was updated to 60501 +SELECT is( + (SELECT target_biblio_record_entry from container.biblio_record_entry_bucket_item where id=101)::BIGINT, + 60501::BIGINT, + 'LP 1731960 asset.merge_record_assets() preserve book bag entries, bib bucket item 101 should be 60501' +); + +SELECT * FROM finish(); + +ROLLBACK; + -- 2.11.0