DeleteAccountDataProvider.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\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\DeleteAccount;
  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: 18.09.19
  14. * Time: 11:28
  15. * Class DeleteAccountDataProvider
  16. */
  17. class DeleteAccountDataProvider extends BaseDataProvider
  18. {
  19. public function read()
  20. {
  21. $this->data['id'] = $this->actionElementId;
  22. }
  23. public function update()
  24. {
  25. // TODO: Implement update() method.
  26. }
  27. public function delete()
  28. {
  29. /**
  30. * hosting id
  31. */
  32. $hid = $this->request->get('id');
  33. /**
  34. * product manager allow to check product settings
  35. */
  36. $productManager = new ProductManager();
  37. $productManager->loadByHostingId($hid);
  38. $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
  39. try {
  40. $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
  41. } catch (KerioApiException $error) {
  42. logModuleCall(
  43. 'kerioEmail',
  44. __FUNCTION__,
  45. $error,
  46. 'Debug Error',
  47. $error->getMessage()
  48. );
  49. return ['error' => $error->getMessage()];
  50. }
  51. try {
  52. $api->deleteUser($this->formData['id']);
  53. } catch (KerioApiException $error) {
  54. logModuleCall(
  55. 'kerioEmail',
  56. __FUNCTION__,
  57. $error,
  58. 'Debug Error',
  59. $error->getMessage()
  60. );
  61. return ['error' => $error->getMessage()];
  62. }
  63. $api->logout();
  64. return (new HtmlDataJsonResponse())->setMessageAndTranslate('emailAccountHasBeenDeleted')->setStatusSuccess();
  65. }
  66. public function massDelete()
  67. {
  68. /**
  69. * hosting id
  70. */
  71. $hid = $this->request->get('id');
  72. /**
  73. * product manager allow to check product settings
  74. */
  75. $productManager = new ProductManager();
  76. $productManager->loadByHostingId($hid);
  77. $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
  78. try {
  79. $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
  80. } catch (KerioApiException $error) {
  81. logModuleCall(
  82. 'kerioEmail',
  83. __FUNCTION__,
  84. $error,
  85. 'Debug Error',
  86. $error->getMessage()
  87. );
  88. return ['error' => $error->getMessage()];
  89. }
  90. /**
  91. *
  92. */
  93. foreach($this->request->get('massActions') as $id)
  94. {
  95. try {
  96. $api->deleteUser($id);
  97. } catch (KerioApiException $error) {
  98. logModuleCall(
  99. 'kerioEmail',
  100. __FUNCTION__,
  101. $error,
  102. 'Debug Error',
  103. $error->getMessage()
  104. );
  105. return ['error' => $error->getMessage()];
  106. }
  107. }
  108. $api->logout();
  109. return (new HtmlDataJsonResponse())->setMessageAndTranslate('massEmailAccountHasBeenDeleted')->setStatusSuccess();
  110. }
  111. }