Bugzilla – Attachment 178178 Details for
Bug 36365
compare_es_to_db.pl should offer a way to reconcile differences
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36365: Add a way for compare_es_to_db.pl to fix problems
Bug-36365-Add-a-way-for-compareestodbpl-to-fix-pro.patch (text/plain), 3.94 KB, created by
Andrew Fuerste-Henry
on 2025-02-18 13:33:38 UTC
(
hide
)
Description:
Bug 36365: Add a way for compare_es_to_db.pl to fix problems
Filename:
MIME Type:
Creator:
Andrew Fuerste-Henry
Created:
2025-02-18 13:33:38 UTC
Size:
3.94 KB
patch
obsolete
>From 1e8ccc0fc6efa46e2d84ae1a3cbf6972bb491045 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 14 Feb 2025 22:35:41 +0000 >Subject: [PATCH] Bug 36365: Add a way for compare_es_to_db.pl to fix problems > >This patch adds a new option switch `--fix` (or `-f`) to make the script >try to fix the problems it found. > >Bonus: `--help` option switch added. > >To test: >1. Apply this patch >2. Run: > $ ktd --shell > k$ perl -MKoha::SearchEngine -MKoha::SearchEngine::Indexer -e 'my $i = Koha::SearchEngine::Indexer->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); $i->delete_index([1]);' >=> SUCCESS: Bibliographic record #deleted from ES index >3. Run: > k$ koha-mysql kohadev > > DELETE FROM biblio WHERE biblionumber=2 OR biblionumber=3; >=> SUCCESS: Bibliographic records 2 and 3 deleted directly from the >database, no reindex triggered by Koha. >4. Run: > k$ perl misc/maintenance/compare_es_to_db.pl >=> SUCCESS: The results from (2) and (3) are explained. [1] >5. Run: > k$ perl misc/maintenance/compare_es_to_db.pl --fix >=> SUCCESS: It says it is gonna fix things >6. Repeat 4 >=> SUCCESS: The problems we generated are no longer reported! They've >been fixed! >7. Sign off :-D > >[1] Note KTD ships some broken records on purpose so devs need to deal >with a not-perfect DB everyday, and catch misses in the code. > >Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com> >--- > misc/maintenance/compare_es_to_db.pl | 70 ++++++++++++++++++++++++++++ > 1 file changed, 70 insertions(+) > >diff --git a/misc/maintenance/compare_es_to_db.pl b/misc/maintenance/compare_es_to_db.pl >index 394449b743..7d9c52acd6 100755 >--- a/misc/maintenance/compare_es_to_db.pl >+++ b/misc/maintenance/compare_es_to_db.pl >@@ -30,7 +30,10 @@ B<compare_es_to_db.pl> > =cut > > use Modern::Perl; >+ > use Array::Utils qw( array_minus ); >+use Getopt::Long qw( GetOptions ); >+use Try::Tiny qw( catch try ); > > use C4::Context; > >@@ -39,6 +42,33 @@ use Koha::Biblios; > use Koha::Items; > use Koha::SearchEngine::Elasticsearch; > >+my $help; >+my $fix; >+ >+GetOptions( >+ 'h|help' => \$help, >+ 'f|fix' => \$fix, >+); >+ >+my $usage = <<'ENDUSAGE'; >+ >+This script finds differences between the records on the Koha database >+and the Elasticsearch index. >+ >+The `--fix` option switch can be passed to try fixing them. >+ >+This script has the following parameters : >+ >+ -f|--fix Try to fix errors >+ -h|--help Print this message >+ >+ENDUSAGE >+ >+if ($help) { >+ print $usage; >+ exit; >+} >+ > foreach my $index ( ( 'biblios', 'authorities' ) ) { > print "=================\n"; > print "Checking $index\n"; >@@ -110,4 +140,44 @@ foreach my $index ( ( 'biblios', 'authorities' ) ) { > print " Enter this command to view record: curl $es_base/data/$problem?pretty=true\n"; > } > } >+ >+ if ( $fix && ( @koha_problems || @es_problems ) ) { >+ >+ print "=================\n"; >+ print "Trying to fix problems:\n\n"; >+ >+ my $indexer; >+ my $server; >+ if ( $index eq 'biblios' ) { >+ $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); >+ $server = 'biblioserver'; >+ } else { >+ $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); >+ $server = 'authorityserver'; >+ } >+ >+ if (@koha_problems) { >+ >+ print "=================\n"; >+ print "Fixing missing records in the index ($index):\n\n"; >+ >+ foreach my $id (@koha_problems) { >+ try { >+ $indexer->update_index( [$id] ); >+ } catch { >+ print STDERR "ERROR: record #$id failed: $_\n\n"; >+ }; >+ } >+ } >+ >+ if (@es_problems) { >+ >+ print "=================\n"; >+ print "Deleting non-existent records from the index ($index)...\n"; >+ >+ $indexer->delete_index( \@es_problems ); >+ } >+ } > } >+ >+1; >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36365
:
178124
|
178178
|
178874
|
179623
|
180724
|
180725