-
Notifications
You must be signed in to change notification settings - Fork 1
PAT-251 Init new command to mass project deletion #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,133 @@ | ||||||||||||||||||||||||
| <?php | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| namespace Keboola\Console\Command; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| use Keboola\ManageApi\Client; | ||||||||||||||||||||||||
| use Keboola\ManageApi\ClientException; | ||||||||||||||||||||||||
| use Symfony\Component\Console\Command\Command; | ||||||||||||||||||||||||
| use Symfony\Component\Console\Input\InputArgument; | ||||||||||||||||||||||||
| use Symfony\Component\Console\Input\InputInterface; | ||||||||||||||||||||||||
| use Symfony\Component\Console\Input\InputOption; | ||||||||||||||||||||||||
| use Symfony\Component\Console\Output\OutputInterface; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| class DeleteProjects extends Command | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| private int $projectNotFound = 0; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| private int $projectsDisabled = 0; | ||||||||||||||||||||||||
| private int $projectsFailed = 0; | ||||||||||||||||||||||||
| private int $projectsDeleted = 0; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| protected function configure(): void | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| $this | ||||||||||||||||||||||||
| ->setName('manage:delete-projects') | ||||||||||||||||||||||||
| ->setDescription('Delete all projects specified by project IDs') | ||||||||||||||||||||||||
| ->addArgument('token', InputArgument::REQUIRED, 'manage token') | ||||||||||||||||||||||||
| ->addArgument('url', InputArgument::REQUIRED, 'Stack URL. Including https://') | ||||||||||||||||||||||||
| ->addArgument('projects', InputArgument::REQUIRED, 'list of IDs separated by comma ("1,7,146")') | ||||||||||||||||||||||||
| ->addOption('force', 'f', InputOption::VALUE_NONE, 'Will actually do the work, otherwise it\'s dry run'); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| public function execute(InputInterface $input, OutputInterface $output): ?int | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| $apiToken = $input->getArgument('token'); | ||||||||||||||||||||||||
| $apiUrl = $input->getArgument('url'); | ||||||||||||||||||||||||
| $projects = $input->getArgument('projects'); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| $force = (bool) $input->getOption('force'); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| $client = $this->createClient($apiUrl, $apiToken); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| $projectIds = array_filter(explode(',', $projects), 'is_numeric'); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| $projectIds = array_filter(explode(',', $projects), 'is_numeric'); | |
| $projectIdStrings = array_map('trim', explode(',', $projects)); | |
| $invalidProjectIds = array_filter($projectIdStrings, function($id) { | |
| return !is_numeric($id); | |
| }); | |
| if (!empty($invalidProjectIds)) { | |
| $output->writeln('<error>Invalid project IDs detected: ' . implode(', ', $invalidProjectIds) . '</error>'); | |
| $output->writeln('Please check your input for typos or formatting issues. Only numeric project IDs are allowed.'); | |
| return 1; | |
| } | |
| $projectIds = array_map('intval', $projectIdStrings); |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tag <err> should be <error> to match Symfony Console's standard error formatting tags.
| sprintf('<err>project "%s" deletion failed</err>', $projectDetail['id']) | |
| sprintf('<error>project "%s" deletion failed</error>', $projectDetail['id']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type should be
intinstead of?int. Symfony Console commands should always return an integer exit code, and this method always returns 0.