From: Mike Rylander Date: Wed, 8 Jul 2020 17:18:52 +0000 (-0400) Subject: LP#1886852: Protect against dupes in hold-copy map function X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=53b9deca88551f8d32985949436a8433a88ef502;p=Evergreen.git LP#1886852: Protect against dupes in hold-copy map function If the DB function that regenerates the hold-copy maps for a hold receives duplicate copies in its second parameter, it blows up. This commit prevents that by making the list unique at use time. Signed-off-by: Mike Rylander Signed-off-by: Jason Stephenson --- diff --git a/Open-ILS/src/sql/Pg/090.schema.action.sql b/Open-ILS/src/sql/Pg/090.schema.action.sql index af8a3e36b9..8d8163b6f9 100644 --- a/Open-ILS/src/sql/Pg/090.schema.action.sql +++ b/Open-ILS/src/sql/Pg/090.schema.action.sql @@ -548,7 +548,7 @@ CREATE OR REPLACE FUNCTION action.hold_request_regen_copy_maps( hold_id INTEGER, copy_ids INTEGER[]) RETURNS VOID AS $$ DELETE FROM action.hold_copy_map WHERE hold = $1; - INSERT INTO action.hold_copy_map (hold, target_copy) SELECT $1, UNNEST($2); + INSERT INTO action.hold_copy_map (hold, target_copy) SELECT DISTINCT $1, UNNEST($2); $$ LANGUAGE SQL; CREATE TABLE action.transit_copy ( diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.function.distinct-regen_copy_map.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.function.distinct-regen_copy_map.sql new file mode 100755 index 0000000000..2d4739a48e --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.function.distinct-regen_copy_map.sql @@ -0,0 +1,12 @@ +BEGIN; + +SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +CREATE OR REPLACE FUNCTION + action.hold_request_regen_copy_maps( + hold_id INTEGER, copy_ids INTEGER[]) RETURNS VOID AS $$ + DELETE FROM action.hold_copy_map WHERE hold = $1; + INSERT INTO action.hold_copy_map (hold, target_copy) SELECT DISTINCT $1, UNNEST($2); +$$ LANGUAGE SQL; + +COMMIT;