checkConfigOrLoadFromPrevious($this->getRequestValue('id')); $this->loadDefaultData(); $this->overrideDefaultDataByProductConfig(); } /** * */ public function update() { $this->catchFormData(); $cos = $this->formData['cos']; unset($this->formData['cos']); $productId = $this->request->get('id'); foreach ($this->formData as $key => $value) { ProductConfiguration::updateOrCreate(['product_id' => $productId, 'setting' => $key], ['value' => $value]); } /** * save serialized cos */ ProductConfiguration::updateOrCreate(['product_id' => $productId, 'setting' => 'cos'], ['value' => json_encode($cos)]); } /** * */ protected function loadDefaultData() { /* default data */ $this->data['acc_limit'] = Size::DEFAULT_ACC_LIMIT; $this->data['acc_base'] = Size::DEFAULT_ACC_BASE; $this->data['acc_size'] = Size::DEFAULT_ACC_SIZE; $this->data['alias_limit'] = Size::DEFAULT_ALIAS_LIMIT; $this->data['domain_alias_limit'] = Size::DEFAULT_DOMAIN_ALIAS_LIMIT; $this->data['cos_name'] = ClassOfServices::CUSTOM_ZIMBRA; $this->data['dist_list_limit'] = Size::DEFAULT_DIST_ALIAS_LIMIT; $this->data['login_link'] = Kerio::DEFAULT_LOGIN_LINK; $this->data['domainMaxSize'] = Size::UNLIMITED; $this->data['domainBaseSize'] = Size::UNLIMITED; /* available class of services*/ $this->availableValues['cos_name'] = [ ClassOfServices::CUSTOM_ZIMBRA => $this->getLang()->absoluteT('addonAA', 'configuration', 'product', 'kerio', 'cos', 'Use Custom Settings'), ClassOfServices::ZIMBRA_CONFIG_OPTIONS => $this->getLang()->absoluteT('addonAA', 'configuration', 'product', 'kerio', 'cos', 'Allow clients to choose Class Of Service'), ClassOfServices::CLASS_OF_SERVICE_QUOTA => $this->getLang()->absoluteT('addonAA', 'configuration', 'product', 'kerio', 'cos', 'Allow clients to choose Class Of Service Quota Per Account'), ]; $manager = new KerioManager(); $repository = $manager->getApiByProduct($this->getRequestValue('id'))->soap->repository(); $cosList = $repository->cos->all(); /** * class of services from API */ foreach ($cosList as $cos) { /** * @var $cos \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\ClassOfService */ $this->availableValues['cos_name'][$cos->getId()] = $this->getLang()->absoluteT($cos->getName()); } } /** * @description load data from database */ protected function overrideDefaultDataByProductConfig() { $settings = ProductConfiguration::where('product_id', $this->request->get('id'))->get(); foreach ($settings as $setting) { if('cos' === $setting->setting) { $this->data[$setting->setting] = json_decode($setting->value, true); continue; } $this->data[$setting->setting] = $setting->value; } } /** * @description catch params from request */ protected function catchFormData() { /** * catch from request */ $params = array_merge(Kerio::BASE_ACCOUNT_CONFIG,self::FORM_DATA); foreach ($params as $name) { if ($value = $this->request->get($name)) { $this->formData[$name] = $value; }elseif(!in_array($name,self::FILED_NOT_UPDATED)){ $this->formData[$name] = ProductParams::SWITCHER_DISABLED; }else{ $this->formData[$name] = ''; } } } private function checkConfigOrLoadFromPrevious($id) { if(ProductConfiguration::where('product_id', $id)->first()) { return; } $migration = new Version1To2\Settings(); $exists = DB::schema()->hasTable($migration->getFromTable()); if(!$exists) { return; } $previous = DB::table($migration->getFromTable())->where('product_id', $id)->get(); /** * */ $prodManager = new ProductConfiguration(); /** * * storage all params per product id */ foreach($previous as $setting) { $settings[$setting->product_id][$setting->setting] = $setting->value; $products[] = $setting->product_id; } /** * * update setting data & save */ foreach($settings as $prodId => $settingsArray) { $attrs = $migration->updateValues($settingsArray, $prodId); foreach($attrs as $key => $value) { $prodManager->updateOrCreate(['product_id' => $prodId, 'setting' => $key],['value' => $value]); } } /** * * new options */ foreach($migration->getNewFields() as $key => $value) { $prodManager->updateOrCreate(['product_id' => $id, 'setting' => $key],['value' => $value]); } } }