[Koha-patches] [PATCH] (bug #4321) clean C4::Biblio::GetBiblio and uses

Nahuel ANGELINETTI nahuel.angelinetti at biblibre.com
Thu Mar 18 14:54:15 CET 2010


There is a file that musn't not be in the patch. I'll resend the patch.


Le 18/03/2010 14:28, Nahuel ANGELINETTI a écrit :
> This change the getbiblio function to be correctly coded, and change all places where it was used.
> ---
>   C4/Biblio.pm                        |   16 ++--
>   C4/ILSDI/Services.pm                |    6 +-
>   C4/ImportBatch.pm                   |    4 +-
>   C4/Serials.pm                       |    2 +-
>   catalogue/issuehistory.pl           |    4 +-
>   tools/batchedit.pl                  |  197 +++++++++++++++++++++++++++++++++++
>   virtualshelves/addbybiblionumber.pl |   12 +-
>   7 files changed, 219 insertions(+), 22 deletions(-)
>   create mode 100755 tools/batchedit.pl
>
> diff --git a/C4/Biblio.pm b/C4/Biblio.pm
> index ded50fc..49ba477 100755
> --- a/C4/Biblio.pm
> +++ b/C4/Biblio.pm
> @@ -894,15 +894,15 @@ sub GetBiblio {
>       my ($biblionumber) = @_;
>       my $dbh            = C4::Context->dbh;
>       my $sth            = $dbh->prepare("SELECT * FROM biblio WHERE biblionumber = ?");
> -    my $count          = 0;
> -    my @results;
> +
>       $sth->execute($biblionumber);
> -    while ( my $data = $sth->fetchrow_hashref ) {
> -        $results[$count] = $data;
> -        $count++;
> -    }    # while
> -    $sth->finish;
> -    return ( $count, @results );
> +
> +    if ( my $data = $sth->fetchrow_hashref ) {
> +        return $data;
> +    }else{
> +        return undef;
> +    }
> +
>   }    # sub GetBiblio
>
>   =head2 GetBiblioItemInfosOf
> diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm
> index bb32166..fd96826 100644
> --- a/C4/ILSDI/Services.pm
> +++ b/C4/ILSDI/Services.pm
> @@ -406,7 +406,7 @@ sub GetPatronInfo {
>               # Add additional fields
>               $reserve->{'item'}       = $item;
>               $reserve->{'branchname'} = $branchname;
> -            $reserve->{'title'}      = ( GetBiblio( $reserve->{'biblionumber'} ) )[1]->{'title'};
> +            $reserve->{'title'}      = GetBiblio( $reserve->{'biblionumber'} )->{'title'};
>           }
>           $borrower->{'holds'}->{'hold'} = \@reserves;
>       }
> @@ -605,7 +605,7 @@ sub HoldTitle {
>
>       # Get the biblio record, or return an error code
>       my $biblionumber = $cgi->param('bib_id');
> -    my ( $count, $biblio ) = GetBiblio($biblionumber);
> +    my $biblio = GetBiblio($biblionumber);
>       if ( not $biblio->{'biblionumber'} ) {
>           return { message =>  'RecordNotFound' };
>       }
> @@ -678,7 +678,7 @@ sub HoldItem {
>
>       # Get the biblio or return an error code
>       my $biblionumber = $cgi->param('bib_id');
> -    my ( $count, $biblio ) = GetBiblio($biblionumber);
> +    my $biblio = GetBiblio($biblionumber);
>       if ( not $biblio->{'biblionumber'} ) {
>           return { message =>  'RecordNotFound' };
>       }
> diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm
> index f8b5d54..e4dd3fe 100644
> --- a/C4/ImportBatch.pm
> +++ b/C4/ImportBatch.pm
> @@ -503,7 +503,7 @@ sub BatchCommitBibRecords {
>           } elsif ($bib_result eq 'replace') {
>               $num_updated++;
>               my $biblionumber = $bib_match;
> -            my ($count, $oldbiblio) = GetBiblio($biblionumber);
> +            my $oldbiblio = GetBiblio($biblionumber);
>               my $oldxml = GetXmlBiblio($biblionumber);
>
>               # remove item fields so that they don't get
> @@ -649,7 +649,7 @@ sub BatchRevertBibRecords {
>               $num_reverted++;
>               my $old_record = MARC::Record->new_from_xml(StripNonXmlChars($rowref->{'marcxml_old'}), 'UTF-8', $rowref->{'encoding'});
>               my $biblionumber = $rowref->{'matched_biblionumber'};
> -            my ($count, $oldbiblio) = GetBiblio($biblionumber);
> +            my $oldbiblio = GetBiblio($biblionumber);
>               $num_items_deleted += BatchRevertItems($rowref->{'import_record_id'}, $rowref->{'matched_biblionumber'});
>               ModBiblio($old_record, $biblionumber, $oldbiblio->{'frameworkcode'});
>               SetImportRecordStatus($rowref->{'import_record_id'}, 'reverted');
> diff --git a/C4/Serials.pm b/C4/Serials.pm
> index 439bd01..55dd8e0 100644
> --- a/C4/Serials.pm
> +++ b/C4/Serials.pm
> @@ -1393,7 +1393,7 @@ sub NewSubscription {
>       logaction( "SERIAL", "ADD", $subscriptionid, "" ) if C4::Context->preference("SubscriptionLog");
>
>       #set serial flag on biblio if not already set.
> -    my ( $null, ($bib) ) = GetBiblio($biblionumber);
> +    my $bib = GetBiblio($biblionumber);
>       if ( !$bib->{'serial'} ) {
>           my $record = GetMarcBiblio($biblionumber);
>           my ( $tag, $subf ) = GetMarcFromKohaField( 'biblio.serial', $bib->{'frameworkcode'} );
> diff --git a/catalogue/issuehistory.pl b/catalogue/issuehistory.pl
> index 8790bb5..1e1856f 100755
> --- a/catalogue/issuehistory.pl
> +++ b/catalogue/issuehistory.pl
> @@ -56,10 +56,10 @@ if ($itemnumber){
>   	);
>   } else {
>   	$issues = GetBiblioIssues($biblionumber);
> -	my (undef, at biblio)=GetBiblio($biblionumber);
> +	my $biblio = GetBiblio($biblionumber);
>   	my $total  = scalar @$issues;
>   	$template->param(
> -		%{$biblio[0]},
> +		%{$biblio},
>   	);
>   }
>   foreach (@$issues){
> diff --git a/tools/batchedit.pl b/tools/batchedit.pl
> new file mode 100755
> index 0000000..d74c9cb
> --- /dev/null
> +++ b/tools/batchedit.pl
> @@ -0,0 +1,197 @@
> +#!/usr/bin/perl
> +
> +
> +# Copyright 2010 SARL BibLibre
> +#
> +# This file is part of Koha.
> +#
> +# Koha is free software; you can redistribute it and/or modify it under the
> +# terms of the GNU General Public License as published by the Free Software
> +# Foundation; either version 2 of the License, or (at your option) any later
> +# version.
> +#
> +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
> +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
> +# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License along with
> +# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
> +# Suite 330, Boston, MA  02111-1307 USA
> +
> +use CGI;
> +use strict;
> +use C4::Output;
> +use C4::Auth;
> +use C4::Branch;
> +use C4::Koha;
> +use C4::Biblio;
> +use C4::Context;
> +use C4::Debug;
> +use JSON;
> +
> +my $input = new CGI;
> +my $dbh = C4::Context->dbh;
> +
> +my @biblionumbers = split('/', $input->param('bib_list'));
> +my $op            = $input->param('op');
> +
> +my $frameworkcode="";
> +my $tagslib =&GetMarcStructure(1,$frameworkcode);
> +
> +
> +if($input->param('field') and not defined $op){
> +    my ($template, $loggedinuser, $cookie)
> +        = get_template_and_user({template_name =>  "acqui/ajax.tmpl",
> +                 query =>  $input,
> +                 type =>  "intranet",
> +                 authnotrequired =>  0,
> +                 flagsrequired =>  "batchedit",
> +        });
> +
> +
> +    my $tag      = $input->param('field');
> +    my $subfield = $input->param('subfield');
> +
> +    if($input->param('subfield')){
> +        my $branches = GetBranchesLoop();
> +
> +        my @authorised_values;
> +        if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
> +             if ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "branches" ) {
> +                foreach my $thisbranch (@$branches) {
> +                    push @authorised_values, {
> +                            code =>  $thisbranch->{value},
> +                            value =>  $thisbranch->{branchname},
> +                        };
> +                    # $value = $thisbranch->{value} if $thisbranch->{selected};
> +                }
> +             }elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) {
> +                 my $sth = $dbh->prepare("SELECT itemtype,description FROM itemtypes ORDER BY description");
> +                 $sth->execute();
> +                 while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) {
> +                    push @authorised_values, {
> +                        code =>  $itemtype,
> +                        value =>  $description,
> +                    };
> +                 }
> +
> +            }else {
> +                  # Getting the fields where the item location is
> +                  my ($location_field, $location_subfield) = GetMarcFromKohaField('items.location', $frameworkcode);
> +
> +                  # Getting the name of the authorised values' category for item location
> +                  my $item_location_category = $tagslib->{$location_field}->{$location_subfield}->{'authorised_value'};
> +        	      # Are we dealing with item location ?
> +                  my $item_location = ($tagslib->{$tag}->{$subfield}->{authorised_value} eq $item_location_category) ? 1 : 0;
> +
> +                  # If so, we sort by authorised_value, else by libelle
> +                  my $orderby = $item_location ? 'authorised_value' : 'lib';
> +
> +                  my $authorised_values_sth = $dbh->prepare("SELECT authorised_value,lib FROM authorised_values WHERE category=? ORDER BY $orderby");
> +
> +                  $authorised_values_sth->execute( $tagslib->{$tag}->{$subfield}->{authorised_value});
> +
> +
> +                  while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
> +                    push @authorised_values, {
> +                        code =>  $value,
> +                        value =>  ($item_location) ? $value . " - " . $lib : $lib,
> +                    };
> +        	      	
> +                  }
> +            }
> +        }
> +      $template->param('return' =>  to_json(\@authorised_values));
> +    }else{
> +        my @modifiablesubf;
> +
> +        foreach my $subfield (sort keys %{$tagslib->{$tag}}) {
> +            next if subfield_is_koha_internal_p($subfield);
> +            next if ($tagslib->{$tag}->{$subfield}->{'tab'} eq "10");
> +            my %subfield_data;
> +            $subfield_data{subfield} = $subfield;
> +            push @modifiablesubf, \%subfield_data;
> +        }
> +        $template->param('return' =>  to_json(\@modifiablesubf));
> +    }
> +
> +
> +    output_html_with_http_headers $input, $cookie, $template->output;
> +    exit;
> +}
> +elsif(!defined $op) {
> +    my ($template, $loggedinuser, $cookie)
> +        = get_template_and_user({template_name =>  "tools/batchedit.tmpl",
> +                 query =>  $input,
> +                 type =>  "intranet",
> +                 authnotrequired =>  0,
> +                 flagsrequired =>  "batchedit",
> +                 });
> +
> +    my @modifiablefields;
> +    my @biblioinfos;
> +
> +    for my $biblionumber (@biblionumbers){
> +        my $biblio = GetBiblio($biblionumber);
> +        push @biblioinfos, $biblio;
> +    }
> +
> +    foreach my $tag (sort keys %{$tagslib}) {
> +        my %subfield_data;
> +        foreach my $subfield (sort keys %{$tagslib->{$tag}}) {
> +            next if $subfield_data{tag};
> +            next if subfield_is_koha_internal_p($subfield);
> +            next if ($tagslib->{$tag}->{$subfield}->{'tab'} eq "10");
> +
> +            $subfield_data{tag}      = $tag;
> +
> +            push @modifiablefields, \%subfield_data;
> +        }
> +    }
> +
> +    $template->param( marcfields =>  \@modifiablefields,
> +                      bib_list =>  $input->param('bib_list')
> +                     );
> +    output_html_with_http_headers $input, $cookie, $template->output;
> +    exit;
> +
> +}else{
> +    my ($template, $loggedinuser, $cookie)
> +        = get_template_and_user({template_name =>  "tools/batchedit.tmpl",
> +                 query =>  $input,
> +                 type =>  "intranet",
> +                 authnotrequired =>  0,
> +                 flagsrequired =>  "batchedit",
> +                 });
> +    my @fields    = $input->param('field');
> +    my @subfields = $input->param('subfield');
> +    my @actions   = $input->param('action');
> +    my @condvals   = $input->param('condval');
> +    my @repvals    = $input->param('repval');
> +
> +    foreach my $biblionumber ( @biblionumbers ){
> +        my $record = GetMarcBiblio($biblionumber);
> +        for(my $i = 0 ; $i<  scalar(@fields) ; $i++ ){
> +            my $field    = $fields[$i];
> +            my $subfield = $subfields[$i];
> +            my $action   = $actions[$i];
> +            my $condval  = $condvals[$i];
> +            my $repval   = $repvals[$i];
> +
> +            if($record->field($field)){
> +                foreach my $rfield( $record->field($field) ){
> +                    if($rfield->subfield($subfield)){
> +                        BatchModField($rfield, $subfield, $action, $condval, $repval);
> +                    }
> +                }
> +            }
> +        }
> +    }
> +
> +    $template->param('modsuccess' =>  1);
> +
> +    output_html_with_http_headers $input, $cookie, $template->output;
> +    exit;
> +
> +}
> +
> diff --git a/virtualshelves/addbybiblionumber.pl b/virtualshelves/addbybiblionumber.pl
> index 8b8a6ca..9aaaa03 100755
> --- a/virtualshelves/addbybiblionumber.pl
> +++ b/virtualshelves/addbybiblionumber.pl
> @@ -198,21 +198,21 @@ else {    # this shelf doesn't already exist.
>       );
>
>       unless (@biblionumbers) {
> -        my ( $bibliocount, @biblios ) = GetBiblio($biblionumber);
> +        my $biblio = GetBiblio($biblionumber);
>
>           $template->param
>             (
>              biblionumber      =>  $biblionumber,
> -           title             =>  $biblios[0]->{'title'},
> -           author            =>  $biblios[0]->{'author'},
> +           title             =>  $biblio->{'title'},
> +           author            =>  $biblio->{'author'},
>             );
>       } else {
>           my @biblioloop = ();
>           foreach my $biblionumber (@biblionumbers) {
> -            my ( $bibliocount, @biblios ) = GetBiblio($biblionumber);
> +            my $biblio = GetBiblio($biblionumber);
>               my %biblioiter = (
> -                              title=>$biblios[0]->{'title'},
> -                              author=>$biblios[0]->{'author'}
> +                              title =>$biblio->{'title'},
> +                              author=>$biblio->{'author'}
>                                );
>               push @biblioloop, \%biblioiter;
>           }
>    


-- 
Nahuel ANGELINETTI




More information about the Koha-patches mailing list