diff --git a/system/src/Commands/SettingsResetCommand.php b/system/src/Commands/SettingsResetCommand.php new file mode 100644 index 00000000..a495edf4 --- /dev/null +++ b/system/src/Commands/SettingsResetCommand.php @@ -0,0 +1,36 @@ +setName('settings:reset') + ->setDescription('Removes all settings in database'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $io = new SymfonyStyle($input, $output); + + if (!$io->confirm('Are you sure you want to reset all settings in database?', false)) { + return Command::FAILURE; + } + + SettingsModel::truncate(); + + $settings = Settings::getInstance(); + $settings->clearCache(); + + $io->success('Setting cleared successfully'); + return Command::SUCCESS; + } +} diff --git a/system/src/Commands/SettingsSetCommand.php b/system/src/Commands/SettingsSetCommand.php new file mode 100644 index 00000000..1159689a --- /dev/null +++ b/system/src/Commands/SettingsSetCommand.php @@ -0,0 +1,55 @@ +setName('settings:set') + ->setDescription('Updates the setting specified by argument in database') + ->addArgument('key', + InputArgument::REQUIRED, + 'Setting name/key' + ) + ->addArgument('value', + InputArgument::REQUIRED, + 'New value' + ); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $io = new SymfonyStyle($input, $output); + + $key = $input->getArgument('key'); + $value = $input->getArgument('value'); + + $settings = Settings::getInstance(); + $settings->clearCache(); + $settings->load(); + + $setting = $settings[$key]; + if (!isset($setting['value'])) { + $io->warning('Settings with this key does not exists'); + return Command::FAILURE; + } + + // format plugin_name.key + // example: core.template + $explode = explode('.', $key); + + $settings->updateInDatabase($explode[0], $explode[1], $value); + $settings->clearCache(); + + $io->success("Setting $key successfully updated"); + return Command::SUCCESS; + } +} diff --git a/system/src/Settings.php b/system/src/Settings.php index 349bd518..91516e34 100644 --- a/system/src/Settings.php +++ b/system/src/Settings.php @@ -464,9 +464,15 @@ class Settings implements \ArrayAccess $ret['value'] = $value; } else { + if (!isset($this->settingsFile[$pluginKeyName]['settings'][$key])) { + return null; + } + $ret['value'] = $this->settingsFile[$pluginKeyName]['settings'][$key]['default']; } + $ret['key'] = $key; + if(isset($ret['type'])) { switch($ret['type']) { case 'boolean':