DeleteRessourceDataProvider.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\UI\Client\Ressource\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\DeleteRessource;
  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 DeleteRessourceDataProvider
  16. */
  17. class DeleteRessourceDataProvider 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. $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
  30. try {
  31. $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
  32. } catch (KerioApiException $error) {
  33. logModuleCall(
  34. 'kerioEmail',
  35. __FUNCTION__,
  36. $error,
  37. 'Debug Error',
  38. $error->getMessage()
  39. );
  40. return ['error' => $error->getMessage()];
  41. }
  42. try {
  43. $api->delResouce($this->formData['id']);
  44. } catch (KerioApiException $error) {
  45. logModuleCall(
  46. 'kerioEmail',
  47. __FUNCTION__,
  48. $error,
  49. 'Debug Error',
  50. $error->getMessage()
  51. );
  52. return ['error' => $error->getMessage()];
  53. }
  54. $api->logout();
  55. return (new HtmlDataJsonResponse())->setMessageAndTranslate('ressourceHasBeenDeleted')->setStatusSuccess();
  56. }
  57. public function massDelete()
  58. {
  59. $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
  60. try {
  61. $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
  62. } catch (KerioApiException $error) {
  63. logModuleCall(
  64. 'kerioEmail',
  65. __FUNCTION__,
  66. $error,
  67. 'Debug Error',
  68. $error->getMessage()
  69. );
  70. return ['error' => $error->getMessage()];
  71. }
  72. foreach($this->request->get('massActions') as $id)
  73. {
  74. try {
  75. $api->delResouce($id);
  76. } catch (KerioApiException $error) {
  77. logModuleCall(
  78. 'kerioEmail',
  79. __FUNCTION__,
  80. $error,
  81. 'Debug Error',
  82. $error->getMessage()
  83. );
  84. return ['error' => $error->getMessage()];
  85. }
  86. }
  87. $api->logout();
  88. return (new HtmlDataJsonResponse())->setMessageAndTranslate('massRessourceHasBeenDeleted')->setStatusSuccess();
  89. }
  90. }