/** * Create system settings, core_path and assets_url are created automatically */ private function createSystemSettings() { $this->createSystemSetting($this->config->getLowCaseName() . '.core_path', $this->packageCorePath, 'textfield', 'Git Package Management Settings'); $this->createSystemSetting($this->config->getLowCaseName() . '.assets_path', $this->packageAssetsPath, 'textfield', 'Git Package Management Settings'); $this->createSystemSetting($this->config->getLowCaseName() . '.assets_url', $this->packageAssetsUrl, 'textfield', 'Git Package Management Settings'); /** @var $setting GitPackageConfigSetting */ foreach ($this->config->getSettings() as $setting) { $this->createSystemSetting($setting->getNamespacedKey(), $setting->getValue(), $setting->getType(), $setting->getArea()); } $this->modx->log(modX::LOG_LEVEL_INFO, 'System settings created.'); }
private function addSystemSettings() { /** @var GitPackageConfigSetting[] $settings */ $settings = $this->config->getSettings(); foreach ($settings as $setting) { /** @var modSystemSetting $settingObject */ $settingObject = $this->modx->newObject('modSystemSetting'); $settingObject->fromArray(array('key' => $setting->getNamespacedKey(), 'value' => $setting->getValue(), 'xtype' => $setting->getType(), 'namespace' => $this->config->getLowCaseName(), 'area' => $setting->getArea()), '', true, true); $vehicle = $this->builder->createVehicle($settingObject, 'setting'); $this->builder->putVehicle($vehicle); } }
private function updateSystemSettings() { $oldSettings = $this->oldConfig->getSettings(); $notUsedSettings = array_keys($this->oldConfig->getSettings()); $notUsedSettings = array_flip($notUsedSettings); foreach ($this->newConfig->getSettings() as $key => $setting) { /** @var modSystemSetting $systemSetting */ $systemSetting = $this->modx->getObject('modSystemSetting', array('key' => $key)); if (!$systemSetting) { $systemSetting = $this->modx->newObject('modSystemSetting'); $systemSetting->set('key', $key); $systemSetting->set('value', $setting->getValue()); $systemSetting->set('namespace', $this->newConfig->getLowCaseName()); $systemSetting->set('area', $setting->getArea()); $systemSetting->set('xtype', $setting->getType()); } else { if (!isset($oldSettings[$key]) || $oldSettings[$key]->getValue() != $setting->getValue()) { $systemSetting->set('value', $setting->getValue()); } $systemSetting->set('area', $setting->getArea()); $systemSetting->set('xtype', $setting->getType()); } $systemSetting->save(); if (isset($notUsedSettings[$key])) { unset($notUsedSettings[$key]); } } foreach ($notUsedSettings as $key => $value) { /** @var modSystemSetting $setting */ $setting = $this->modx->getObject('modSystemSetting', array('key' => $key)); if ($setting) { $setting->remove(); } } return true; }