DeleteDomainAliasProvider.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\UI\Client\DomainAlias\Providers;
  3. use ThurData\Servers\KerioEmail\App\Helpers\KerioManager;
  4. use ThurData\Servers\KerioEmail\App\Libs\Product\ProductManager;
  5. use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Services\Delete\DeleteDomainAlias;
  6. use ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
  7. use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
  8. use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
  9. /**
  10. *
  11. * Created by PhpStorm.
  12. * User: ThurData
  13. * Date: 02.10.19
  14. * Time: 14:41
  15. * Class DeleteDomainAliasProvider
  16. */
  17. class DeleteDomainAliasProvider extends BaseDataProvider
  18. {
  19. /**
  20. *
  21. */
  22. public function read()
  23. {
  24. $this->data['id'] = $this->actionElementId;
  25. }
  26. /**
  27. *
  28. */
  29. public function update()
  30. {
  31. // TODO: Implement update() method.
  32. }
  33. /**
  34. * @return HtmlDataJsonResponse|void
  35. */
  36. public function delete()
  37. {
  38. /**
  39. * hosting id
  40. */
  41. $hid = $this->request->get('id');
  42. $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
  43. try {
  44. $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
  45. $domains = $api->getDomains(['id','name','aliasList']);
  46. } catch (KerioApiException $error) {
  47. logModuleCall(
  48. 'kerioEmail',
  49. __FUNCTION__,
  50. $error,
  51. 'Debug Error',
  52. $error->getMessage()
  53. );
  54. return ['error' => $error->getMessage()];
  55. }
  56. foreach($domains as $domain) {
  57. if(($domain['name']) === $this->getWhmcsParamByKey('domain')){
  58. $domainID = $domain['id'];
  59. $domainName = $domain['name'];
  60. $aliasList = $domain['aliasList'];
  61. }
  62. }
  63. $newList = array_values(array_diff($aliasList, [ $this->formData['id']]));
  64. $attr = array('aliasList' => $newList);
  65. try {
  66. $result = $api->modifyDomain($domainID,$attr);
  67. } catch (KerioApiException $error) {
  68. logModuleCall(
  69. 'kerioEmail',
  70. __FUNCTION__,
  71. $error,
  72. 'Debug Error',
  73. $error->getMessage()
  74. );
  75. return ['error' => $error->getMessage()];
  76. }
  77. $api->logout();
  78. return (new HtmlDataJsonResponse())->setMessageAndTranslate('domainAliasHasBeenDeleted')->setStatusSuccess();
  79. }
  80. public function massDelete()
  81. {
  82. /**
  83. *
  84. */
  85. $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
  86. try {
  87. $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
  88. $domains = $api->getDomains(['id','name','aliasList']);
  89. } catch (KerioApiException $error) {
  90. logModuleCall(
  91. 'kerioEmail',
  92. __FUNCTION__,
  93. $error,
  94. 'Debug Error',
  95. $error->getMessage()
  96. );
  97. return ['error' => $error->getMessage()];
  98. }
  99. foreach($domains as $domain) {
  100. if(($domain['name']) === $this->getWhmcsParamByKey('domain')){
  101. $domainID = $domain['id'];
  102. $domainName = $domain['name'];
  103. $aliasList = $domain['aliasList'];
  104. }
  105. }
  106. $newList = array_values(array_diff($aliasList, $this->request->get('massActions')));
  107. $attr = array('aliasList' => $newList);
  108. try {
  109. $result = $api->modifyDomain($domainID,$attr);
  110. } catch (KerioApiException $error) {
  111. logModuleCall(
  112. 'kerioEmail',
  113. __FUNCTION__,
  114. $error,
  115. 'Debug Error',
  116. $error->getMessage()
  117. );
  118. return ['error' => $error->getMessage()];
  119. }
  120. $api->logout();
  121. return (new HtmlDataJsonResponse())
  122. ->setMessageAndTranslate('massDomainAliasHasBeenDeleted')
  123. ->setStatusSuccess();
  124. }
  125. }