[Koha-patches] [PATCH] bug_5473: add 952 fields when receiving an order

LAURENT Henri-Damien henridamien.laurent at biblibre.com
Wed Sep 7 10:52:46 CEST 2011


Hi
In my opinion, append_fields should not be used that much.
use insert_fields_ordered or insert_fields_before
rather than append_fields...
Why ?
Because usually, what you want is tags to be grouped and not dispatched
in the biblio. And append_fields will append them at the end of the
record. If the record is too long, then it will simply fail to index
that part. (when 999 tag/subfields which stores the biblionumber, you
would certainly have indexing problems on big records.)


Le 07/09/2011 10:32, Srdjan Jankovic a écrit :
> ---
>  C4/Biblio.pm           |   42 ++++++++++++++++++++++++++++++++++++++++++
>  acqui/finishreceive.pl |    9 +++++++++
>  2 files changed, 51 insertions(+), 0 deletions(-)
> 
> diff --git a/C4/Biblio.pm b/C4/Biblio.pm
> index 96baaef..c483fd0 100644
> --- a/C4/Biblio.pm
> +++ b/C4/Biblio.pm
> @@ -99,6 +99,7 @@ BEGIN {
>        &ModBiblio
>        &ModBiblioframework
>        &ModZebra
> +      &AddMarcFields
>      );
>  
>      # To delete something
> @@ -3681,6 +3682,47 @@ sub get_biblio_authorised_values {
>      return $authorised_values;
>  }
>  
> +=head2 AddMarcFields
> +
> +Adds fields to existing marcxml
> +
> +parameters:
> +    biblionumber
> +    fields
> +
> +returns: nothing
> +
> +  $fields: { tag1 => val1, tag2 => val2, ... }
> +  $valX  : $val for tags < 10, { subfild1 => subval1, subfild2 => subval2, ... }
> +
> +Notes: no indicator support
> +
> +=cut
> +
> +sub AddMarcFields {
> +    my ( $biblionumber, $fields ) = @_;
> +
> +    my $rec = GetMarcBiblio($biblionumber) or die "Invalid biblionumber $biblionumber";
> +
> +    my @fields;
> +    while ( my ($tag, $val) = each %$fields ) {
> +        my $newfield;
> +        if (ref $val) {
> +            $newfield = MARC::Field->new( $tag, '', '', %$val );
> +        } else {
> +            $newfield = MARC::Field->new( $tag, $val );
> +        }
> +        push @fields, $newfield;
> +    }
> +    $rec->append_fields(@fields);
> +
> +    my $dbh    = C4::Context->dbh;
> +    my $encoding = C4::Context->preference("marcflavour");
> +    $dbh->do("UPDATE biblioitems SET marcxml=? WHERE biblionumber=?", undef,
> +        $rec->as_xml_record($encoding),
> +        $biblionumber );
> +}
> +
>  1;
>  
>  __END__
> diff --git a/acqui/finishreceive.pl b/acqui/finishreceive.pl
> index 71b13d6..8d14478 100755
> --- a/acqui/finishreceive.pl
> +++ b/acqui/finishreceive.pl
> @@ -114,4 +114,13 @@ if ($quantityrec > $origquantityrec ) {
>      	$datereceived = ModReceiveOrder($biblionumber,$ordernumber, $quantityrec ,$user,$unitprice,$invoiceno,$freight,$replacement,undef,$datereceived);
>  	}
>  }
> +
> +AddMarcFields( $biblionumber, { 952 => { e => $supplierid,
> +                                         d => $datereceived,
> +                                         g => $unitprice,
> +                                         v => $replacement,
> +                                     },
> +                                 } );
> +# XXX                                    w => Price effective from
> +
>      print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoice=$invoiceno&supplierid=$supplierid&freight=$freight&gst=$gst&datereceived=$datereceived$error_url_str");



More information about the Koha-patches mailing list