ChangePackageDedicatedCos.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Services\Update;
  3. use ModulesGarden\Servers\KerioEmail\App\Enums\ProductParams;
  4. use ModulesGarden\Servers\KerioEmail\App\Enums\Kerio;
  5. use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Interfaces\ApiService;
  6. use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Account;
  7. use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\ClassOfService;
  8. /**
  9. *
  10. * Created by PhpStorm.
  11. * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
  12. * Date: 07.11.19
  13. * Time: 14:00
  14. * Class ChangePackageDedicatedCos
  15. */
  16. class ChangePackageDedicatedCos extends ChangePackage
  17. {
  18. protected $cosModels = [];
  19. /**
  20. *
  21. */
  22. public function config()
  23. {
  24. $this->cosModels = $this->api->repository()->cos->all();
  25. parent::config(); // TODO: Change the autogenerated stub
  26. }
  27. /**
  28. * @return bool
  29. */
  30. public function isValid()
  31. {
  32. /**
  33. *
  34. */
  35. if(!$this->formData['domain'])
  36. {
  37. $this->setError('Domain name can not be found.');
  38. return false;
  39. }
  40. /**
  41. * if cos doesn't exists
  42. */
  43. if(!$this->productManager->getSettingCos())
  44. {
  45. $this->setError('Can not found class of service Id');
  46. return false;
  47. }
  48. /**
  49. * invalid id format
  50. */
  51. if(!is_string($this->productManager->getSettingCos()))
  52. {
  53. $this->setError('Invalid class of service ID format');
  54. return false;
  55. }
  56. return parent::isValid();
  57. }
  58. /**
  59. * @return bool|mixed
  60. */
  61. public function process()
  62. {
  63. $accounts = $this->api->repository()->accounts->getByDomainName($this->formData['domain']);
  64. foreach($accounts as $account)
  65. {
  66. /* @var $account Account*/
  67. /* @var $cos ClassOfService*/
  68. $cos = $this->cosModels[$this->productManager->getSettingCos()];
  69. /**
  70. * set quota by class of service
  71. */
  72. $account->setAttr(Account::ATTR_MAIL_QUOTA, $cos->getDataResourceA(Account::ATTR_MAIL_QUOTA));
  73. /**
  74. * define class of services attribute for account
  75. */
  76. $cosAttrs = $cos->getAllDataResourcesAAttributes();
  77. foreach(Kerio::BASE_ACCOUNT_CONFIG as $key)
  78. {
  79. $value = $cosAttrs[$key] ? $cosAttrs[$key] : Kerio::ATTR_DISABLED;
  80. $account->setAttr($key, $value);
  81. }
  82. /**
  83. *
  84. * set class of service id as account attribute
  85. */
  86. $account->setAttr(Account::ATTR_CLASS_OF_SERVICE_ID, $cos->getId());
  87. /**
  88. * update account
  89. */
  90. $result = $this->api->account->update($account);
  91. if(!$result)
  92. {
  93. //todo
  94. }
  95. }
  96. return true;
  97. }
  98. }