DeleteSiteCommand.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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\Input\InputOption;
  8. use Symfony\Component\Console\Output\OutputInterface;
  9. use Symfony\Component\Console\Style\SymfonyStyle;
  10. /**
  11. * This CLI command delete an existing organization's website
  12. *
  13. * @package Opentalent\OtAdmin\Command
  14. */
  15. class DeleteSiteCommand extends Command
  16. {
  17. /**
  18. * -- This method is expected by Typo3, do not rename ou remove --
  19. *
  20. * Allows to configure the command.
  21. * Allows to add a description, a help text, and / or define arguments.
  22. *
  23. */
  24. protected function configure()
  25. {
  26. $this
  27. ->setName("ot:site:delete")
  28. ->setDescription("Delete an organization website")
  29. ->setHelp("Call this method by giving it the organization's id in the Opentalent DB.
  30. By default, it proceed to a soft deletion, marking the records as deleted
  31. and renaming files: this kind of deletion can then be undone
  32. with the ot:site:undelete command.
  33. If the --hard option is passed, the records and files will be permanently deleted,
  34. with no possibility of undoing. A confirmation will be demanded.")
  35. ->addOption(
  36. 'hard',
  37. null,
  38. InputOption::VALUE_NONE,
  39. "Permanently delete the records and files. Use with caution."
  40. )
  41. ->addArgument(
  42. 'organization_id',
  43. InputArgument::REQUIRED,
  44. "The organization's id in the opentalent DB"
  45. );
  46. }
  47. /**
  48. * -- This method is expected by Typo3, do not rename ou remove --
  49. *
  50. * Executes the command for creating the new organization
  51. *
  52. * @param InputInterface $input
  53. * @param OutputInterface $output
  54. * @throws \Exception
  55. */
  56. protected function execute(InputInterface $input, OutputInterface $output)
  57. {
  58. $org_id = $input->getArgument('organization_id');
  59. $hard = $input->getOption('hard');
  60. $io = new SymfonyStyle($input, $output);
  61. $siteController = new SiteController();
  62. $rootUid = $siteController->deleteSiteAction($org_id, $hard);
  63. if ($hard) {
  64. $io->success(sprintf("The website with root uid " . $rootUid . " has been permanently deleted"));
  65. } else {
  66. $io->success(sprintf("The website with root uid " . $rootUid . " has been soft-deleted. Use ot:site:undelete to restore it."));
  67. }
  68. }
  69. }