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