Koha/misc/migration_tools/upgradeitems.pl
Martin Renvoize d2e189ca1c Bug 22600: Set 'commandline' interface appropriately
This patch change Koha::Cron to be a more generic Koha::Script class and
update all commanline driven scripts to use it.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
2019-04-10 19:43:11 +00:00

52 lines
1.3 KiB
Perl
Executable file

#!/usr/bin/perl
use strict;
#use warnings; FIXME - Bug 2505
use Koha::Script;
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;
}
}
}