#!/bin/sh
set -e

. /usr/share/debconf/confmodule
. /usr/share/dbconfig-common/dpkg/prerm.mysql

# See the comment in debian/postinst: dbconfig-common does not expect the
# caller to run with "set -e", and a debconf protocol error status there must
# not abort the removal (Debian bug #1121130). A status of 1 means the
# administrator chose "abort", which asks to leave the database alone, not to
# make the package impossible to remove, so nothing here is fatal either.
run_dbc_go() {
	set +e
	dbc_go phpmyadmin $@
	dbc_go_status=$?
	set -e
	if [ "$dbc_go_status" -eq 1 ]; then
		echo "WARNING: phpMyAdmin's database cleanup was aborted at the administrator's request." >&2
		echo "WARNING: the database was left untouched; drop it by hand if it is no longer needed." >&2
	elif [ "$dbc_go_status" -ne 0 ]; then
		echo "WARNING: dbconfig-common failed while preparing phpMyAdmin's database cleanup (status $dbc_go_status)." >&2
		echo "WARNING: continuing so that dpkg can complete this operation." >&2
	fi
}

run_dbc_go "$@"

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
