|
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 111-114
foreach my $index ( ( 'biblios', 'authorities' ) ) {
Link Here
|
| 111 |
print " Enter this command to view record: curl $es_base/data/$problem?pretty=true\n"; |
141 |
print " Enter this command to view record: curl $es_base/data/$problem?pretty=true\n"; |
| 112 |
} |
142 |
} |
| 113 |
} |
143 |
} |
|
|
144 |
|
| 145 |
if ( $fix && ( @koha_problems || @es_problems ) ) { |
| 146 |
|
| 147 |
print "=================\n"; |
| 148 |
print "Trying to fix problems:\n\n"; |
| 149 |
|
| 150 |
my $indexer; |
| 151 |
my $server; |
| 152 |
if ( $index eq 'biblios' ) { |
| 153 |
$indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); |
| 154 |
$server = 'biblioserver'; |
| 155 |
} else { |
| 156 |
$indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); |
| 157 |
$server = 'authorityserver'; |
| 158 |
} |
| 159 |
|
| 160 |
if (@koha_problems) { |
| 161 |
|
| 162 |
print "=================\n"; |
| 163 |
print "Fixing missing records in the index ($index):\n\n"; |
| 164 |
|
| 165 |
foreach my $id (@koha_problems) { |
| 166 |
try { |
| 167 |
$indexer->update_index( [$id] ); |
| 168 |
} catch { |
| 169 |
print STDERR "ERROR: record #$id failed: $_\n\n"; |
| 170 |
}; |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
if (@es_problems) { |
| 175 |
|
| 176 |
print "=================\n"; |
| 177 |
print "Deleting non-existent records from the index ($index)...\n"; |
| 178 |
|
| 179 |
$indexer->delete_index( \@es_problems ); |
| 180 |
} |
| 181 |
} |
| 114 |
} |
182 |
} |
| 115 |
- |
183 |
|
|
|
184 |
1; |