File: //usr/local/mailchannels/hooks/PostAccountsModify.php
<?php
namespace MailChannels;
//For the Whostmgr modify function, we provision the domain name in this post hook
//because in the pre hook we are not able to properly provision this domain name until the modify function executes and the
//new main domain name is associated with the account.
//There is a chance that the new main domain has different protection than the old main domain (ex: the old domain was unprotected
//but the new main domain is protected) since we cannot determine if the old domain was protected or not, and therefore rely on
//the status of inboundEnabled and isAutomaticDomainProtectionEnabled for the new domain name.
class PostAccountsModify extends PostAccountsCreate {
public function execute($hookData) {
if ($this->inboundEnabled()) {
if (!isset($hookData['data']) || !isset($hookData['data']['domain'])) {
return array(true, "no domain parameter");
}
$newMainDomain = $hookData['data']['domain'];
if ($this->inboundConfig->isAutomaticDomainProtectionEnabled()) {
try {
list($provisionResult, $provisionMessage) = $this->inboundProvision($newMainDomain);
} catch (\Exception $e) {
$errorMessage = $e->getTraceAsString();
return array(false, "error provisioning domain $newMainDomain: $errorMessage");
}
if ($provisionResult) {
return array(true, "successfully provisioned new main domain $newMainDomain");
} else {
return array(false, "error provisioning new main domain $newMainDomain: $provisionMessage");
}
}
return array(true, "provisioning action not taken; AutomaticDomainProtection not enabled");
}
return array(true, "provisioning action not taken; inbound not enabled");
}
public static function category() {
return 'Whostmgr';
}
public static function event() {
return 'Accounts::Modify';
}
public static function stage() {
return 'post';
}
}