[Koha-patches] [PATCH] 6094 Fixing ModAuthority problems
Marcel de Rooy
M.de.Rooy at rijksmuseum.nl
Thu Apr 7 10:21:51 CEST 2011
Pref MergeAuthoritiesOnUpdate does not exist; should be dontmerge.
In: C4/AuthoritiesMarc.pm
Subfolder tmp/modified_authorities should not be in $cgidir or $intranetdir.
The apache user should not be assumed to have write access there.
I would like to move it (back?) to /tmp/modified_authorities.
The subfolder should be created if not existing.
This change applies to AuthoritiesMarc.pm and merge_authority.pl.
POD lines added for ModAuthority. Deprecated parameter $merge removed.
---
C4/AuthoritiesMarc.pm | 34 ++++++++++++++++++------------
misc/migration_tools/merge_authority.pl | 17 ++++++++-------
2 files changed, 29 insertions(+), 22 deletions(-)
diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm
index 57d318b..f55019d 100644
--- a/C4/AuthoritiesMarc.pm
+++ b/C4/AuthoritiesMarc.pm
@@ -732,28 +732,34 @@ 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);
- }
-
- my $filename = $cgidir."/tmp/modified_authorities/$authid.authid";
- open AUTH, "> $filename";
+ # save the file in tmp/modified_authorities
+ my $dir= "/tmp/modified_authorities";
+ mkdir $dir unless -d $dir;
+ 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..4f020cd 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 /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= "/tmp/modified_authorities";
+ my $rv=opendir(DIR, $dir);
+ print "Cannot open 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
More information about the Koha-patches
mailing list