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

(-)a/misc/migration_tools/remove_unused_authorities.pl (-3 / +19 lines)
Lines 32-43 use Koha::SearchEngine::Search; Link Here
32
my @authtypes;
32
my @authtypes;
33
my $want_help = 0;
33
my $want_help = 0;
34
my $test = 0;
34
my $test = 0;
35
my $commit;
36
my $i = 0;
37
35
GetOptions(
38
GetOptions(
36
    'aut|authtypecode:s' => \@authtypes,
39
    'aut|authtypecode:s' => \@authtypes,
37
    't|test'             => \$test,
40
    't|test'             => \$test,
41
    'c|commit:i'         => \$commit,
38
    'h|help'             => \$want_help
42
    'h|help'             => \$want_help
39
);
43
);
40
44
45
my $commitnum = $commit ? $commit : 50;
46
41
if ($want_help) {
47
if ($want_help) {
42
    print_usage();
48
    print_usage();
43
    exit 0;
49
    exit 0;
Lines 63-70 my $rqsql = "SELECT * from auth_header where 1"; Link Here
63
$rqsql .= " AND authtypecode IN (".join(",",map{$dbh->quote($_)}@authtypes).")" if @authtypes;
69
$rqsql .= " AND authtypecode IN (".join(",",map{$dbh->quote($_)}@authtypes).")" if @authtypes;
64
my $rqselect = $dbh->prepare($rqsql);
70
my $rqselect = $dbh->prepare($rqsql);
65
$|=1;
71
$|=1;
66
67
$rqselect->execute;
72
$rqselect->execute;
73
74
$dbh->{AutoCommit} = 0;
68
my $counter=0;
75
my $counter=0;
69
my $totdeleted=0;
76
my $totdeleted=0;
70
my $totundeleted=0;
77
my $totundeleted=0;
Lines 82-94 while (my $data=$rqselect->fetchrow_hashref){ Link Here
82
    print "$counter\n" unless $counter++ % 100;
89
    print "$counter\n" unless $counter++ % 100;
83
    # if found, delete, otherwise, just count
90
    # if found, delete, otherwise, just count
84
    if ($used>=$thresholdmin and $used<=$thresholdmax){
91
    if ($used>=$thresholdmin and $used<=$thresholdmax){
85
        DelAuthority({ authid => $data->{'authid'} }) unless $test;
92
93
        # call with 'skip_merge' arg, as we already know these authority records
94
        # are not linked to any bibs
95
        DelAuthority({ authid => $data->{'authid'}, skip_merge => 1 }) unless $test;
96
86
        $totdeleted++;
97
        $totdeleted++;
87
    } else {
98
    } else {
88
        $totundeleted++;
99
        $totundeleted++;
89
    }
100
    }
101
    $i++;
102
    $dbh->commit() if (0 == $i % $commitnum);
90
}
103
}
91
104
105
$dbh->commit();
106
$dbh->{AutoCommit} = 1;
107
92
print "$counter authorities parsed, $totdeleted deleted and $totundeleted unchanged because used\n";
108
print "$counter authorities parsed, $totdeleted deleted and $totundeleted unchanged because used\n";
93
109
94
110
Lines 110-115 operator to confirm the deletion of each authority record. Link Here
110
parameters
126
parameters
111
    --aut|authtypecode TYPE       the list of authtypes to check
127
    --aut|authtypecode TYPE       the list of authtypes to check
112
    --test or -t                  test mode, don't delete really, just count
128
    --test or -t                  test mode, don't delete really, just count
129
    --commit or -c                the number of records to wait before performing a 'commit' operation
113
    --help or -h                  show this message.
130
    --help or -h                  show this message.
114
131
115
_USAGE_
132
_USAGE_
116
- 

Return to bug 20377