From e0b029a4f5ff378291e86fa55e07841297d611e7 Mon Sep 17 00:00:00 2001 From: Nahuel ANGELINETTI Date: Mon, 17 May 2010 15:43:37 +0200 Subject: [PATCH] (bug #4518) enhance 2.2 to 3.0 scripts Signed-off-by: Chris Cormack --- .../22_to_30/missing090field.pl | 4 +++- .../22_to_30/move_marc_to_authheader.pl | 2 +- misc/migration_tools/upgradeitems.pl | 23 +++++++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/misc/migration_tools/22_to_30/missing090field.pl b/misc/migration_tools/22_to_30/missing090field.pl index aae803236d..bfa85760af 100755 --- a/misc/migration_tools/22_to_30/missing090field.pl +++ b/misc/migration_tools/22_to_30/missing090field.pl @@ -21,7 +21,7 @@ use MARC::File::USMARC; $|=1; my $dbh = C4::Context->dbh; -my $sth=$dbh->prepare("select m.biblionumber,b.biblioitemnumber from biblio m left join biblioitems b on b.biblionumber=m.biblionumber"); +my $sth=$dbh->prepare("SELECT biblionumber, biblioitemnumber FROM biblioitems"); $sth->execute(); my $i=1; @@ -35,6 +35,8 @@ while (my ($biblionumber,$biblioitemnumber)=$sth->fetchrow ){ sub MARCmodbiblionumber{ my ($biblionumber,$biblioitemnumber,$record)=@_; + return unless $record; + my ($tagfield,$biblionumtagsubfield) = &GetMarcFromKohaField("biblio.biblionumber",""); my ($tagfield2,$biblioitemtagsubfield) = &GetMarcFromKohaField("biblio.biblioitemnumber",""); diff --git a/misc/migration_tools/22_to_30/move_marc_to_authheader.pl b/misc/migration_tools/22_to_30/move_marc_to_authheader.pl index 2546da855b..f5e4b43288 100755 --- a/misc/migration_tools/22_to_30/move_marc_to_authheader.pl +++ b/misc/migration_tools/22_to_30/move_marc_to_authheader.pl @@ -43,7 +43,7 @@ while ( my ( $authid,$authtypecode ) = $sth->fetchrow ) { $string=~s/\-//g; $string = sprintf("%-*s",26, $string); substr($string,9,6,"frey50"); - unless ($record->subfield(100,"a")){ + unless ($record->subfield(100,"a") and length($record->subfield(100,"a")) == 26 ){ $record->insert_fields_ordered(MARC::Field->new(100,"","","a"=>$string)); } if ($record->field(152)){ diff --git a/misc/migration_tools/upgradeitems.pl b/misc/migration_tools/upgradeitems.pl index 10c754433a..c5469eeb44 100755 --- a/misc/migration_tools/upgradeitems.pl +++ b/misc/migration_tools/upgradeitems.pl @@ -13,6 +13,8 @@ if (C4::Context->preference("marcflavour") ne "UNIMARC") { 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){ @@ -21,10 +23,27 @@ while (my ($biblionumber)= $rqbiblios->fetchrow_array){ my $marcitem=MARC::Record->new(); $marcitem->encoding('UTF-8'); $marcitem->append_fields($itemfield); - eval{ModItemFromMarc($marcitem,$biblionumber,$itemfield->subfield('9'));}; + + + 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 "$biblionumber : $@"; + warn "Problem with : $biblionumber : $@"; warn $record->as_formatted; } } -- 2.39.5