DeleteSiteCommand.php 3.1 KB

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