Koha/misc/migration_tools/upgradeitems.pl
Mark Tompsett d5986c9b97 Bug 19040: Refactor GetMarcBiblio parameters
Change parameters to a hashref.

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Looks good to me.
Two calls in migration_tools/22_to_30 still in old style.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-08-25 10:23:42 -03:00

50 lines
1.3 KiB
Perl
Executable file

#!/usr/bin/perl
use strict;
#use warnings; FIXME - Bug 2505
use C4::Context;
use C4::Items;
use C4::Biblio;
my $dbh=C4::Context->dbh;
if (C4::Context->preference("marcflavour") ne "UNIMARC") {
print "this script is for UNIMARC only\n";
exit;
}
my $rqbiblios=$dbh->prepare("SELECT biblionumber from biblioitems");
my $rqitemnumber=$dbh->prepare("SELECT itemnumber, biblionumber from items where itemnumber = ? and biblionumber = ?");
$rqbiblios->execute;
$|=1;
while (my ($biblionumber)= $rqbiblios->fetchrow_array){
my $record=GetMarcBiblio({ biblionumber => $biblionumber });
foreach my $itemfield ($record->field('995')){
my $marcitem=MARC::Record->new();
$marcitem->encoding('UTF-8');
$marcitem->append_fields($itemfield);
my $itemnum;
my @itemnumbers = $itemfield->subfield('9');
foreach my $itemnumber ( @itemnumbers ){
$rqitemnumber->execute($itemnumber, $biblionumber);
if( my $row = $rqitemnumber->fetchrow_hashref ){
$itemnum = $row->{itemnumber};
}
}
eval{
if($itemnum){
ModItemFromMarc($marcitem,$biblionumber,$itemnum)
}else{
die("$biblionumber");
}
};
print "\r$biblionumber";
if ($@){
warn "Problem with : $biblionumber : $@";
warn $record->as_formatted;
}
}
}