[Koha-patches] [PATCH] remove incomplete bib bulk editing code

Galen Charlton galen.charlton at liblime.com
Mon Apr 6 16:45:56 CEST 2009


Per discussion I had with Henri, removing experimental
bulk editing from the staff search results code, as
feature is incomplete and can be dangerous if
one tries to use it on a large search result
set.
---
 C4/Koha.pm                                         |   44 -------
 C4/Search.pm                                       |  125 --------------------
 catalogue/search.pl                                |   31 -----
 .../prog/en/modules/catalogue/results.tmpl         |   31 -----
 t/lib/KohaTest/Koha.pm                             |    1 -
 t/lib/KohaTest/Search.pm                           |    1 -
 6 files changed, 0 insertions(+), 233 deletions(-)

diff --git a/C4/Koha.pm b/C4/Koha.pm
index 9c37020..418b815 100644
--- a/C4/Koha.pm
+++ b/C4/Koha.pm
@@ -52,7 +52,6 @@ BEGIN {
 		&GetAuthorisedValueCategories
 		&GetKohaAuthorisedValues
 		&GetAuthValCode
-		&GetManagedTagSubfields
 		&GetNormalizedUPC
 		&GetNormalizedISBN
 		&GetNormalizedEAN
@@ -1069,49 +1068,6 @@ sub GetKohaAuthorisedValues {
   }
 }
 
-=head2 GetManagedTagSubfields
-
-=over 4
-
-$res = GetManagedTagSubfields();
-
-=back
-
-Returns a reference to a big hash of hash, with the Marc structure fro the given frameworkcode
-
-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.
-
-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
-
-sub GetManagedTagSubfields{
-  my $dbh=C4::Context->dbh;
-  my $rq=$dbh->prepare(qq|
-SELECT 
-  DISTINCT CONCAT( marc_subfield_structure.tagfield, tagsubfield ) AS tagsubfield, 
-  marc_subfield_structure.liblibrarian as subfielddesc, 
-  marc_tag_structure.liblibrarian as tagdesc
-FROM marc_subfield_structure
-  LEFT JOIN marc_tag_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
-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;
-}
-
 =head2 display_marc_indicators
 
 =over 4
diff --git a/C4/Search.pm b/C4/Search.pm
index 571edf7..59d0a08 100644
--- a/C4/Search.pm
+++ b/C4/Search.pm
@@ -61,7 +61,6 @@ This module provides searching functions for Koha's bibliographic databases
   &getRecords
   &buildQuery
   &NZgetRecords
-  &ModBiblios
 );
 
 # make all your functions, whether exported or not;
@@ -2139,130 +2138,6 @@ sub NZorder {
     }
 }
 
-=head2 ModBiblios
-
-($countchanged,$listunchanged) = ModBiblios($listbiblios, $tagsubfield,$initvalue,$targetvalue,$test);
-
-this function changes all the values $initvalue in subfield $tag$subfield in any record in $listbiblios
-test parameter if set donot perform change to records in database.
-
-=over 2
-
-=item C<input arg:>
-
-    * $listbiblios is an array ref to marcrecords to be changed
-    * $tagsubfield is the reference of the subfield to change.
-    * $initvalue is the value to search the record for
-    * $targetvalue is the value to set the subfield to
-    * $test is to be set only not to perform changes in database.
-
-=item C<Output arg:>
-    * $countchanged counts all the changes performed.
-    * $listunchanged contains the list of all the biblionumbers of records unchanged.
-
-=item C<usage in the script:>
-
-=back
-
-my ($countchanged, $listunchanged) = EditBiblios($results->{RECORD}, $tagsubfield,$initvalue,$targetvalue);;
-#If one wants to display unchanged records, you should get biblios foreach @$listunchanged 
-$template->param(countchanged => $countchanged, loopunchanged=>$listunchanged);
-
-=cut
-
-sub ModBiblios {
-    my ( $listbiblios, $tagsubfield, $initvalue, $targetvalue, $test ) = @_;
-    my $countmatched;
-    my @unmatched;
-    my ( $tag, $subfield ) = ( $1, $2 )
-      if ( $tagsubfield =~ /^(\d{1,3})([a-z0-9A-Z@])?$/ );
-    if ( ( length($tag) < 3 ) && $subfield =~ /0-9/ ) {
-        $tag = $tag . $subfield;
-        undef $subfield;
-    }
-    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) };
-        my $biblionumber;
-        if ($@) {
-
-            # usmarc is not a valid usmarc May be a biblionumber
-            # 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 ) {
-                $biblionumber = $record->subfield( $bntag, $bnsubf );
-            }
-            else {
-                $biblionumber = $record->field($bntag)->data;
-            }
-        }
-
-        #GetBiblionumber is to be written.
-        #Could be replaced by TransformMarcToKoha (But Would be longer)
-        if ( $record->field($tag) ) {
-            my $modify = 0;
-            foreach my $field ( $record->field($tag) ) {
-                if ($subfield) {
-                    if (
-                        $field->delete_subfield(
-                            'code'  => $subfield,
-                            'match' => qr($initvalue)
-                        )
-                      )
-                    {
-                        $countmatched++;
-                        $modify = 1;
-                        $field->update( $subfield, $targetvalue )
-                          if ($targetvalue);
-                    }
-                }
-                else {
-                    if ( $tag >= 010 ) {
-                        if ( $field->delete_field($field) ) {
-                            $countmatched++;
-                            $modify = 1;
-                        }
-                    }
-                    else {
-                        $field->data = $targetvalue
-                          if ( $field->data =~ qr($initvalue) );
-                    }
-                }
-            }
-
-            #       warn $record->as_formatted;
-            if ($modify) {
-                ModBiblio( $record, $biblionumber,
-                    GetFrameworkCode($biblionumber) )
-                  unless ($test);
-            }
-            else {
-                push @unmatched, $biblionumber;
-            }
-        }
-        else {
-            push @unmatched, $biblionumber;
-        }
-    }
-    return ( $countmatched, \@unmatched );
-}
-
 END { }    # module clean-up code here (global destructor)
 
 1;
diff --git a/catalogue/search.pl b/catalogue/search.pl
index 902318a..a5beb6d 100755
--- a/catalogue/search.pl
+++ b/catalogue/search.pl
@@ -481,37 +481,6 @@ if ($@ || $error) {
     exit;
 }
 
-# FIXME: This belongs in tools/ not in the primary search results page
-my $op=$cgi->param("operation");
-if ($op eq "bulkedit"){
-    my ($countchanged,$listunchanged)=
-    ModBiblios($results_hashref->{'biblioserver'}->{"RECORDS"},
-                      $params->{"tagsubfield"},
-                      $params->{"inputvalue"},
-                      $params->{"targetvalue"},
-                      $params->{"test"}
-                      );
-    $template->param(bulkeditresults=>1,
-                      tagsubfield=>$params->{"tagsubfield"},
-                      inputvalue=>$params->{"inputvalue"},
-                      targetvalue=>$params->{"targetvalue"},
-                      countchanged=>$countchanged,
-                      countunchanged=>scalar(@$listunchanged),
-                      listunchanged=>$listunchanged);
-
-    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=>$editable_subfields);
-    }
-}
-
 # At this point, each server has given us a result set
 # now we build that set for template display
 my @sup_results_array;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl
index 5acb105..abaf52e 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl
@@ -194,37 +194,6 @@ $(window).load(function() {
                 <!-- /TMPL_IF -->
                 <!-- FACETS END -->
                 <!-- /TMPL_IF --> <!-- NoZebra -->
-                <!-- BULKEDIT START -->
-                <!--TMPL_IF Name="bulkedit"--> 
-                    <dt id="hbulkedit" onclick="var Elt=document.getElementById('parambulkedit');if (Elt.style.display!='block'){Elt.style.display='block';} else {Elt.style.display='none';}">
-                    Bulk edit
-                    </dt>
-                    <dd id="parambulkedit" style="display:none;">
-                    <form name="bulkedit" action="search.pl">
-                        <input type="hidden" name="q" value="<!-- TMPL_VAR NAME="searchdesc" -->" />
-                        <input type="hidden" name="operation" value="bulkedit" />
-                        Search for Value :<input type="text" name="inputvalue" value="" /><br />
-                        Subfield       <select name="tagsubfield">
-                        <!--TMPL_LOOP Name="tagsubfields"-->
-                            <option value="<!--TMPL_VAR Name="tagsubfield"-->"> <!--TMPL_VAR Name="tagsubfield"-->
-                            <!-- --<TMPL_VAR Name="tagdesc">--<TMPL_VAR Name="subfielddesc">-->
-                            </option>
-                        <!--/TMPL_LOOP -->
-                        </select><br />
-                        Change to : <input type="text" name="targetvalue" value="" /><br />
-                        Test only : <input type="checkbox" name="test" value="1" /><br />
-                        <input type="Submit" name="Edit" value="Edit" />
-                    </form>
-                    </dd>
-                    <!-- TMPL_IF NAME="bulkeditresults" -->
-                    <dd>
-                        tagsubfield : <!-- TMPL_VAR NAME="countchanged" --> Change <!-- TMPL_VAR NAME="countchanged" --> To <!-- TMPL_VAR NAME="countchanged" --><br />
-                        <!-- TMPL_VAR NAME="countchanged" --> biblios changed <br />
-                        <!--TMPL_VAR Name="countunchanged"--> biblios unchanged<br />
-                    </dd>
-                    <!-- /TMPL_IF -->
-                <!--/TMPL_IF--> 
-                <!-- BULKEDIT END -->
                 </dl>
             </div>
             <!-- ######### -->
diff --git a/t/lib/KohaTest/Koha.pm b/t/lib/KohaTest/Koha.pm
index c1773d9..b1774a2 100644
--- a/t/lib/KohaTest/Koha.pm
+++ b/t/lib/KohaTest/Koha.pm
@@ -41,7 +41,6 @@ sub methods : Test( 1 ) {
       GetAuthorisedValues
       GetAuthorisedValueCategories
       GetKohaAuthorisedValues
-      GetManagedTagSubfields
       display_marc_indicators
     );
 
diff --git a/t/lib/KohaTest/Search.pm b/t/lib/KohaTest/Search.pm
index 44d7885..ef27acd 100644
--- a/t/lib/KohaTest/Search.pm
+++ b/t/lib/KohaTest/Search.pm
@@ -29,7 +29,6 @@ sub methods : Test( 1 ) {
                       NZoperatorOR
                       NZoperatorNOT
                       NZorder
-                      ModBiblios
                 );
     
     can_ok( $self->testing_class, @methods );    
-- 
1.5.6.5




More information about the Koha-patches mailing list