From ed03edddbdb6846588ff42e967b44c190cdb019b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 15 Mar 2017 12:39:01 -0300 Subject: [PATCH] Bug 18277: Remove GetBiblionumberFromItemnumber - create_analytical_rel.pl I have no idea how to test this patch, see bug 5528, or simply read the code. Signed-off-by: Josef Moravec Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- misc/migration_tools/create_analytical_rel.pl | 57 +++++++++---------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/misc/migration_tools/create_analytical_rel.pl b/misc/migration_tools/create_analytical_rel.pl index 7c970b5d28..3069a34ccc 100755 --- a/misc/migration_tools/create_analytical_rel.pl +++ b/misc/migration_tools/create_analytical_rel.pl @@ -12,6 +12,7 @@ BEGIN { use C4::Context; use C4::Biblio; use C4::Items; +use Koha::Items; use Getopt::Long; $| = 1; @@ -34,7 +35,6 @@ if (not $result or $want_help or not $do_update) { my $num_bibs_processed = 0; my $num_bibs_modified = 0; -my $num_nobib_foritemnumber = 0; my $num_noitem_forbarcode = 0; my $num_nobarcode_inhostfield =0; my $num_hostfields_unabletomodify =0; @@ -91,36 +91,31 @@ sub process_bib { my $analyticfield = '773'; foreach my $hostfield ( $bib->field($analyticfield) ) { if(my $barcode = $hostfield->subfield('o')){ - my $itemnumber = GetItemnumberFromBarcode($barcode); - if ($itemnumber ne undef){ - my $bibnumber = GetBiblionumberFromItemnumber($itemnumber); - if ($bibnumber ne undef){ - my $modif; - if ($hostfield->subfield('0') ne $bibnumber){ - $hostfield->update('0', $bibnumber); - $modif = 1; - } - if ($hostfield->subfield('9') ne $itemnumber){ - $hostfield->update('9', $itemnumber); - $modif=1; - } - if ($modif){ - $num_bibs_modified++; - my $modresult = ModBiblio($bib, $biblionumber, ''); - warn "Modifying biblio $biblionumber"; - if (!$modresult){ - warn "Unable to modify biblio $biblionumber with update host field"; - $num_hostfields_unabletomodify++; - } - } - } else { - warn "No biblio record found corressponding to itemnumber $itemnumber"; - $num_nobib_foritemnumber++; - } - } else { - warn "No item record found for barcode $barcode"; - $num_noitem_forbarcode++; - } + my $item = Koha::Items->find({ barcode => $barcode }); + if ($item) { + my $modif; + if ( $hostfield->subfield('0') ne $biblionumber ) { + $hostfield->update( '0', $biblionumber ); + $modif = 1; + } + if ( $hostfield->subfield('9') ne $item->itemnumber ) { + $hostfield->update( '9', $item->itemnumber ); + $modif = 1; + } + if ($modif) { + $num_bibs_modified++; + my $modresult = ModBiblio( $bib, $biblionumber, '' ); + warn "Modifying biblio $biblionumber"; + if ( !$modresult ) { + warn "Unable to modify biblio $biblionumber with update host field"; + $num_hostfields_unabletomodify++; + } + } + } + else { + warn "No item record found for barcode $barcode"; + $num_noitem_forbarcode++; + } } else{ warn "No barcode in host field for biblionumber $biblionumber"; $num_nobarcode_inhostfield++; -- 2.39.5