From 71ec14c81b1c6c7831d496e4a99ac225fd0869bc Mon Sep 17 00:00:00 2001 From: slawkens Date: Fri, 8 Nov 2024 11:09:46 +0100 Subject: [PATCH] Option to clear specified plugin settings by name --- system/src/Commands/SettingsResetCommand.php | 26 +++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/system/src/Commands/SettingsResetCommand.php b/system/src/Commands/SettingsResetCommand.php index 69473848..78748b00 100644 --- a/system/src/Commands/SettingsResetCommand.php +++ b/system/src/Commands/SettingsResetCommand.php @@ -14,7 +14,11 @@ class SettingsResetCommand extends Command protected function configure(): void { $this->setName('settings:reset') - ->setDescription('Removes all settings in database'); + ->setDescription('Removes settings in database') + ->addArgument('name', + InputArgument::OPTIONAL, + 'Name of the plugin' + ); } protected function execute(InputInterface $input, OutputInterface $output): int @@ -23,16 +27,30 @@ class SettingsResetCommand extends Command $io = new SymfonyStyle($input, $output); - if (!$io->confirm('Are you sure you want to reset all settings in database?', false)) { + $name = $input->getArgument('name'); + + $all = !$name ? 'all' : $name; + if (!$io->confirm("Are you sure you want to reset {$all} settings in database?", false)) { return Command::FAILURE; } - SettingsModel::truncate(); + if (!$name) { + SettingsModel::truncate(); + } + else { + $settingsModel = SettingsModel::where('name', $name)->first(); + if (!$settingsModel) { + $io->warning('No settings for this plugin saved in database'); + return Command::SUCCESS; + } + + SettingsModel::where('name', $name)->delete(); + } $settings = Settings::getInstance(); $settings->clearCache(); - $io->success('Setting cleared successfully'); + $io->success('Settings cleared successfully'); return Command::SUCCESS; } }