DeleteDomainAliasProvider.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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_diff($aliasList, [ $this->formData['id']]);
  64. logModuleCall(
  65. 'kerioEmail',
  66. __FUNCTION__,
  67. $aliasList,
  68. 'Debug Error',
  69. $newList
  70. );
  71. return (new HtmlDataJsonResponse())->setMessageAndTranslate('domainAliasHasBeenDeleted')->setStatusSuccess();
  72. }
  73. public function massDelete()
  74. {
  75. /**
  76. * hosting id
  77. */
  78. $hid = $this->request->get('id');
  79. /**
  80. * load product configuration
  81. */
  82. $productManager = new ProductManager();
  83. $productManager->loadByHostingId($hid);
  84. /**
  85. * load kerio manager by hosting id
  86. */
  87. $service = (new KerioManager())
  88. ->getApiByHosting($hid)
  89. ->soap
  90. ->service()
  91. ->deleteDomainAlias();
  92. /**
  93. *
  94. */
  95. foreach($this->request->get('massActions') as $id)
  96. {
  97. $service->setFormData(['id' => $id]);
  98. $result = $service->run();
  99. }
  100. return (new HtmlDataJsonResponse())
  101. ->setMessageAndTranslate('massDomainAliasHasBeenDeleted')
  102. ->setStatusSuccess();
  103. }
  104. }