mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +02:00
settings:set + settings:reset commands
This commit is contained in:
parent
235e69b8da
commit
e2487f97e3
36
system/src/Commands/SettingsResetCommand.php
Normal file
36
system/src/Commands/SettingsResetCommand.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace MyAAC\Commands;
|
||||
|
||||
use MyAAC\Models\Settings as SettingsModel;
|
||||
use MyAAC\Settings;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class SettingsResetCommand extends Command
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
55
system/src/Commands/SettingsSetCommand.php
Normal file
55
system/src/Commands/SettingsSetCommand.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace MyAAC\Commands;
|
||||
|
||||
use MyAAC\Models\Settings as SettingsModel;
|
||||
use MyAAC\Settings;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
class SettingsSetCommand extends Command
|
||||
{
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
@ -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':
|
||||
|
Loading…
x
Reference in New Issue
Block a user