ChangePackage.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\Http\Actions;
  3. use ThurData\Servers\KerioEmail\App\Enums\Response;
  4. use ThurData\Servers\KerioEmail\App\Helpers\KerioManager;
  5. use ThurData\Servers\KerioEmail\App\Libs\Product\ProductManager;
  6. use ThurData\Servers\KerioEmail\App\Traits\ExtensionsCheckerTrait;
  7. use ThurData\Servers\KerioEmail\Core\App\Controllers\Instances\AddonController;
  8. use ThurData\Servers\KerioEmail\App\Models\ProductConfiguration;
  9. use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
  10. use ThurData\Servers\KerioEmail\Core\Helper\ConfigOptionsHelper;
  11. use ThurData\Servers\KerioEmail\Core\Helper\UpdateLimit;
  12. /**
  13. *
  14. * Created by PhpStorm.
  15. * User: ThurData
  16. * Date: 09.09.19
  17. * Time: 15:15
  18. * Class ChangePackage
  19. */
  20. class ChangePackage extends AddonController
  21. {
  22. use ExtensionsCheckerTrait;
  23. /**
  24. * @param null $params
  25. * @return string|void
  26. */
  27. public function execute($params = null)
  28. {
  29. try{
  30. /**
  31. * check if extensions are installed
  32. */
  33. $this->checkExtensionOrThrowError();
  34. /**
  35. * run kerio service
  36. */
  37. $result = $this->kerioRunService($params);
  38. return $result;
  39. }catch (\Exception $ex)
  40. {
  41. /**
  42. * return some crit error
  43. */
  44. return $ex->getMessage();
  45. }
  46. }
  47. /**
  48. * @param null $params
  49. * @return string
  50. */
  51. protected function kerioRunService($params = null)
  52. {
  53. $productManager = new ProductManager();
  54. $productManager->loadById($params['pid']);
  55. $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
  56. try {
  57. $api->login($params['serverhostname'], $params['serverusername'], $params['serverpassword']);
  58. $result = $api->getDomains(['name', 'id']);
  59. } catch (KerioApiException $error) {
  60. logModuleCall(
  61. 'kerioEmail',
  62. __FUNCTION__,
  63. $error,
  64. 'Debug Error',
  65. $error->getMessage()
  66. );
  67. return ['error' => $error->getMessage()];
  68. }
  69. logModuleCall(
  70. 'kerioEmail',
  71. __FUNCTION__,
  72. $result,
  73. 'Debug ChangePackage',
  74. $params
  75. );
  76. $api->logout();
  77. return Response::SUCCESS;
  78. }
  79. }