File: //usr/local/mailchannels/bin/uninstall.php
<?php
namespace MailChannels;
$bootFile = "/usr/local/mailchannels/boot.php";
if (!file_exists($bootFile)) {
return;
}
$loadFile = "/usr/local/mailchannels/load.php";
if (!file_exists($loadFile)) {
return;
}
const OUTBOUND_CONFIG_DETECTED_MESSAGE = "We've detected that you have MailChannels Outbound filtering configured. Would" .
" you like to restore your outbound email configuration to what it was before the plugin was installed (you will no" .
" longer filter outbound email through MailChannels)?";
const REMOVING_HOOKS_START_MESSAGE = "Removing hooks...";
const REMOVING_OUTBOUND_START_MESSAGE = "Removing MailChannels outbound email filtering...";
const USER_INPUT_YES_NO_MESSAGE = "(yes / no ): ";
const FAILED_OUTBOUND_ROUTER_REMOVE_MESSAGE = "Failed to remove the MailChannels Router section from the exim configuration";
const FAILED_OUTBOUND_TRANSPORT_REMOVE_MESSAGE = "Failed to remove the MailChannels Transport section from the exim configuration";
const FAILED_OUTBOUND_AUTH_REMOVE_MESSAGE = "Failed to remove the MailChannels Auth section from the exim configuration";
const REMOVED_OUTBOUND_SUCCESS = "MailChannels outbound email filtering removed";
ini_set("error_log", "/var/log/mailchannels/php-error.log");
require_once($bootFile);
Config::$CONFIG_CLASS = 'MailChannels\UninstallConfig';
require_once($loadFile);
$config = App::getConfig();
$purge = false;
foreach ($argv as $arg) {
if ($arg === '--purge') {
$purge = true;
}
}
//Register hooks
$hookRegister = new HookRegister($config::HOOKS);
echo REMOVING_HOOKS_START_MESSAGE . "\n";
$out = $hookRegister->deleteHooks();
$outboundSMTPService = ServiceSelector::getService(OutboundSMTPService::class);
if (! $outboundSMTPService instanceof OutboundSMTPService) {
App::getLogger()->error("No OutboundSMTPService set in the ServiceSelector");
echo "An error occurred while trying to detect the state of the outbound email configuration, please check the logs";
exit(1);
}
if ($outboundSMTPService->isMailServerConfigured()) {
if (!$purge) {
echo OUTBOUND_CONFIG_DETECTED_MESSAGE . "\n";
$input = readline(USER_INPUT_YES_NO_MESSAGE);
}
if ($purge || strtolower($input) === 'yes') {
echo REMOVING_OUTBOUND_START_MESSAGE . "\n";
$outboundSMTPService->unConfigureMailServer();
echo REMOVED_OUTBOUND_SUCCESS . "\n";
}
}
if (!empty($out)) {
echo "\n";
foreach ($out as $o) {
echo "$o\n";
}
}