From 0456e457dc023686d7876b1b71db567b96d10dcb Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Tue, 25 Dec 2007 01:26:02 -0600 Subject: [PATCH] IMPORTANT - replaced TransformMarcToKoha Replaced with FasterTransformMarcToKoha from a previous commit. Main differences are: [1] At least twice as fast because of improvement in algorithm for processing the MARC record -- each tag is processed only once. [2] Fixed bug where biblio.notes would end up with an extra ' | ' at the end. Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Biblio.pm | 89 ++++------------------------------------------------ 1 file changed, 6 insertions(+), 83 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index a6bd9df478..3a8383af72 100755 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -285,7 +285,7 @@ sub AddBiblioAndItems { # transform the data into koha-table style data # FIXME - this paragraph copied from AddBiblio - my $olddata = FasterTransformMarcToKoha( $dbh, $record, $frameworkcode ); + my $olddata = TransformMarcToKoha( $dbh, $record, $frameworkcode ); ($biblionumber,$error) = _koha_add_biblio( $dbh, $olddata, $frameworkcode ); $olddata->{'biblionumber'} = $biblionumber; ($biblioitemnumber,$error) = _koha_add_biblioitem( $dbh, $olddata ); @@ -307,7 +307,7 @@ sub AddBiblioAndItems { $temp_item_marc->append_fields($item_field); # add biblionumber and biblioitemnumber - my $item = &FasterTransformMarcToKoha( $dbh, $temp_item_marc, $frameworkcode, 'items' ); + my $item = TransformMarcToKoha( $dbh, $temp_item_marc, $frameworkcode, 'items' ); $item->{'biblionumber'} = $biblionumber; $item->{'biblioitemnumber'} = $biblioitemnumber; @@ -2696,99 +2696,22 @@ sub TransformHtmlToMarc { return $record; } -=head2 TransformMarcToKoha - -=over 4 - - $result = TransformMarcToKoha( $dbh, $record, $frameworkcode ) - -=back - -=cut - -sub TransformMarcToKoha { - my ( $dbh, $record, $frameworkcode, $table ) = @_; - - my $result; - - # sometimes we only want to return the items data - if ($table eq 'items') { - my $sth = $dbh->prepare("SHOW COLUMNS FROM items"); - $sth->execute(); - while ( (my $field) = $sth->fetchrow ) { - my $value = get_koha_field_from_marc($table,$field,$record,$frameworkcode); - my $key = _disambiguate($table, $field); - if ($result->{$key}) { - $result->{$key} .= " | " . $value; - } else { - $result->{$key} = $value; - } - } - return $result; - } else { - my @tables = ('biblio','biblioitems','items'); - foreach my $table (@tables){ - my $sth2 = $dbh->prepare("SHOW COLUMNS from $table"); - $sth2->execute; - while (my ($field) = $sth2->fetchrow){ - # FIXME use of _disambiguate is a temporary hack - # $result->{_disambiguate($table, $field)} = get_koha_field_from_marc($table,$field,$record,$frameworkcode); - my $value = get_koha_field_from_marc($table,$field,$record,$frameworkcode); - my $key = _disambiguate($table, $field); - if ($result->{$key}) { - # FIXME - hack to not bring in duplicates of the same value - unless (($key eq "biblionumber" or $key eq "biblioitemnumber") and ($value eq "")) { - $result->{$key} .= " | " . $value; - } - } else { - $result->{$key} = $value; - } - } - $sth2->finish(); - } - # modify copyrightdate to keep only the 1st year found - my $temp = $result->{'copyrightdate'}; - $temp =~ m/c(\d\d\d\d)/; # search cYYYY first - if ( $1 > 0 ) { - $result->{'copyrightdate'} = $1; - } - else { # if no cYYYY, get the 1st date. - $temp =~ m/(\d\d\d\d)/; - $result->{'copyrightdate'} = $1; - } - - # modify publicationyear to keep only the 1st year found - $temp = $result->{'publicationyear'}; - $temp =~ m/c(\d\d\d\d)/; # search cYYYY first - if ( $1 > 0 ) { - $result->{'publicationyear'} = $1; - } - else { # if no cYYYY, get the 1st date. - $temp =~ m/(\d\d\d\d)/; - $result->{'publicationyear'} = $1; - } - return $result; - } -} - - # cache inverted MARC field map our $inverted_field_map; -=head2 FasterTransformMarcToKoha +=head2 TransformMarcToKoha =over 4 - $result = FasterTransformMarcToKoha( $dbh, $record, $frameworkcode ) + $result = TransformMarcToKoha( $dbh, $record, $frameworkcode ) =back Extract data from a MARC bib record into a hashref representing -Koha biblio, biblioitems, and items fields. This function will -replace TransformMarcToKoha once it has been tested. +Koha biblio, biblioitems, and items fields. =cut -sub FasterTransformMarcToKoha { +sub TransformMarcToKoha { my ( $dbh, $record, $frameworkcode, $limit_table ) = @_; my $result; -- 2.39.5