DeleteEmailAliasDataProvider.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. $api->logout();
  60. $productManager = new ProductManager();
  61. $productManager->loadByHostingId($hid);
  62. return (new HtmlDataJsonResponse())->setMessageAndTranslate('emailAliasHasBeenDeleted')->setStatusSuccess();
  63. }
  64. public function massDelete()
  65. {
  66. /**
  67. * hosting id
  68. */
  69. $hid = $this->request->get('id');
  70. /**
  71. * product manager allow to check product settings
  72. */
  73. $productManager = new ProductManager();
  74. $productManager->loadByHostingId($hid);
  75. foreach ($this->request->get('massActions') as $endodedData)
  76. {
  77. logModuleCall(
  78. 'kerioEmail',
  79. __FUNCTION__,
  80. $endodedData,
  81. 'Debug Error',
  82. ''
  83. );
  84. }
  85. return (new HtmlDataJsonResponse())->setMessageAndTranslate('massEmailAliasHasBeenDeleted')->setStatusSuccess();
  86. }
  87. }