Commiting necessary subs for bulkedition.

This commit is contained in:
hdl 2007-04-30 14:29:21 +00:00
parent be61c6558d
commit ae56dd4f03
2 changed files with 100 additions and 1 deletions

View file

@ -75,6 +75,8 @@ Koha.pm provides many functions for Koha scripts.
&GetAuthorisedValues
&FixEncoding
&GetKohaAuthorisedValues
&GetManagedTagSubfields
$DEBUG
);
@ -1184,6 +1186,39 @@ sub GetKohaAuthorisedValues {
return \%values;
}
=head2 GetManagedTagSubfields
=over 4
$res = GetManagedTagSubfields();
Returns a reference to a big hash of hash, with the Marc structure fro the given frameworkcode
$forlibrarian :if set to 1, the MARC descriptions are the librarians ones, otherwise it's the public (OPAC) ones
$frameworkcode : the framework code to read
=back
=back
=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
ORDER BY tagsubfield|);
$rq->execute;
my $data=$rq->fetchall_arrayref({});
return $data;
}
1;

View file

@ -54,6 +54,7 @@ This module provides the searching facilities for the Koha into a zebra catalog.
&getRecords
&buildQuery
&NZgetRecords
&EditBiblios
);
# make all your functions, whether exported or not;
@ -831,7 +832,7 @@ sub searchResults {
my %subfieldstosearch;
while ( ( my $column ) = $sth2->fetchrow ) {
my ( $tagfield, $tagsubfield ) =
&GetMarcFromKohaField( $dbh, "items." . $column, "" );
&GetMarcFromKohaField( "items." . $column, "" );
$subfieldstosearch{$column} = $tagsubfield;
}
my $times;
@ -1046,6 +1047,69 @@ sub searchResults {
}
=head2 EditBiblios
($countchanged,$listunchanged) = EditBiblios($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 EditBiblios{
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);
}
#----------------------------------------------------------------------
#
# Non-Zebra GetRecords#