9 use C4::AuthoritiesMarc; ###merge routine moved to there
10 use Time::HiRes qw(gettimeofday);
13 my ($version, $verbose, $mergefrom,$mergeto,$noconfirm,$batch);
23 if ($version || ($mergefrom eq '' && !$batch)) {
25 Script to merge an authority into another
27 \th : this version/help screen
28 \tv : verbose mode (show many things on screen)
29 \tf : the authority number to merge (the one that can be deleted after the merge).
30 \tt : the authority number where to merge
32 \tn : don't ask for confirmation (useful for batch mergings, should not be used on command line)
34 All biblios with the authority in -t will be modified to be "connected" to authority -f
36 ./merge_authority.pl -f 2457 -t 531
38 Before doing anything, the script will show both authorities and ask for confirmation. Of course, you can merge only 2 authorities of the same kind.
41 The batch mode is done to report modifs. On every authority modif, a file is generated in KOHAROOT/localfile/modified_authorities/ If this script is called with -b, it parses the directory, finding & updating biblios using the modified authority.
43 ./merge_authority.pl -b
45 (don't forget to export PERL5LIB and KOHA_CONF. Here is my cron job :
47 */5 * * * * export PERL5LIB=/home/httpd/koha;export KOHA_CONF=/etc/mykoha.conf;/home/httpd/koha/scripts/misc/merge_authority.pl -b -n
54 my $dbh = C4::Context->dbh;
55 # my @subf = $subfields =~ /(##\d\d\d##.)/g;
57 $|=1; # flushes output
58 my $starttime = gettimeofday;
61 my $cgidir = C4::Context->intranetdir ."/cgi-bin";
62 unless (opendir(DIR, "$cgidir/localfile/modified_authorities")) {
63 $cgidir = C4::Context->intranetdir;
64 opendir(DIR, "$cgidir/localfile/modified_authorities") || die "can't opendir $cgidir/localfile/modified_authorities: $!";
66 while (my $authid = readdir(DIR)) {
67 if ($authid =~ /\.authid$/) {
68 $authid =~ s/\.authid$//;
69 print "managing $authid\n" if $verbose;
70 my $MARCauth = XMLgetauthorityhash($dbh,$authid);
71 &merge($dbh,$authid,$MARCauth,$authid,$MARCauth) if ($MARCauth);
72 unlink $cgidir.'/localfile/modified_authorities/'.$authid.'.authid';
77 my $MARCfrom = XMLgetauthorityhash($dbh,$mergefrom);
78 my $MARCto = XMLgetauthorityhash($dbh,$mergeto);
79 &merge($dbh,$mergefrom,$MARCfrom,$mergeto,$MARCto);
81 my $timeneeded = gettimeofday - $starttime;
82 print "Done in $timeneeded seconds" unless $noconfirm;