DeleteUserCreatedPagesCommand.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Opentalent\OtAdmin\Command;
  3. use Opentalent\OtAdmin\Controller\SiteController;
  4. use Symfony\Component\Console\Command\Command;
  5. use Symfony\Component\Console\Input\InputArgument;
  6. use Symfony\Component\Console\Input\InputInterface;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. use Symfony\Component\Console\Style\SymfonyStyle;
  9. /**
  10. * This CLI command provoke the definitive deletion of all the pages
  11. * created by the users, leaving only the starting mandatory pages.
  12. *
  13. * /!\ Warning: this is a destructive operation
  14. *
  15. * @package Opentalent\OtAdmin\Command
  16. */
  17. class DeleteUserCreatedPagesCommand extends Command
  18. {
  19. public function __construct(
  20. private readonly SiteController $siteController
  21. ) {
  22. parent::__construct();
  23. }
  24. /**
  25. * -- This method is expected by Typo3, do not rename ou remove --
  26. *
  27. * Allows to configure the command.
  28. * Allows to add a description, a help text, and / or define arguments.
  29. *
  30. */
  31. protected function configure(): void
  32. {
  33. $this
  34. ->setName("ot:site:delete-user-created-pages")
  35. ->setDescription("Delete all the pages created by the users, leaving only the starting mandatory pages.")
  36. ->setHelp("This CLI command provoke the definitive deletion of all the pages
  37. created by the users, leaving only the starting mandatory pages.
  38. /!\ Warning: this is a destructive operation.")
  39. ->addArgument(
  40. 'organization-id',
  41. InputArgument::OPTIONAL,
  42. "The organization's id in the opentalent DB"
  43. );
  44. }
  45. /**
  46. * -- This method is expected by Typo3, do not rename ou remove --
  47. *
  48. * @param InputInterface $input
  49. * @param OutputInterface $output
  50. * @return int
  51. * @throws \Exception
  52. */
  53. protected function execute(InputInterface $input, OutputInterface $output): int
  54. {
  55. $org_id = $input->getArgument('organization-id');
  56. $io = new SymfonyStyle($input, $output);
  57. if (
  58. !$io->confirm("Are you sure you want to delete all the pages created " .
  59. "by the users? (organization id: " . $org_id . ")")
  60. ) {
  61. $io->error("Aborting.");
  62. return 1;
  63. }
  64. $rootUid = $this->siteController->deleteUserCreatedPagesAction($org_id);
  65. $io->success(sprintf("The website with root uid " . $rootUid . " had its user-created pages deleted."));
  66. return 0;
  67. }
  68. }