| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- namespace ThurData\Servers\KerioEmail\App\UI\Client\DomainAlias\Providers;
- use ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
- use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
- use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
- /**
- *
- * Created by PhpStorm.
- * User: ThurData
- * Date: 02.10.19
- * Time: 14:41
- * Class DeleteDomainAliasProvider
- */
- class DeleteDomainAliasProvider extends BaseDataProvider
- {
- /**
- *
- */
- public function read()
- {
- $this->data['id'] = $this->actionElementId;
- }
- /**
- *
- */
- public function update()
- {
- // TODO: Implement update() method.
- }
- /**
- * @return HtmlDataJsonResponse|void
- */
- public function delete()
- {
- $maildomain = $this->getWhmcsParamByKey('domain');
- $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
- try {
- $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
- $domains = $api->getDomains(['id','name','aliasList']);
- } catch (KerioApiException $error) {
- logModuleCall(
- 'kerioEmail',
- __FUNCTION__,
- $error,
- 'Debug Error',
- $error->getMessage()
- );
- return ['error' => $error->getMessage()];
- }
- foreach($domains as $domain) {
- if($domain['name'] === $maildomain){
- $domainID = $domain['id'];
- $aliasList = $domain['aliasList'];
- }
- }
- $newList = array_values(array_diff($aliasList, [ $this->formData['id']]));
- $attr = array('aliasList' => $newList);
- try {
- $result = $api->modifyDomain($domainID,$attr);
- } catch (KerioApiException $error) {
- logModuleCall(
- 'kerioEmail',
- __FUNCTION__,
- $error,
- 'Debug Error',
- $error->getMessage()
- );
- return ['error' => $error->getMessage()];
- }
- $api->logout();
- return (new HtmlDataJsonResponse())->setMessageAndTranslate('domainAliasHasBeenDeleted')->setStatusSuccess();
- }
- public function massDelete()
- {
- $maildomain = $this->getWhmcsParamByKey('domain');
- $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
- try {
- $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
- $domains = $api->getDomains(['id','name','aliasList']);
- } catch (KerioApiException $error) {
- logModuleCall(
- 'kerioEmail',
- __FUNCTION__,
- $error,
- 'Debug Error',
- $error->getMessage()
- );
- return ['error' => $error->getMessage()];
- }
- foreach($domains as $domain) {
- if($domain['name'] === $maildomain){
- $domainID = $domain['id'];
- $aliasList = $domain['aliasList'];
- }
- }
- $newList = array_values(array_diff($aliasList, $this->request->get('massActions')));
- $attr = array('aliasList' => $newList);
- try {
- $result = $api->modifyDomain($domainID,$attr);
- } catch (KerioApiException $error) {
- logModuleCall(
- 'kerioEmail',
- __FUNCTION__,
- $error,
- 'Debug Error',
- $error->getMessage()
- );
- return ['error' => $error->getMessage()];
- }
- $api->logout();
- return (new HtmlDataJsonResponse())
- ->setMessageAndTranslate('massDomainAliasHasBeenDeleted')
- ->setStatusSuccess();
- }
- }
|