From f7b5af15c48878bea67f9d0e6038daf697f456c7 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 30 Apr 2008 15:45:42 -0500 Subject: [PATCH] added reindexing routine to KohaTest KohaTest->reindex_marc() does a full Zebra reindexing of bib and authority records and clears zebraqueue. It is meant for use in test classes that do a lot of bib, authority, and/or item record changes that would be slowed down by waiting for zebraqueue_daemon. Also adjusted list of tables that are automatically truncated. Signed-off-by: Joshua Ferraro --- t/lib/KohaTest.pm | 48 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/t/lib/KohaTest.pm b/t/lib/KohaTest.pm index 0a21b2117c..cb89d6b2bc 100644 --- a/t/lib/KohaTest.pm +++ b/t/lib/KohaTest.pm @@ -15,6 +15,7 @@ use C4::Context; use C4::Items; use C4::Members; use C4::Search; +use File::Temp qw/ tempdir /; # Since this is an abstract base class, this prevents these tests from # being run directly unless we're testing a subclass. It just makes @@ -154,11 +155,8 @@ sub startup_15_truncate_tables : Test( startup => 1 ) { deletedborrowers deleteditems ethnicity - import_items - import_record_matches issues issuingrules - items labels labels_profile matchchecks @@ -393,4 +391,48 @@ sub add_biblios { } +=head3 reindex_bibs + +Do a fast reindexing of all of the bib and authority +records and mark all zebraqueue entries done. + +Useful for test routines that need to do a +lot of indexing without having to wait for +zebraqueue. + +In NoZebra model, this only marks zebraqueue +done - the records should already be indexed. + +=cut + +sub reindex_marc { + my $self = shift; + + # mark zebraqueue done regardless of the indexing mode + my $dbh = C4::Context->dbh(); + $dbh->do("UPDATE zebraqueue SET done = 1 WHERE done = 0"); + + return if C4::Context->preference('NoZebra'); + + my $directory = tempdir(CLEANUP => 1); + foreach my $record_type qw(biblio authority) { + mkdir "$directory/$record_type"; + my $sth = $dbh->prepare($record_type eq "biblio" ? "SELECT marc FROM biblioitems" : "SELECT marc FROM auth_header"); + $sth->execute(); + open OUT, ">:utf8", "$directory/$record_type/records"; + while (my ($blob) = $sth->fetchrow_array) { + print OUT $blob; + } + close OUT; + my $zebra_server = "${record_type}server"; + my $zebra_config = C4::Context->zebraconfig($zebra_server)->{'config'}; + my $zebra_db_dir = C4::Context->zebraconfig($zebra_server)->{'directory'}; + my $zebra_db = $record_type eq 'biblio' ? 'biblios' : 'authorities'; + system "zebraidx -c $zebra_config -d $zebra_db -g iso2709 init > /dev/null 2>\&1"; + system "zebraidx -c $zebra_config -d $zebra_db -g iso2709 update $directory/${record_type} > /dev/null 2>\&1"; + system "zebraidx -c $zebra_config -d $zebra_db -g iso2709 commit > /dev/null 2>\&1"; + } + +} + 1; -- 2.39.5