From 11b5ed63754fea5313585fa60b79d42137b572e0 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 7 Apr 2011 10:14:08 +0200 Subject: [PATCH] 6094 Fixing ModAuthority problems Content-Type: text/plain; charset="utf-8" Pref MergeAuthoritiesOnUpdate does not exist; should be dontmerge. In: C4/AuthoritiesMarc.pm Subfolder modified_authorities should not be in $cgidir or $intranetdir. Implementing suggestion of Janus Kaczmarec, I move it to /var/tmp. The subfolder is created if not existing. This change applies to AuthoritiesMarc.pm and merge_authority.pl. POD lines added for ModAuthority. Deprecated parameter $merge removed. July 25, 2011: Adjusted. --- C4/AuthoritiesMarc.pm | 34 +++++++++++++++++++----------- misc/migration_tools/merge_authority.pl | 17 ++++++++------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index fa2ef00..ae7cb4a 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -734,28 +734,36 @@ sub DelAuthority { $sth->execute($authid); } +=head2 ModAuthority + + $authid= &ModAuthority($authid,$record,$authtypecode) + +Modifies authority record, optionally updates attached biblios. + +=cut + sub ModAuthority { - my ($authid,$record,$authtypecode,$merge)=@_; + my ($authid,$record,$authtypecode)=@_; # deprecated $merge parameter removed + my $dbh=C4::Context->dbh; #Now rewrite the $record to table with an add my $oldrecord=GetAuthority($authid); $authid=AddAuthority($record,$authid,$authtypecode); -### If a library thinks that updating all biblios is a long process and wishes to leave that to a cron job to use merge_authotities.p -### they should have a system preference "dontmerge=1" otherwise by default biblios will be updated -### the $merge flag is now depreceated and will be removed at code cleaning - if (C4::Context->preference('MergeAuthoritiesOnUpdate') ){ + # If a library thinks that updating all biblios is a long process and wishes + # to leave that to a cron job, use misc/migration_tools/merge_authority.pl. + # In that case set system preference "dontmerge" to 1. Otherwise biblios will + # be updated. + unless(C4::Context->preference('dontmerge') eq '1'){ &merge($authid,$oldrecord,$authid,$record); } else { - # save the file in tmp/modified_authorities - my $cgidir = C4::Context->intranetdir ."/cgi-bin"; - unless (opendir(DIR,"$cgidir")) { - $cgidir = C4::Context->intranetdir."/"; - closedir(DIR); + # save the file in /var/tmp/modified_authorities + my $dir= "/var/tmp/modified_authorities"; + unless(-d $dir) { + mkdir $dir; system "chmod 777 $dir"; } - - my $filename = $cgidir."/tmp/modified_authorities/$authid.authid"; - open AUTH, "> $filename"; + my $filename = "$dir/$authid.authid"; + open AUTH, '>', $filename; print AUTH $authid; close AUTH; } diff --git a/misc/migration_tools/merge_authority.pl b/misc/migration_tools/merge_authority.pl index b99591f..4cc6f37 100755 --- a/misc/migration_tools/merge_authority.pl +++ b/misc/migration_tools/merge_authority.pl @@ -44,6 +44,7 @@ SAMPLE : ./merge_authority.pl -f 2457 -t 531 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. +Make sure that if this script runs in batch mode, the process has sufficient permissions for removing files from /var/tmp/modified_authorities. EOF ;# die; @@ -76,22 +77,22 @@ my $starttime = gettimeofday; print "Merging\n" unless $noconfirm; if ($batch) { my @authlist; - my $cgidir = C4::Context->intranetdir ."/cgi-bin"; - unless (opendir(DIR, "$cgidir/tmp/modified_authorities")) { - $cgidir = C4::Context->intranetdir; - opendir(DIR, "$cgidir/tmp/modified_authorities") || die "can't opendir $cgidir/tmp/modified_authorities: $!"; - } - while (my $authid = readdir(DIR)) { + my $dir= "/var/tmp/modified_authorities"; + my $rv=opendir(DIR, $dir); + print "Cannot open /var/tmp/modified_authorities!\n" unless $rv; + while ($rv && (my $authid = readdir(DIR))) { if ($authid =~ /\.authid$/) { $authid =~ s/\.authid$//; print "managing $authid\n" if $verbose; my $MARCauth = GetAuthority($authid) ; next unless ($MARCauth); merge($authid,$MARCauth,$authid,$MARCauth) if ($MARCauth); - unlink $cgidir.'/tmp/modified_authorities/'.$authid.'.authid'; + unlink $dir.'/'.$authid.'.authid'; + print "Warning: File $authid.authid could not be removed\n" + if -e $dir.'/'.$authid.'.authid'; } } - closedir DIR; + closedir DIR if $rv; } else { my $MARCfrom = GetAuthority($mergefrom); my $MARCto = GetAuthority($mergeto); -- 1.6.0.6