Lines 30-36
B<compare_es_to_db.pl>
Link Here
|
30 |
=cut |
30 |
=cut |
31 |
|
31 |
|
32 |
use Modern::Perl; |
32 |
use Modern::Perl; |
|
|
33 |
|
33 |
use Array::Utils qw( array_minus ); |
34 |
use Array::Utils qw( array_minus ); |
|
|
35 |
use Getopt::Long qw( GetOptions ); |
36 |
use Try::Tiny qw( catch try ); |
34 |
|
37 |
|
35 |
use C4::Context; |
38 |
use C4::Context; |
36 |
|
39 |
|
Lines 39-44
use Koha::Biblios;
Link Here
|
39 |
use Koha::Items; |
42 |
use Koha::Items; |
40 |
use Koha::SearchEngine::Elasticsearch; |
43 |
use Koha::SearchEngine::Elasticsearch; |
41 |
|
44 |
|
|
|
45 |
my $help; |
46 |
my $fix; |
47 |
|
48 |
GetOptions( |
49 |
'h|help' => \$help, |
50 |
'f|fix' => \$fix, |
51 |
); |
52 |
|
53 |
my $usage = <<'ENDUSAGE'; |
54 |
|
55 |
This script finds differences between the records on the Koha database |
56 |
and the Elasticsearch index. |
57 |
|
58 |
The `--fix` option switch can be passed to try fixing them. |
59 |
|
60 |
This script has the following parameters : |
61 |
|
62 |
-f|--fix Try to fix errors |
63 |
-h|--help Print this message |
64 |
|
65 |
ENDUSAGE |
66 |
|
67 |
if ($help) { |
68 |
print $usage; |
69 |
exit; |
70 |
} |
71 |
|
42 |
foreach my $index ( ( 'biblios', 'authorities' ) ) { |
72 |
foreach my $index ( ( 'biblios', 'authorities' ) ) { |
43 |
print "=================\n"; |
73 |
print "=================\n"; |
44 |
print "Checking $index\n"; |
74 |
print "Checking $index\n"; |
Lines 110-113
foreach my $index ( ( 'biblios', 'authorities' ) ) {
Link Here
|
110 |
print " Enter this command to view record: curl $es_base/data/$problem?pretty=true\n"; |
140 |
print " Enter this command to view record: curl $es_base/data/$problem?pretty=true\n"; |
111 |
} |
141 |
} |
112 |
} |
142 |
} |
|
|
143 |
|
144 |
if ( $fix && ( @koha_problems || @es_problems ) ) { |
145 |
|
146 |
print "=================\n"; |
147 |
print "Trying to fix problems:\n\n"; |
148 |
|
149 |
my $indexer; |
150 |
my $server; |
151 |
if ( $index eq 'biblios' ) { |
152 |
$indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); |
153 |
$server = 'biblioserver'; |
154 |
} else { |
155 |
$indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); |
156 |
$server = 'authorityserver'; |
157 |
} |
158 |
|
159 |
if (@koha_problems) { |
160 |
|
161 |
print "=================\n"; |
162 |
print "Fixing missing records in the index ($index):\n\n"; |
163 |
|
164 |
foreach my $id (@koha_problems) { |
165 |
try { |
166 |
$indexer->update_index( [$id] ); |
167 |
} catch { |
168 |
print STDERR "ERROR: record #$id failed: $_\n\n"; |
169 |
}; |
170 |
} |
171 |
} |
172 |
|
173 |
if (@es_problems) { |
174 |
|
175 |
print "=================\n"; |
176 |
print "Deleting non-existent records from the index ($index)...\n"; |
177 |
|
178 |
$indexer->delete_index( \@es_problems ); |
179 |
} |
180 |
} |
113 |
} |
181 |
} |
114 |
- |
182 |
|
|
|
183 |
1; |