item rework: do not allow bulkedit to update items
authorGalen Charlton <galen.charlton@liblime.com>
Thu, 3 Jan 2008 18:36:18 +0000 (12:36 -0600)
committerJoshua Ferraro <jmf@liblime.com>
Thu, 3 Jan 2008 22:23:47 +0000 (16:23 -0600)
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 <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Koha.pm
C4/Search.pm
catalogue/search.pl

index 52146e5..6c6b6e0 100644 (file)
@@ -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;
index 232fa42..fc3c802 100644 (file)
@@ -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 ) {
index 8f66087..16dbbaa 100755 (executable)
@@ -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 '&mdash;' to avoid escaping issues
+        for (my $i = 0; $i <= $#{$editable_subfields}; $i++) {
+            $editable_subfields->[$i]->{subfielddesc} =~ s/--/&mdash;/g;
+            $editable_subfields->[$i]->{tagdesc} =~ s/--/&mdash;/g;
+        }
         $template->param(bulkedit => 1);
-        $template->param(tagsubfields=>GetManagedTagSubfields());
+        $template->param(tagsubfields=>$editable_subfields);
     }
 }