/** * Index method * * @return void */ public function index() { if ($this->request->is(['post', 'put'])) { $settings = $this->Settings->find('all')->all(); $settings = $this->Settings->patchEntities($settings, $this->request->data()['Setting']); $result = $this->Settings->connection()->transactional(function () use($settings) { foreach ($settings as $setting) { $result = $this->Settings->save($setting, ['atomic' => false]); if (!$result) { return false; } } return true; }); if ($result) { $settings = $this->Settings->find()->combine('path', 'value')->toArray(); ksort($settings); $settings = Hash::expand($settings); Settings::dump('config', 'default', $settings); $this->Flash->success('The settings has been saved.'); $this->redirect(['action' => 'index']); } else { $this->Flash->error('The settings could not be saved. Please, try again.'); } } $settings = $this->Settings->find('extended')->find('editable')->toArray(); $this->set('settings', $settings['editable']); }
public function import() { $settingsFile = 'settings'; if (!empty($this->plugin)) { $settingsFile = $this->plugin . '.' . $settingsFile; $settingsFileDir = Plugin::path($this->plugin) . 'config'; } else { $settingsFileDir = ROOT . DS . 'config'; } $settingsDir = new Folder($settingsFileDir, false); if (!$settingsDir->find('settings.*')) { return false; } $config = new PhpConfig(); $data = $config->read($settingsFile); if (!$data) { return false; } if (!empty($this->plugin)) { $this->out(__d('platform', '- <success>Processing settings pool for {0} plugin</success>', $this->plugin)); } else { $this->out(__d('platform', '- <success>Processing settings pool for {0}</success>', 'App')); } $settingsTable = TableRegistry::get('Platform.Settings'); foreach ($data as $row) { if (!isset($row['plugin']) || empty($row['plugin'])) { $row['plugin'] = $this->plugin; } $data = ['plugin' => $row['plugin'], 'path' => $row['path']]; $setting = $settingsTable->find('all', ['conditions' => $data])->first(); if (!$setting) { $setting = $settingsTable->newEntity(); $data = array_merge($data, ['value' => isset($row['default']) ? $row['default'] : '']); } $setting = $settingsTable->patchEntity($setting, $data); $settingsTable->save($setting); } //TODO: Maybe chared method for settings save $settings = $settingsTable->find()->combine('path', 'value')->toArray(); ksort($settings); $settings = Hash::expand($settings); Settings::dump('config', 'default', $settings); }