From b7c35853f265d9f03d653789d91524dd030b8ade Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 3 Jan 2008 12:36:18 -0600 Subject: [PATCH 1/1] item rework: do not allow bulkedit to update items This patch is meant to guarantee that a bulkedit does not try to edit an item tag embedded in a MARC biblio without updating the items feature. It is not a comprehensive fix of the bulkedit feature, which currently does not appear to be functional and needs some thought: * The general search results is probably not the best place to put this feature -- it should probably be in tools. * A bulk edit of something like items is desireable, but needs to be designed so that it respects business logic for circulation and acquisitions. Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Koha.pm | 19 ++++++++++++++----- C4/Search.pm | 23 ++++++++++++++--------- catalogue/search.pl | 8 +++++++- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index 52146e5834..6c6b6e0443 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -918,13 +918,18 @@ sub GetKohaAuthorisedValues { $res = GetManagedTagSubfields(); +=back + Returns a reference to a big hash of hash, with the Marc structure fro the given frameworkcode -$forlibrarian :if set to 1, the MARC descriptions are the librarians ones, otherwise it's the public (OPAC) ones -$frameworkcode : the framework code to read -=back +NOTE: This function is used only by the (incomplete) bulk editing feature. Since +that feature currently does not deal with items and biblioitems changes +correctly, those tags are specifically excluded from the list prepared +by this function. -=back +For future reference, if a bulk item editing feature is implemented at some point, it +needs some design thought -- for example, circulation status fields should not +be changed willy-nilly. =cut @@ -940,7 +945,11 @@ FROM marc_subfield_structure ON marc_tag_structure.tagfield = marc_subfield_structure.tagfield AND marc_tag_structure.frameworkcode = marc_subfield_structure.frameworkcode WHERE marc_subfield_structure.tab>=0 -ORDER BY tagsubfield|); +AND marc_tag_structure.tagfield NOT IN (SELECT tagfield FROM marc_subfield_structure WHERE kohafield like 'items.%') +AND marc_tag_structure.tagfield NOT IN (SELECT tagfield FROM marc_subfield_structure WHERE kohafield = 'biblioitems.itemtype') +AND marc_subfield_structure.kohafield <> 'biblio.biblionumber' +AND marc_subfield_structure.kohafield <> 'biblioitems.biblioitemnumber' +ORDER BY marc_subfield_structure.tagfield, tagsubfield|); $rq->execute; my $data=$rq->fetchall_arrayref({}); return $data; diff --git a/C4/Search.pm b/C4/Search.pm index 232fa42ea5..fc3c802a08 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -2089,6 +2089,12 @@ sub ModBiblios { } my ( $bntag, $bnsubf ) = GetMarcFromKohaField('biblio.biblionumber'); my ( $itemtag, $itemsubf ) = GetMarcFromKohaField('items.itemnumber'); + if ($tag eq $itemtag) { + # do not allow the embedded item tag to be + # edited from here + warn "Attempting to edit item tag via C4::Search::ModBiblios -- not allowed"; + return (0, []); + } foreach my $usmarc (@$listbiblios) { my $record; $record = eval { MARC::Record->new_from_usmarc($usmarc) }; @@ -2096,15 +2102,14 @@ sub ModBiblios { if ($@) { # usmarc is not a valid usmarc May be a biblionumber - if ( $tag eq $itemtag ) { - my $bib = GetBiblioFromItemNumber($usmarc); - $record = GetMarcItem( $bib->{'biblionumber'}, $usmarc ); - $biblionumber = $bib->{'biblionumber'}; - } - else { - $record = GetMarcBiblio($usmarc); - $biblionumber = $usmarc; - } + # FIXME - sorry, please let's figure out whether + # this function is to be passed a list of + # record numbers or a list of MARC::Record + # objects. The former is probably better + # because the MARC records supplied by Zebra + # may be not current. + $record = GetMarcBiblio($usmarc); + $biblionumber = $usmarc; } else { if ( $bntag >= 010 ) { diff --git a/catalogue/search.pl b/catalogue/search.pl index 8f66087a4e..16dbbaafb2 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -471,8 +471,14 @@ if ($op eq "bulkedit"){ if (C4::Context->userenv->{'flags'}==1 ||(C4::Context->userenv->{'flags'} & ( 2**9 ) )){ #Edit Catalogue Permissions + my $editable_subfields = GetManagedTagSubfields(); + # change '--' to '—' to avoid escaping issues + for (my $i = 0; $i <= $#{$editable_subfields}; $i++) { + $editable_subfields->[$i]->{subfielddesc} =~ s/--/—/g; + $editable_subfields->[$i]->{tagdesc} =~ s/--/—/g; + } $template->param(bulkedit => 1); - $template->param(tagsubfields=>GetManagedTagSubfields()); + $template->param(tagsubfields=>$editable_subfields); } } -- 2.11.0