View | Details | Raw Unified | Return to bug 6094
Collapse All | Expand All

(-)a/C4/AuthoritiesMarc.pm (-17 / +20 lines)
Lines 734-763 sub DelAuthority { Link Here
734
    $sth->execute($authid);
734
    $sth->execute($authid);
735
}
735
}
736
736
737
=head2 ModAuthority
738
739
  $authid= &ModAuthority($authid,$record,$authtypecode)
740
741
Modifies authority record, optionally updates attached biblios.
742
743
=cut
744
737
sub ModAuthority {
745
sub ModAuthority {
738
  my ($authid,$record,$authtypecode,$merge)=@_;
746
  my ($authid,$record,$authtypecode)=@_; # deprecated $merge parameter removed
747
739
  my $dbh=C4::Context->dbh;
748
  my $dbh=C4::Context->dbh;
740
  #Now rewrite the $record to table with an add
749
  #Now rewrite the $record to table with an add
741
  my $oldrecord=GetAuthority($authid);
750
  my $oldrecord=GetAuthority($authid);
742
  $authid=AddAuthority($record,$authid,$authtypecode);
751
  $authid=AddAuthority($record,$authid,$authtypecode);
743
752
744
### 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
753
  # If a library thinks that updating all biblios is a long process and wishes
745
### they should have a system preference "dontmerge=1" otherwise by default biblios will be updated
754
  # to leave that to a cron job, use misc/migration_tools/merge_authority.pl.
746
### the $merge flag is now depreceated and will be removed at code cleaning
755
  # In that case set system preference "dontmerge" to 1. Otherwise biblios will
747
  if (C4::Context->preference('MergeAuthoritiesOnUpdate') ){
756
  # be updated.
757
  unless(C4::Context->preference('dontmerge') eq '1'){
748
      &merge($authid,$oldrecord,$authid,$record);
758
      &merge($authid,$oldrecord,$authid,$record);
749
  } else {
759
  } else {
750
  # save the file in tmp/modified_authorities
760
      # save a record in need_merge_authorities table
751
      my $cgidir = C4::Context->intranetdir ."/cgi-bin";
761
      my $sqlinsert="INSERT INTO need_merge_authorities (authid, done) ".
752
      unless (opendir(DIR,"$cgidir")) {
762
	"VALUES (?,?)";
753
              $cgidir = C4::Context->intranetdir."/";
763
      $dbh->do($sqlinsert,undef,($authid,0));
754
              closedir(DIR);
755
      }
756
  
757
      my $filename = $cgidir."/tmp/modified_authorities/$authid.authid";
758
      open AUTH, "> $filename";
759
      print AUTH $authid;
760
      close AUTH;
761
  }
764
  }
762
  logaction( "AUTHORITIES", "MODIFY", $authid, "BEFORE=>" . $oldrecord->as_formatted ) if C4::Context->preference("AuthoritiesLog");
765
  logaction( "AUTHORITIES", "MODIFY", $authid, "BEFORE=>" . $oldrecord->as_formatted ) if C4::Context->preference("AuthoritiesLog");
763
  return $authid;
766
  return $authid;
Lines 1323-1329 sub merge { Link Here
1323
            push @reccache, $marcdata;
1326
            push @reccache, $marcdata;
1324
            $z++;
1327
            $z++;
1325
        }
1328
        }
1326
        $oConnection->destroy();    
1329
        #$oConnection->destroy(); #see Bugzilla 6094 Uncommenting this line makes that the second subsequent call of merge crashes on the Zconn call line little before this line
1327
    }
1330
    }
1328
    #warn scalar(@reccache)." biblios to update";
1331
    #warn scalar(@reccache)." biblios to update";
1329
    # Get All candidate Tags for the change 
1332
    # Get All candidate Tags for the change 
(-)a/misc/migration_tools/merge_authority.pl (-13 / +7 lines)
Lines 44-49 SAMPLE : Link Here
44
./merge_authority.pl -f 2457 -t 531
44
./merge_authority.pl -f 2457 -t 531
45
45
46
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.
46
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.
47
Make sure that if this script runs in batch mode, the process has sufficient permissions for removing files from /var/tmp/modified_authorities.
47
EOF
48
EOF
48
;#
49
;#
49
die;
50
die;
Lines 75-97 unless ($noconfirm || $batch) { Link Here
75
my $starttime = gettimeofday;
76
my $starttime = gettimeofday;
76
print "Merging\n" unless $noconfirm;
77
print "Merging\n" unless $noconfirm;
77
if ($batch) {
78
if ($batch) {
78
  my @authlist;
79
  my $authref;
79
  my $cgidir = C4::Context->intranetdir ."/cgi-bin";
80
  $dbh->do("update need_merge_authorities set done=2 where done=0"); #temporary status 2 means: selected for merge
80
  unless (opendir(DIR, "$cgidir/tmp/modified_authorities")) {
81
  $authref=$dbh->selectall_arrayref("select distinct authid from need_merge_authorities where done=2");
81
    $cgidir = C4::Context->intranetdir;
82
  foreach(@$authref) {
82
    opendir(DIR, "$cgidir/tmp/modified_authorities") || die "can't opendir $cgidir/tmp/modified_authorities: $!";
83
      my $authid=$_->[0];
83
  } 
84
  while (my $authid = readdir(DIR)) {
85
    if ($authid =~ /\.authid$/) {
86
      $authid =~ s/\.authid$//;
87
      print "managing $authid\n" if $verbose;
84
      print "managing $authid\n" if $verbose;
88
      my $MARCauth = GetAuthority($authid) ;
85
      my $MARCauth = GetAuthority($authid) ;
89
      next unless ($MARCauth);
86
      next unless ($MARCauth);
90
      merge($authid,$MARCauth,$authid,$MARCauth) if ($MARCauth);
87
      merge($authid,$MARCauth,$authid,$MARCauth) if ($MARCauth);
91
      unlink $cgidir.'/tmp/modified_authorities/'.$authid.'.authid';
92
    }
93
  }
88
  }
94
  closedir DIR;
89
  $dbh->do("update need_merge_authorities set done=1 where done=2"); #DONE
95
} else {
90
} else {
96
  my $MARCfrom = GetAuthority($mergefrom);
91
  my $MARCfrom = GetAuthority($mergefrom);
97
  my $MARCto = GetAuthority($mergeto);
92
  my $MARCto = GetAuthority($mergeto);
98
- 

Return to bug 6094