Koha/misc/migration_tools/upgradeitems.pl
Jonathan Druart 70d61d80fb
Bug 29697: Replace GetMarcBiblio occurrences with $biblio->metadata->record
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

JD Amended patch:
-# FIXME Special case here

-    print "Biblio not found\n,";
+    print "Biblio not found\n";

- my $biblio = Koha::Biblio->find($hostbiblionumber);
+ my $biblio = Koha::Biblios->find($hostbiblionumber);

Rebased-by: Joonas Kylmälä <joonas.kylmala@iki.fi>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2022-07-22 15:24:11 -03:00

53 lines
1.4 KiB
Perl
Executable file

#!/usr/bin/perl
use strict;
#use warnings; FIXME - Bug 2505
use Koha::Script;
use C4::Context;
use C4::Items qw( ModItemFromMarc );
use Koha::Biblios;
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 $biblio = Koha::Biblios->find($biblionumber);
my $record = $biblio->metadata->record;
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;
}
}
}