use EmailAccounts.delete API call in Emails.delete instead of repeating the code

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2019-06-28 11:07:29 +02:00
parent 5dfb74701c
commit e209989f2a

View File

@@ -340,26 +340,12 @@ class Emails extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\ResourceEnt
} }
// check whether this address is an account // check whether this address is an account
if ($result['popaccountid'] != 0) { if ($result['popaccountid'] != 0) {
// Free the Quota used by the email account // use EmailAccounts.delete
if (Settings::Get('system.mail_quota_enabled') == 1) { $this->apiCall('EmailAccounts.delete', array(
$stmt = Database::prepare("SELECT `quota` FROM `" . TABLE_MAIL_USERS . "` WHERE `customerid`= :customerid AND `id`= :id"); 'id' => $result['id'],
$res_quota = Database::pexecute_first($stmt, array( 'customerid' => $customer['customerid'],
"customerid" => $customer['customerid'], 'delete_userfiles' => $delete_userfiles
"id" => $result['popaccountid'] ));
), true, true);
Customers::decreaseUsage($customer['customerid'], 'email_quota_used', '', $res_quota['quota']);
Admins::decreaseUsage($customer['customerid'], 'email_quota_used', '', $res_quota['quota']);
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_INFO, "[API] deleted quota entries for email address '" . $result['email_full'] . "'");
}
// delete account
$stmt = Database::prepare("DELETE FROM `" . TABLE_MAIL_USERS . "` WHERE `customerid`= :customerid AND `id`= :id");
Database::pexecute($stmt, array(
"customerid" => $customer['customerid'],
"id" => $result['popaccountid']
), true, true);
Customers::decreaseUsage($customer['customerid'], 'email_accounts_used');
Admins::decreaseUsage($customer['customerid'], 'email_accounts_used');
$this->logger()->logAction($this->isAdmin() ? \Froxlor\FroxlorLogger::ADM_ACTION : \Froxlor\FroxlorLogger::USR_ACTION, LOG_INFO, "[API] deleted email account '" . $result['email_full'] . "'");
$number_forwarders --; $number_forwarders --;
} }