From 231415e5be425546eafec11c7c004dd9cffb5e8a Mon Sep 17 00:00:00 2001 From: Henri-Damien LAURENT Date: Tue, 9 Oct 2007 16:46:43 -0500 Subject: [PATCH] BugFix in MARCdetail.pl : getauthorisedvaluedesc contained itemtype. + Rewriting ModBiblios (now can take in itemnumbers or biblionumbers + allow modification for tags <010) Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Search.pm | 162 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 98 insertions(+), 64 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 1c508c6482..02a4438612 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -54,7 +54,7 @@ This module provides the searching facilities for the Koha into a zebra catalog. &getRecords &buildQuery &NZgetRecords - &EditBiblios + &ModBiblios ); # make all your functions, whether exported or not; @@ -1056,69 +1056,6 @@ sub searchResults { } -=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 - - * $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 - * $countchanged counts all the changes performed. - * $listunchanged contains the list of all the biblionumbers of records unchanged. - -=item C - -=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})(.)$/); - my ($bntag,$bnsubf) = GetMarcFromKohaField('biblio.biblionumber'); - - foreach my $usmarc (@$listbiblios){ - my $record=MARC::Record->new_from_usmarc($usmarc); - my $biblionumber; - if ($bntag>10){ - $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)){ - foreach my $field ($record->field($tag)){ - if ($field->delete_subfield('code' =>$subfield,'match'=>qr($initvalue))){ - $countmatched++; - $field->update($subfield,$targetvalue) if ($targetvalue); - } - } -# warn $record->as_formatted; - ModBiblio($record,$biblionumber,GetFrameworkCode($biblionumber)) unless ($test); - } else { - push @unmatched, $biblionumber; - } - } - return ($countmatched,\@unmatched); -} #---------------------------------------------------------------------- # @@ -1522,6 +1459,103 @@ sub NZorder { return $finalresult; } } +=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 + + * $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 + * $countchanged counts all the changes performed. + * $listunchanged contains the list of all the biblionumbers of records unchanged. + +=item C + +=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'); + 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 + if ($tag eq $itemtag){ + my $bib=GetBiblioFromItemNumber($usmarc); + $record=GetMarcItem($bib->{'biblionumber'},$usmarc) ; + $biblionumber=$bib->{'biblionumber'}; + } else { + $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) -- 2.39.5