-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added command to remove rules. Not yet complete, can only remove ALL …
…rules
- Loading branch information
1 parent
39c4952
commit a5c3e2b
Showing
2 changed files
with
71 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
namespace PHSA\Command; | ||
|
||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
/** | ||
* Command used to remove rules from the database | ||
*/ | ||
class Remove extends BaseCommand { | ||
/** | ||
* Class constructor | ||
*/ | ||
public function __construct() { | ||
parent::__construct('remove'); | ||
$this->setDescription('Remove rules'); | ||
$this->setHelp('Remove rules from the database based on one or more options. Several options can be combined to remove more rules'); | ||
|
||
$this->addOption('all', null, InputOption::VALUE_NONE, 'Remove all rules'); | ||
|
||
$this->addOption('repos', null, InputOption::VALUE_OPTIONAL, 'Comma separated list of repositories to remove rules from'); | ||
$this->addOption('user', null, InputOption::VALUE_OPTIONAL, 'Comma separated list of users to remove rules from'); | ||
$this->addOption('group', null, InputOption::VALUE_OPTIONAL, 'Comma separated list of groups to remove rules from'); | ||
$this->addOption('rule', null, InputOption::VALUE_OPTIONAL, 'Remove rules of this type. "allow" or "deny"'); | ||
$this->addOption('role', null, InputOption::VALUE_OPTIONAL, 'Remove rules with this role. "user" or "group"'); | ||
$this->addOption('path', null, InputOption::VALUE_OPTIONAL, 'Comma separated list of paths to remove'); | ||
} | ||
|
||
/** | ||
* Execute the command | ||
* | ||
* @see \Symfony\Components\Console\Command\Command::execute() | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) { | ||
$dialog = $this->getHelper('dialog'); | ||
$result = $dialog->askConfirmation($output, 'Are you sure you want to remove rules? ', false); | ||
|
||
if (!$result) { | ||
$output->writeln('Command aborted'); | ||
return; | ||
} | ||
|
||
$database = $this->configuration['database']['driver']; | ||
|
||
if ($input->getOption('all')) { | ||
$result = $dialog->askConfirmation($output, 'Are you REALLY sure you want to remove ALL rules? ', false); | ||
|
||
if ($result) { | ||
$database->removeAllRules(); | ||
$output->writeln('All rules have been removed'); | ||
return; | ||
} else { | ||
$output->writeln('Command aborted'); | ||
return; | ||
} | ||
} | ||
} | ||
} |