| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- namespace ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Services\Update;
- use ModulesGarden\Servers\KerioEmail\App\Enums\ProductParams;
- use ModulesGarden\Servers\KerioEmail\App\Enums\Kerio;
- use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Interfaces\ApiService;
- use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Account;
- use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\ClassOfService;
- /**
- *
- * Created by PhpStorm.
- * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
- * Date: 07.11.19
- * Time: 14:00
- * Class ChangePackageDedicatedCos
- */
- class ChangePackageDedicatedCos extends ChangePackage
- {
- protected $cosModels = [];
- /**
- *
- */
- public function config()
- {
- $this->cosModels = $this->api->repository()->cos->all();
- parent::config(); // TODO: Change the autogenerated stub
- }
- /**
- * @return bool
- */
- public function isValid()
- {
- /**
- *
- */
- if(!$this->formData['domain'])
- {
- $this->setError('Domain name can not be found.');
- return false;
- }
- /**
- * if cos doesn't exists
- */
- if(!$this->productManager->getSettingCos())
- {
- $this->setError('Can not found class of service Id');
- return false;
- }
- /**
- * invalid id format
- */
- if(!is_string($this->productManager->getSettingCos()))
- {
- $this->setError('Invalid class of service ID format');
- return false;
- }
- return parent::isValid();
- }
- /**
- * @return bool|mixed
- */
- public function process()
- {
- $accounts = $this->api->repository()->accounts->getByDomainName($this->formData['domain']);
- foreach($accounts as $account)
- {
- /* @var $account Account*/
- /* @var $cos ClassOfService*/
- $cos = $this->cosModels[$this->productManager->getSettingCos()];
- /**
- * set quota by class of service
- */
- $account->setAttr(Account::ATTR_MAIL_QUOTA, $cos->getDataResourceA(Account::ATTR_MAIL_QUOTA));
- /**
- * define class of services attribute for account
- */
- $cosAttrs = $cos->getAllDataResourcesAAttributes();
- foreach(Kerio::BASE_ACCOUNT_CONFIG as $key)
- {
- $value = $cosAttrs[$key] ? $cosAttrs[$key] : Kerio::ATTR_DISABLED;
- $account->setAttr($key, $value);
- }
- /**
- *
- * set class of service id as account attribute
- */
- $account->setAttr(Account::ATTR_CLASS_OF_SERVICE_ID, $cos->getId());
- /**
- * update account
- */
- $result = $this->api->account->update($account);
- if(!$result)
- {
- //todo
- }
- }
- return true;
- }
- }
|