Bugzilla – Attachment 14822 Details for
Bug 9453
Update records according to the new UNIMARCField100Language system preference
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[SIGNED-OFF] Bug 9453: Update records acording to the new UNIMARCField100Language system preference
Bug-9453-Update-records-acording-to-the-new-UNIMAR.patch (text/plain), 9.81 KB, created by
Vitor Fernandes
on 2013-01-24 14:49:45 UTC
(
hide
)
Description:
[SIGNED-OFF] Bug 9453: Update records acording to the new UNIMARCField100Language system preference
Filename:
MIME Type:
Creator:
Vitor Fernandes
Created:
2013-01-24 14:49:45 UTC
Size:
9.81 KB
patch
obsolete
>From c2dc00a59889834a2a4dbe8fd18ce2a88dfb3af5 Mon Sep 17 00:00:00 2001 >From: Vitor FERNANDES <vfernandes@keep.pt> >Date: Thu, 24 Jan 2013 14:46:28 +0000 >Subject: [PATCH] Bug 9453: Update records acording to the new > UNIMARCField100Language system preference > >Problems with perlcritic corrected. >Script without parameters shows help. >--- > misc/maintenance/update_unimarc_100a_language.pl | 337 ++++++++++++---------- > 1 file changed, 179 insertions(+), 158 deletions(-) > >diff --git a/misc/maintenance/update_unimarc_100a_language.pl b/misc/maintenance/update_unimarc_100a_language.pl >index 8563ab1..5713a41 100644 >--- a/misc/maintenance/update_unimarc_100a_language.pl >+++ b/misc/maintenance/update_unimarc_100a_language.pl >@@ -1,158 +1,179 @@ >-#!/usr/bin/perl >-# >-# Copyright (C) 2012 FCT/UNL >-# >-# This file is part of Koha. >-# >-# Koha is free software; you can redistribute it and/or modify it under the >-# terms of the GNU General Public License as published by the Free Software >-# Foundation; either version 2 of the License, or (at your option) any later >-# version. >-# >-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >-# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >-# >-# You should have received a copy of the GNU General Public License along >-# with Koha; if not, write to the Free Software Foundation, Inc., >-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >- >-use strict; >-use warnings; >-BEGIN { >- # find Koha's Perl modules >- # test carefully before changing this >- use FindBin; >- eval { require "$FindBin::Bin/../kohalib.pl" }; >-} >- >-# possible modules to use >-use Getopt::Long; >-use C4::Context; >-use C4::Biblio; >-use Pod::Usage; >- >- >-sub usage { >- pod2usage( -verbose => 2 ); >- exit; >-} >- >-# Database handle >-my $dbh = C4::Context->dbh; >- >-# Benchmarking variables >-my $startime = time(); >-my $totalcount = 0; >- >-# Options >-my $biblionumber = ''; >-my $whereclause = ''; >-my $help; >-my $outfile; >-my $default_unimarc_language = C4::Context->preference("UNIMARCField100Language"); >-GetOptions( >- 'o|output:s' => \$outfile, >- 'b|biblionumber:s' => \$biblionumber, >- 'h|help' => \$help, >- ); >- >-usage() if $help; >- >-# Add filter search by biblionumber(s) if any was given >-if ($biblionumber) { >- $whereclause = "WHERE `biblionumber` IN ( $biblionumber )"; >-} >- >-# Output log or STDOUT >-if (defined $outfile) { >- open(OUT, ">$outfile") || die ("Cannot open output file"); >-} else { >- open(OUT, ">&STDOUT") || die ("Couldn't duplicate STDOUT: $!"); >-} >- >-# Fetch info from the search >-my $sth1 = $dbh->prepare("SELECT biblionumber, frameworkcode FROM biblio $whereclause"); >-$sth1->execute(); >- >-# Process each MARC biblio record >-while (my ($biblionumber, $frameworkcode) = $sth1->fetchrow_array){ >- # Get MARC biblio record >- my $record = GetMarcBiblio($biblionumber); >- >- # Retrieve subfield 100$a >- my $subfield = $record->subfield('100', 'a'); >- >- # Update the hardcoded 'fre' language code for the one set as UNIMARC default >- $subfield =~ s/fre/$default_unimarc_language/g; >- >- # Print output for the currect record >- print OUT "Biblionumber: $biblionumber, New 100\$a value: '$subfield'\n"; >- >- # Update field 100 with the new subfield a value >- $record->field('100')->update('a' => $subfield); >- >- # Save record to the database >- ModBiblioMarc($record, $biblionumber, $frameworkcode); >- >- $totalcount++; >-} >- >-# Benchmarking >-my $endtime = time(); >-my $time = $endtime-$startime; >-my $averagetime = 0; >-unless ($time == 0) { $averagetime = $totalcount / $time; }; >-print OUT "\nUpdated $totalcount records in $time seconds\n"; >- >-if (defined $outfile) { >- close(OUT); >-} >- >-=head1 NAME >- >-update_unimarc_100a_language.pl >- >-=head1 SYNOPSIS >- >-Update all biblio records' field 100a language value with the one >-defined in the "UNIMARC field 100 default language" system preference. >- >-=head1 DESCRIPTION >- >-Due to bug 8347, Koha forced UNIMARC 100 field code language to 'fre' >-This script aims to replace the value on all the records, or in a >-given set of records, for a new value defined by the new system >-preference "UNIMARC field 100 default language". >- >-=over 8 >- >-=item B<-help> >- >-Prints this help >- >- >-=item B<-b> >- >-Limits the action to a fixed set of comma separated biblionumber values >- >- Update record with biblionumber 1: >- update_unimarc_100a_language.pl -biblionumber=1 (or -b=1) >- >- >- Update records with biblionumbers 1, 2 and 3: >- update_unimarc_100a_language.pl -biblionumber=1,2,3 (or -b=1,2,3) >- >- >-=item B<-o> >- >-Sets the output of the script to a given file. Helpful for verification purposes on big sets of records >- >- Update records with script output being sent to file >- update_unimarc_100a_language.pl -output=file.txt (or -o=file.txt) >- >-=back >- >-=cut >- >- >+#!/usr/bin/perl >+# >+# Copyright (C) 2012 FCT/UNL >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 2 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License along >+# with Koha; if not, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use strict; >+use warnings; >+BEGIN { >+ # find Koha's Perl modules >+ # test carefully before changing this >+ use FindBin; >+ eval { require "$FindBin::Bin/../kohalib.pl" }; >+} >+ >+# possible modules to use >+use Getopt::Long; >+use C4::Context; >+use C4::Biblio; >+use Pod::Usage; >+# use Data::Dumper; # for debugging purposes only >+ >+ >+sub usage { >+ pod2usage( -verbose => 2 ); >+ exit; >+} >+ >+# Database handle >+my $dbh = C4::Context->dbh; >+ >+# Benchmarking variables >+my $startime = time(); >+my $totalcount = 0; >+ >+# Options >+my $all; >+my $biblionumber = ''; >+my $whereclause = ''; >+my $help; >+my $filename; >+my $output; >+my $default_unimarc_language = C4::Context->preference("UNIMARCField100Language"); >+ >+GetOptions( >+ 'a|all' => \$all, >+ 'b|biblionumber:s' => \$biblionumber, >+ 'h|help' => \$help, >+ 'o|output:s' => \$filename, >+ ); >+ >+print $biblionumber; >+ >+ >+# Show usage instructions if: >+# 1 - requested using the -h or -help option >+# 2 - no arguments where passed on >+# 3 - -b or -biblionumber and -a options where used simultaneously >+# 4 - neiter -b, -biblionumber or -a options where used >+usage() if (($help) || (0 == $#ARGV) || ($biblionumber && $all) || (!($biblionumber || $all))); >+ >+# Add filter search by biblionumber(s) if any was given >+if ($biblionumber) { >+ $whereclause = "WHERE `biblionumber` IN ( $biblionumber )"; >+} >+ >+# Output log or STDOUT >+if (defined $filename) { >+ open STDOUT, '>', $filename || die ("Can't open output file '$filename'"); >+} >+ >+# Fetch info from the search >+my $sth1 = $dbh->prepare("SELECT biblionumber, frameworkcode FROM biblio $whereclause"); >+$sth1->execute(); >+ >+# Process each MARC biblio record >+while (my ($biblionumber, $frameworkcode) = $sth1->fetchrow_array){ >+ # Get MARC biblio record >+ my $record = GetMarcBiblio($biblionumber); >+ >+ # Retrieve subfield 100$a >+ my $subfield = $record->subfield('100', 'a'); >+ >+ # Update the hardcoded 'fre' language code for the one set as UNIMARC default >+ $subfield =~ s/fre/$default_unimarc_language/g; >+ >+ # Print output for the currect record >+ print STDOUT "Biblionumber: $biblionumber, New 100\$a value: '$subfield'\n"; >+ >+ # Update field 100 with the new subfield a value >+ $record->field('100')->update('a' => $subfield); >+ >+ # Save record to the database >+ ModBiblioMarc($record, $biblionumber, $frameworkcode); >+ >+ $totalcount++; >+} >+ >+# Benchmarking >+my $endtime = time(); >+my $time = $endtime-$startime; >+my $averagetime = 0; >+unless ($time == 0) { $averagetime = $totalcount / $time; }; >+print STDOUT "Updated $totalcount records in $time seconds\n"; >+ >+if (defined $filename) { >+ close(STDOUT); >+} >+ >+=head1 NAME >+ >+update_unimarc_100a_language.pl >+ >+=head1 SYNOPSIS >+ >+Update all biblio records' field 100a language value with the one >+defined in the "UNIMARC field 100 default language" system preference. >+ >+=head1 DESCRIPTION >+ >+Due to bug 8347, Koha forced UNIMARC 100 field code language to 'fre' >+This script aims to replace the value on all the records, or in a >+given set of records, for a new value defined by the new system >+preference "UNIMARC field 100 default language". >+ >+=head1 REQUIRED ARGUMENTS >+ >+The script must be ran with B<one and only one> of these two options: -a or -b (-biblionumber) >+ >+=head1 USAGE >+ >+=over 8 >+ >+=item B<-help> >+ >+Prints this help >+ >+ >+=item B<-a> >+ >+Update all records >+ >+ update_unimarc_100a_language.pl -a >+ >+ >+=item B<-b> >+ >+Limit the action to a fixed set of comma separated biblionumber values >+ >+ Update record with biblionumber 1: >+ update_unimarc_100a_language.pl -b=1 (or -biblionumber=1) >+ >+ Update records with biblionumbers 1, 2 and 3: >+ update_unimarc_100a_language.pl -b=1,2,3 (or -biblionumber=1,2,3) >+ >+ >+=item B<-o> >+ >+Sets the output of the script to a given file. Helpful for verification purposes on big sets of records >+ >+ Update records with script output being sent to file >+ update_unimarc_100a_language.pl -output=file.txt (or -o=file.txt) >+ >+=back >+ >+=cut >-- >1.7.9.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 9453
:
14778
|
14784
|
14785
|
14822
|
15145