DeleteEmailAliasDataProvider.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\UI\Client\EmailAlias\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\Models\AccountAlias;
  6. use ThurData\Servers\KerioEmail\Core\Models\Whmcs\Hosting;
  7. use ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
  8. use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
  9. use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
  10. /**
  11. *
  12. * Created by PhpStorm.
  13. * User: ThurData
  14. * Date: 18.09.19
  15. * Time: 12:59
  16. * Class DeleteEmailAliasDataProvider
  17. */
  18. class DeleteEmailAliasDataProvider extends BaseDataProvider
  19. {
  20. public function read()
  21. {
  22. $this->data['id'] = $this->actionElementId;
  23. }
  24. public function update()
  25. {
  26. // TODO: Implement update() method.
  27. }
  28. public function delete()
  29. {
  30. /**
  31. * hosting id
  32. */
  33. $hid = $this->request->get('id');
  34. $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
  35. try {
  36. $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
  37. } catch (KerioApiException $error) {
  38. logModuleCall(
  39. 'kerioEmail',
  40. __FUNCTION__,
  41. $error,
  42. 'Debug Error',
  43. $error->getMessage()
  44. );
  45. return ['error' => $error->getMessage()];
  46. }
  47. try {
  48. $result = $api->deleteAlias($this->formData['id']);
  49. } catch (KerioApiException $error) {
  50. logModuleCall(
  51. 'kerioEmail',
  52. __FUNCTION__,
  53. $error,
  54. 'Debug Error',
  55. $error->getMessage()
  56. );
  57. return ['error' => $error->getMessage()];
  58. }
  59. logModuleCall(
  60. 'kerioEmail',
  61. __FUNCTION__,
  62. $this->formData['id'],
  63. 'Debug Error',
  64. $result
  65. );
  66. $api->logout();
  67. $productManager = new ProductManager();
  68. $productManager->loadByHostingId($hid);
  69. return (new HtmlDataJsonResponse())->setMessageAndTranslate('emailAliasHasBeenDeleted')->setStatusSuccess();
  70. }
  71. public function massDelete()
  72. {
  73. /**
  74. * hosting id
  75. */
  76. $hid = $this->request->get('id');
  77. /**
  78. * product manager allow to check product settings
  79. */
  80. $productManager = new ProductManager();
  81. $productManager->loadByHostingId($hid);
  82. /**
  83. *
  84. * get soap create alias service
  85. * set service configuration
  86. */
  87. $service = (new KerioManager())
  88. ->getApiByHosting($hid)
  89. ->soap
  90. ->service()
  91. ->deleteAccountAlias();
  92. foreach ($this->request->get('massActions') as $endodedData)
  93. {
  94. $data = json_decode(base64_decode($endodedData), true);
  95. $data['id'] = $data['accId'];
  96. $service->setFormData($data);
  97. $result = $service->run();
  98. }
  99. return (new HtmlDataJsonResponse())->setMessageAndTranslate('massEmailAliasHasBeenDeleted')->setStatusSuccess();
  100. }
  101. }