CreateAccount.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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\Libs\Kerio\Components\Api\Soap\Models\Domain;
  7. use ThurData\Servers\KerioEmail\App\Traits\ExtensionsCheckerTrait;
  8. use ThurData\Servers\KerioEmail\Core\App\Controllers\Instances\AddonController;
  9. use ThurData\Servers\KerioEmail\App\Traits\HostingService;
  10. use \ThurData\Servers\KerioEmail\Core\UI\Traits\WhmcsParams;
  11. /**
  12. *
  13. * Created by PhpStorm.
  14. * User: ThurData
  15. * Date: 09.09.19
  16. * Time: 15:14
  17. * Class CreateAccount
  18. */
  19. class CreateAccount extends AddonController
  20. {
  21. use ExtensionsCheckerTrait;
  22. use HostingService;
  23. use WhmcsParams;
  24. /**
  25. * create domain in kerio
  26. *
  27. * @param null $params
  28. * @return string
  29. */
  30. public function execute($params = null)
  31. {
  32. try{
  33. /**
  34. * check if extensions are installed
  35. */
  36. $this->checkExtensionOrThrowError();
  37. //update domain
  38. if($params['customfields']['maildomain']){
  39. $params['domain'] = $params['customfields']['maildomain'];
  40. $this->hosting()->domain = $params['domain'];
  41. $this->hosting()->save();
  42. }
  43. /**
  44. * run kerio service
  45. */
  46. $result = $this->kerioRunService($params);
  47. return $result;
  48. }catch (\Exception $ex)
  49. {
  50. /**
  51. * return some crit error
  52. */
  53. return $ex->getMessage();
  54. }
  55. }
  56. /**
  57. * @param null $params
  58. * @return mixed|string
  59. */
  60. protected function kerioRunService($params = null)
  61. {
  62. /**
  63. *
  64. * get soap create domain service
  65. */
  66. $service =(new KerioManager())
  67. ->getApiByServer($params['serverid'])
  68. ->soap
  69. ->service()
  70. ->createDomain();
  71. /**
  72. * product manager allow to check product settings
  73. */
  74. $productManager = new ProductManager();
  75. $productManager->loadByHostingId($params['serviceid']);
  76. /**
  77. *
  78. * set params
  79. * run service (Create domain in Kerio API)
  80. */
  81. $result = $service
  82. ->setProductManager($productManager)
  83. ->setFormData($params)
  84. ->run();
  85. /**
  86. * check service result & return error
  87. */
  88. if(!$result)
  89. {
  90. return $service->getError();
  91. }
  92. /**
  93. * return success response
  94. */
  95. return Response::SUCCESS;
  96. }
  97. }