From b6bb8b927c5b929d21566591c7a9f03a6b425d71 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Thu, 7 Jun 2012 14:54:24 -0400 Subject: [PATCH] LP#937789: fake-delete support for monograph parts Unlike copies, call numbers, and bibs, parts can be directly removed from the database. This has a negative impact on holds, in that the holds become not just orphaned, but broken entirely. With this commit we bring part holds to parity with other hold types such that they can be system-canceled when their target goes away. This will avoid spurious UI-level errors to staff. Signed-off-by: Mike Rylander Signed-off-by: Galen Charlton Signed-off-by: Remington Steed Signed-off-by: Ben Shum --- Open-ILS/examples/fm_IDL.xml | 1 + Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm | 2 +- .../src/perlmods/lib/OpenILS/Application/Search/Biblio.pm | 3 ++- .../lib/OpenILS/Application/Storage/CDBI/biblio.pm | 2 +- Open-ILS/src/perlmods/lib/OpenILS/Application/SuperCat.pm | 4 ++++ Open-ILS/src/sql/Pg/010.schema.biblio.sql | 1 + Open-ILS/src/sql/Pg/800.fkeys.sql | 7 +++++++ Open-ILS/src/sql/Pg/990.schema.unapi.sql | 4 ++-- .../src/sql/Pg/upgrade/XXXX.schema.fake-delete-parts.sql | 7 +++++++ .../src/templates/conify/global/biblio/monograph_part.tt2 | 2 +- Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js | 2 +- .../xul/staff_client/server/cat/volume_copy_creator.js | 2 +- 12 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fake-delete-parts.sql diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 37aab837d2..8cff802157 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -3056,6 +3056,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm index a1336e6eda..3d0ec381b0 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm @@ -2054,7 +2054,7 @@ sub basic_opac_copy_query { acpm => { type => 'left', join => { - bmp => { type => 'left' } + bmp => { type => 'left', filter => { deleted => 'f' } } } } } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm index 5c8449363e..8de593b840 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm @@ -2637,7 +2637,8 @@ sub rec_hold_parts { }, distinct => 1, } - } + }, + deleted => 'f' }, order_by =>[{class=>'bmp', field=>'label_sortkey'}] }; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/biblio.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/biblio.pm index 732dd9a1da..fde1a04126 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/biblio.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/biblio.pm @@ -43,7 +43,7 @@ package biblio::monograph_part; use base qw/biblio/; biblio::monograph_part->table( 'biblio_monograph_part' ); -biblio::monograph_part->columns( Essential => qw/id record label label_sortkey/ ); +biblio::monograph_part->columns( Essential => qw/id record label label_sortkey deleted/ ); #------------------------------------------------------------------------------- 1; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/SuperCat.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/SuperCat.pm index da7f806f27..1d94ef3372 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SuperCat.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SuperCat.pm @@ -3736,6 +3736,9 @@ sub as_xml { package OpenILS::Application::SuperCat::unAPI::acp; use base qw/OpenILS::Application::SuperCat::unAPI/; +use OpenILS::Application::AppUtils; +my $U = "OpenILS::Application::AppUtils"; + sub as_xml { my $self = shift; my $args = shift; @@ -3763,6 +3766,7 @@ sub as_xml { $xml .= " \n"; if (ref($self->obj->parts) && $self->obj->parts) { for my $part ( @{$self->obj->parts} ) { + next if $U->is_true($part->deleted); $xml .= sprintf(' %s',$part->record, $self->escape($part->label_sortkey), $self->escape($part->label)); $xml .= "\n"; } diff --git a/Open-ILS/src/sql/Pg/010.schema.biblio.sql b/Open-ILS/src/sql/Pg/010.schema.biblio.sql index 4ce54ae96b..ff0542d21d 100644 --- a/Open-ILS/src/sql/Pg/010.schema.biblio.sql +++ b/Open-ILS/src/sql/Pg/010.schema.biblio.sql @@ -98,6 +98,7 @@ CREATE TABLE biblio.monograph_part ( record BIGINT NOT NULL REFERENCES biblio.record_entry (id), label TEXT NOT NULL, label_sortkey TEXT NOT NULL, + deleted BOOL NOT NULL DEFAULT FALSE, CONSTRAINT record_label_unique UNIQUE (record,label) ); diff --git a/Open-ILS/src/sql/Pg/800.fkeys.sql b/Open-ILS/src/sql/Pg/800.fkeys.sql index da04275e78..a7604839e7 100644 --- a/Open-ILS/src/sql/Pg/800.fkeys.sql +++ b/Open-ILS/src/sql/Pg/800.fkeys.sql @@ -35,6 +35,13 @@ CREATE RULE protect_copy_location_delete AS DELETE FROM config.circ_limit_set_copy_loc_map WHERE copy_loc = OLD.id; ); +CREATE RULE protect_mono_part_delete AS + ON DELETE TO biblio.monograph_part DO INSTEAD ( + UPDATE biblio.monograph_part + SET deleted = TRUE + WHERE OLD.id = biblio.monograph_part.id + ); + ALTER TABLE actor.usr ADD CONSTRAINT actor_usr_mailing_address_fkey FOREIGN KEY (mailing_address) REFERENCES actor.usr_address (id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE actor.usr ADD CONSTRAINT actor_usr_billing_address_fkey FOREIGN KEY (billing_address) REFERENCES actor.usr_address (id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE actor.usr ADD CONSTRAINT actor_usr_home_ou_fkey FOREIGN KEY (home_ou) REFERENCES actor.org_unit (id) DEFERRABLE INITIALLY DEFERRED; diff --git a/Open-ILS/src/sql/Pg/990.schema.unapi.sql b/Open-ILS/src/sql/Pg/990.schema.unapi.sql index effa2b9879..fcc96e4378 100644 --- a/Open-ILS/src/sql/Pg/990.schema.unapi.sql +++ b/Open-ILS/src/sql/Pg/990.schema.unapi.sql @@ -576,7 +576,7 @@ RETURNS XML AS $F$ (SELECT XMLAGG(bmp) FROM ( SELECT unapi.bmp( id, 'xml', 'monograph_part', evergreen.array_remove_item_by_value( evergreen.array_remove_item_by_value($5,'bre'), 'holdings_xml'), $3, $4, $6, $7, FALSE) FROM biblio.monograph_part - WHERE record = $1 + WHERE NOT deleted AND record = $1 )x) ) ELSE NULL @@ -957,7 +957,7 @@ CREATE OR REPLACE FUNCTION unapi.bmp ( obj_id BIGINT, format TEXT, ename TEXT, CASE WHEN ('bre' = ANY ($4)) THEN unapi.bre( record, 'marcxml', 'record', evergreen.array_remove_item_by_value($4,'bmp'), $5, $6, $7, $8, FALSE) ELSE NULL END ) FROM biblio.monograph_part - WHERE id = $1 + WHERE NOT deleted AND id = $1 GROUP BY id, label, label_sortkey, record; $F$ LANGUAGE SQL STABLE; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fake-delete-parts.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fake-delete-parts.sql new file mode 100644 index 0000000000..ada71d28f3 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fake-delete-parts.sql @@ -0,0 +1,7 @@ +BEGIN; + +ALTER TABLE biblio.monograph_part ADD COLUMN deleted BOOL NOT NULL DEFAULT FALSE; +CREATE RULE protect_mono_part_delete AS ON DELETE TO biblio.monograph_part DO INSTEAD (UPDATE biblio.monograph_part SET deleted = TRUE WHERE OLD.id = biblio.monograph_part.id); + +COMMIT; + diff --git a/Open-ILS/src/templates/conify/global/biblio/monograph_part.tt2 b/Open-ILS/src/templates/conify/global/biblio/monograph_part.tt2 index dfc89cccbd..c1f246a705 100644 --- a/Open-ILS/src/templates/conify/global/biblio/monograph_part.tt2 +++ b/Open-ILS/src/templates/conify/global/biblio/monograph_part.tt2 @@ -37,7 +37,7 @@ openils.Util.addOnLoad( function() { monoPartGrid.overrideEditWidgets.record = new dijit.form.TextBox({"disabled": true}); monoPartGrid.overrideEditWidgets.record.shove = { create : cgi.param('r') }; - monoPartGrid.loadAll({order_by : [{class : 'bmp', field : 'label_sortkey'}]}, {record : cgi.param('r')}); + monoPartGrid.loadAll({order_by : [{class : 'bmp', field : 'label_sortkey'}]}, {deleted : 'f', record : cgi.param('r')}); }); [% END %] diff --git a/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js b/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js index 9d4d0888ba..f922cd6bbf 100644 --- a/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js +++ b/Open-ILS/web/js/ui/default/staff/cat/volcopy/app.js @@ -191,7 +191,7 @@ function(egCore , $q) { return $q.when(service.bmp_parts[rec]); return egCore.pcrud.search('bmp', - {record : rec}, + {record : rec, deleted : 'f'}, null, {atomic : true} ).then(function(list) { service.bmp_parts[rec] = list; diff --git a/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js b/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js index 0b16308cd7..950488ffd1 100644 --- a/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js +++ b/Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js @@ -205,7 +205,7 @@ function my_init() { dojo.require('openils.PermaCrud'); g.pcrud = new openils.PermaCrud({'authtoken':ses()}); - g.parts = g.pcrud.search('bmp',{'record':g.doc_id},{'order_by': { 'bmp' : 'label_sortkey' } }); + g.parts = g.pcrud.search('bmp',{'deleted':'f', 'record':g.doc_id},{'order_by': { 'bmp' : 'label_sortkey' } }); g.parts_hash = util.functional.convert_object_list_to_hash( g.parts ); /***********************************************************************************************************/ -- 2.43.2