CreateAccount.php 2.6 KB

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