From 39d3b9088a34b464708e40d1fd20a954d4a6e702 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 30 Apr 2013 11:58:25 -0300 Subject: [PATCH] Bug 10159 - koha-rebuild-zebra error handling MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch makes koha-rebuild-zebra: - Check for the existence of the instance - Handle arbitrary amount of instance parameters - Capture -a and -b (which made the script rebuild twice the chosen DB). It adds the extended version (--authorities and --biblios respectively) of the option switch. This makes the -a and -b switches work as "only do authorities" (or viceversa). They can be used concurrently, which is the default behaviour when no switch is provided. - Handle -v (and --verbose) as koha-rebuild-zebra options, to ease the use for non-techie users. - The rebuild_zebra.pl is wrapped inside an IF to return error values if we ever make rebuild_zebra.pl return error codes (this is pointed in the code). - Added -h/--help switches and an 'usage' output :-D Please provide patches for any wording issues, or contact me to fix it. To test: - Apply the patch and create your packages (or just use the script from your branch) - Run it in this scenarios / options - -h/--help to see the available option switches - Mix them with one or more instances, of which some could be fake - try -a/--authorities and -b/--biblios in all possible combinations - try -v/--verbose works Regards To+ Sponsored-by: Universidad Nacional de Córdoba Signed-off-by: Robin Sheat Signed-off-by: Jared Camins-Esakov --- debian/docs/koha-rebuild-zebra.xml | 26 +++++- debian/scripts/koha-rebuild-zebra | 143 +++++++++++++++++++++++++---- 2 files changed, 147 insertions(+), 22 deletions(-) diff --git a/debian/docs/koha-rebuild-zebra.xml b/debian/docs/koha-rebuild-zebra.xml index b8ce51cac3..410be8abad 100644 --- a/debian/docs/koha-rebuild-zebra.xml +++ b/debian/docs/koha-rebuild-zebra.xml @@ -17,13 +17,13 @@ koha-rebuild-zebra - Rebuild the Zebra database for a Koha instance. + Rebuild the Zebra database for Koha instances. UNIX/Linux - koha-rebuild-zebra | | instancename + koha-rebuild-zebra | | | | | instancename @@ -41,17 +41,35 @@ Does a reindex of the whole collection. + + + + Only run the indexing process for authority records. + + + + + + Only run the indexing process for biblio records. + + + + + + Be verbose. Useful for debugging indexing problems. + + - Anything else is passed directly to rebuild_zebra. This is useful in particular for -v. + Anything else is passed directly to rebuild_zebra. Description - Rebuild the Zebra database for a Koha instance. + Rebuild the Zebra database for Koha instances. See also diff --git a/debian/scripts/koha-rebuild-zebra b/debian/scripts/koha-rebuild-zebra index b4478fd5d2..f32ca8bbdb 100755 --- a/debian/scripts/koha-rebuild-zebra +++ b/debian/scripts/koha-rebuild-zebra @@ -1,6 +1,6 @@ #!/bin/sh # -# koha-rebuild-zebra -- Rebuild the Zebra database for a Koha instance. +# koha-rebuild-zebra - Rebuild the Zebra database for Koha instances. # Copyright 2010 Catalyst IT, Ltd # # This program is free software: you can redistribute it and/or modify @@ -19,18 +19,117 @@ set -e +die() +{ + echo "$@" 1>&2 + exit 1 +} + +warn() +{ + echo "$@" 1>&2 +} + +is_instance() +{ + local instancename=$1 + + if find /etc/koha/sites -mindepth 1 -maxdepth 1 \ + -type d -printf '%f\n'\ + | grep -q -x $instancename ; then + return 0 + else + return 1 + fi +} + +toggle_biblios_only() +{ + biblios_only="yes" + biblios="yes" + if [ "$authorities_only" != "yes" ]; then + authorities="no" + fi +} + +toggle_authorities_only() +{ + authorities_only="yes" + authorities="yes" + if [ "$biblios_only" != "yes" ]; then + biblios="no" + fi +} + +run_rebuild_zebra() +{ + local instancename=$1; shift + + # TODO: This comment is here to remind us that we should make + # rebuild_zebra.pl return error codes on failure + if sudo -u "$instancename-koha" -H \ + env PERL5LIB=/usr/share/koha/lib \ + KOHA_CONF="/etc/koha/sites/$instancename/koha-conf.xml" \ + /usr/share/koha/bin/migration_tools/rebuild_zebra.pl $@ ; then + return 0 + else + return 1 + fi +} + +usage() +{ + local scriptname=$0 + cat <