#!/bin/sh
#
# koha-upgrade-to-3.4 - performs the necessary changes to upgrade a Koha
# system from 3.2 to 3.4
#
# Copyright 2011  Catalyst IT, Ltd
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

TO_UPGRADE=$@

if [ -z "$TO_UPGRADE" ] ;
then
    TO_UPGRADE=`koha-list`
fi

if [ -z "$TO_UPGRADE" ] ;
then
    echo "No Koha instances were found to upgrade."
    exit
fi

cat <<EOH
Koha will be upgraded for the following instances: $TO_UPGRADE

This may take some time to run. Go make a coffee.
EOH

for name in $TO_UPGRADE
do
    echo "Upgrading $name..."
    sudo -u "$name-koha" -H \
        env PERL5LIB=/usr/share/koha/lib \
        KOHA_CONF="/etc/koha/sites/$name/koha-conf.xml" \
        /usr/share/koha/bin/maintenance/remove_items_from_biblioitems.pl --run
    echo "Rebuilding zebra for $name..."
    koha-rebuild-zebra --full -v -u $name
done
