From 81347af7219ca934c033179bacc701ab56dc60f5 Mon Sep 17 00:00:00 2001 From: Guillaume ARNOUX Date: Sun, 21 Jan 2024 23:39:37 +0100 Subject: [PATCH] change package --- src/Mailcow.php | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/Mailcow.php b/src/Mailcow.php index dd13427..03f556a 100644 --- a/src/Mailcow.php +++ b/src/Mailcow.php @@ -140,7 +140,7 @@ class Server_Manager_Mailcow extends Server_Manager $p = $a->getPackage(); $client = $a->getClient(); // Prepare POST query - $domaindata = [ + $domainData = [ 'json' => [ "active" => "1", "aliases" => $p->getMaxSubdomains(), @@ -158,7 +158,7 @@ class Server_Manager_Mailcow extends Server_Manager ] ]; // Create domain on mailcow - $result1 = $this->_makeRequest('POST', 'add/domain', $domaindata); + $result1 = $this->_makeRequest('POST', 'add/domain', $domainData); if (str_contains($result1, 'success') { // Create Domain Admin in mailcow $domainAdminData = [ @@ -237,13 +237,13 @@ class Server_Manager_Mailcow extends Server_Manager $p = $a->getPackage(); $client = $a->getClient(); // Prepare POST query - $domaindata = [ + $domainData = [ 'body' => [ $a->getDomain(), ] ]; // Delete domain on mailcow - $result1 = $this->_makeRequest('POST', 'delete/domain', $domaindata); + $result1 = $this->_makeRequest('POST', 'delete/domain', $domainData); if (str_contains($result1, 'success') { // Delete Domain Admin in mailcow $domainAdminData = [ @@ -266,4 +266,31 @@ class Server_Manager_Mailcow extends Server_Manager return true; } + /** + * Change account package on server. + */ + public function changeAccountPackage(Server_Account $a, Server_Package $p) + { + // Prepare POST query + $pacakgeData = [ + 'json' => [ + "attr" => [ + "aliases" => $p->getMaxSubdomains(), + "defquota" => $p->getQuota(), + "mailboxes" => $p->getMaxPop(), + ], + "items" => $a->getDomain(), + ] + ]; + // Edit domain on mailcow + $result = $this->_makeRequest('POST', 'edit/domain', $domainData); + if (!str_contains($result, 'success')) { + $placeholders = [':action:' => __trans('change account package'), ':type:' => 'Mailcow']; + + throw new Server_Exception('Failed to :action: on the :type: server, check the error logs for further details', $placeholders); + } + + return true; + } + }