Increment version for 3.22.18
[koha.git] / misc / migration_tools / upgradeitems.pl
blobc5469eeb4471d073e57620cc9f8ec49f19af2822
1 #!/usr/bin/perl
3 use strict;
4 #use warnings; FIXME - Bug 2505
5 use C4::Context;
6 use C4::Items;
7 use C4::Biblio;
9 my $dbh=C4::Context->dbh;
11 if (C4::Context->preference("marcflavour") ne "UNIMARC") {
12 print "this script is for UNIMARC only\n";
13 exit;
15 my $rqbiblios=$dbh->prepare("SELECT biblionumber from biblioitems");
16 my $rqitemnumber=$dbh->prepare("SELECT itemnumber, biblionumber from items where itemnumber = ? and biblionumber = ?");
18 $rqbiblios->execute;
19 $|=1;
20 while (my ($biblionumber)= $rqbiblios->fetchrow_array){
21 my $record=GetMarcBiblio($biblionumber);
22 foreach my $itemfield ($record->field('995')){
23 my $marcitem=MARC::Record->new();
24 $marcitem->encoding('UTF-8');
25 $marcitem->append_fields($itemfield);
28 my $itemnum;
29 my @itemnumbers = $itemfield->subfield('9');
30 foreach my $itemnumber ( @itemnumbers ){
31 $rqitemnumber->execute($itemnumber, $biblionumber);
32 if( my $row = $rqitemnumber->fetchrow_hashref ){
33 $itemnum = $row->{itemnumber};
37 eval{
38 if($itemnum){
39 ModItemFromMarc($marcitem,$biblionumber,$itemnum)
40 }else{
41 die("$biblionumber");
44 print "\r$biblionumber";
45 if ($@){
46 warn "Problem with : $biblionumber : $@";
47 warn $record->as_formatted;