LP#937789: fake-delete support for monograph parts
authorBen Shum <bshum@biblio.org>
Fri, 6 Nov 2015 14:47:16 +0000 (09:47 -0500)
committerGalen Charlton <gmc@esilibrary.com>
Mon, 30 Nov 2015 20:55:59 +0000 (15:55 -0500)
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.

Conflicts: rel_2_8 does not contain the cataloging module for webstaff, commit
amended.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Remington Steed <rjs7@calvin.edu>
Signed-off-by: Ben Shum <bshum@biblio.org>
Conflicts:
Open-ILS/src/sql/Pg/800.fkeys.sql

Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/lib/OpenILS/Application/AppUtils.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/CDBI/biblio.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/SuperCat.pm
Open-ILS/src/sql/Pg/010.schema.biblio.sql
Open-ILS/src/sql/Pg/800.fkeys.sql
Open-ILS/src/sql/Pg/990.schema.unapi.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fake-delete-parts.sql [new file with mode: 0644]
Open-ILS/src/templates/conify/global/biblio/monograph_part.tt2
Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js

index d355b04..efd074f 100644 (file)
@@ -2928,6 +2928,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
                        <field name="record" reporter:datatype="link"/>
                        <field name="label" reporter:datatype="text"/>
                        <field name="label_sortkey" reporter:datatype="text"/>
+                       <field name="deleted" reporter:datatype="bool"/>
                </fields>
                <links>
                        <link field="record" reltype="has_a" key="id" map="" class="bre"/>
index 66ab824..a653e5d 100644 (file)
@@ -2030,7 +2030,7 @@ sub basic_opac_copy_query {
                 acpm => {
                     type => 'left',
                     join => {
-                        bmp => { type => 'left' }
+                        bmp => { type => 'left', filter => { deleted => 'f' } }
                     }
                 }
             }
index 22c0966..2f5f503 100644 (file)
@@ -2637,7 +2637,8 @@ sub rec_hold_parts {
                     },
                     distinct => 1,
                 }
-            }
+            },
+            deleted => 'f'
         },
         order_by =>[{class=>'bmp', field=>'label_sortkey'}]
     };
index 732dd9a..fde1a04 100644 (file)
@@ -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;
index 7f53b53..7252920 100644 (file)
@@ -3735,6 +3735,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;
@@ -3762,6 +3765,7 @@ sub as_xml {
     $xml .= "        <monograph_parts>\n";
     if (ref($self->obj->parts) && $self->obj->parts) {
         for my $part ( @{$self->obj->parts} ) {
+            next if $U->is_true($part->deleted);
             $xml .= sprintf('        <monograph_part record="%s" sortkey="%s">%s</monograph_part>',$part->record, $self->escape($part->label_sortkey), $self->escape($part->label));
             $xml .= "\n";
         }
index 4ce54ae..ff0542d 100644 (file)
@@ -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)
 );
 
index ee9886d..ab7aa35 100644 (file)
@@ -26,6 +26,13 @@ CREATE RULE protect_bib_rec_delete AS
             WHERE OLD.id = biblio.record_entry.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;
index 751ec12..886c778 100644 (file)
@@ -564,7 +564,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
@@ -945,7 +945,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 (file)
index 0000000..ada71d2
--- /dev/null
@@ -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;
+
index dfc89cc..c1f246a 100644 (file)
@@ -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')});
     });
 </script>
 [% END %]
index 0b16308..950488f 100644 (file)
@@ -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 );
 
         /***********************************************************************************************************/