‪TYPO3CMS  ‪main
SetupDefaultBackendUserGroupsCommand.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Symfony\Component\Console\Command\Command;
21 use Symfony\Component\Console\Input\InputInterface;
22 use Symfony\Component\Console\Input\InputOption;
23 use Symfony\Component\Console\Output\OutputInterface;
24 use Symfony\Component\Console\Style\SymfonyStyle;
26 
27 final class ‪SetupDefaultBackendUserGroupsCommand extends Command
28 {
29  private ‪BackendUserGroupType ‪$userGroupEnum = BackendUserGroupType::ALL;
30  private array ‪$availableUserGroups = [];
31 
32  public function ‪__construct(
33  string $name,
34  private readonly ‪SetupService $setupService,
35  ) {
36  parent::__construct($name);
37  }
38 
39  protected function ‪configure(): void
40  {
41  $this->availableUserGroups = $this->userGroupEnum->getAllUserGroupTypes();
42  $actualGroups = $this->userGroupEnum->getActualUserGroupTypes();
43  $stringUserGroupList = $actualGroups !== []
44  ? '- ' . implode("\n- ", $actualGroups)
45  : 'No groups available.';
46  $this->setDescription('Setup default backend user groups')
47  ->addOption(
48  'no-interaction',
49  'n',
50  InputOption::VALUE_NONE,
51  'Do not ask any interactive question',
52  )->addOption(
53  'groups',
54  'g',
55  InputOption::VALUE_OPTIONAL,
56  'Which backend user groups do you want to create? [ ' . implode(', ', $this->availableUserGroups) . ']',
57  $this->userGroupEnum->value,
58  $this->availableUserGroups
59  )->setHelp(
60  <<<EOT
61 The command will allow you to create base backend user groups for your ‪TYPO3 installation.
62 
63 You can create either both or one of the following groups:
64 
65 $stringUserGroupList
66 
67 EOT
68  );
69  }
70 
74  protected function ‪execute(InputInterface $input, OutputInterface ‪$output): int
75  {
76  $input->setInteractive(!$input->getOption('no-interaction'));
77  $io = new SymfonyStyle($input, ‪$output);
78 
79  $createGroups = $this->userGroupEnum->value;
80  if ($input->hasParameterOption('--groups') || $input->hasParameterOption('-g')) {
81  $createGroups = $input->getOption('groups');
82  } elseif (!$input->getOption('no-interaction')) {
83  $createGroups = $io->choice(
84  'Which backend groups do you want to create?',
85  $this->availableUserGroups,
86  $this->userGroupEnum->value
87  );
88  }
89  if ($createGroups === BackendUserGroupType::NONE->value) {
90  $io->info('No backend groups have been created.');
91  return Command::SUCCESS;
92  }
93  if (!in_array($createGroups, $this->availableUserGroups, true)) {
94  $io->error('Invalid user group specified.');
95  return Command::FAILURE;
96  }
97 
98  $createEditor = false;
99  $createAdvancedEditor = false;
100  $creationNotices = [];
101  if ($createGroups === BackendUserGroupType::EDITOR->value || $createGroups === BackendUserGroupType::ALL->value) {
102  $createEditor = true;
103  $creationNotices[] = BackendUserGroupType::EDITOR->value;
104  }
105  if ($createGroups === BackendUserGroupType::ADVANCED_EDITOR->value || $createGroups === BackendUserGroupType::ALL->value) {
106  $createAdvancedEditor = true;
107  $creationNotices[] = BackendUserGroupType::ADVANCED_EDITOR->value;
108  }
109  $this->setupService->createBackendUserGroups($createEditor, $createAdvancedEditor);
110 
111  $io->success(sprintf('Backend user group(s) created: %s', implode(', ', $creationNotices)));
112  return Command::SUCCESS;
113  }
114 }
‪TYPO3
‪TYPO3\CMS\Install\Command\SetupDefaultBackendUserGroupsCommand\execute
‪execute(InputInterface $input, OutputInterface $output)
Definition: SetupDefaultBackendUserGroupsCommand.php:74
‪TYPO3\CMS\Install\Service\SetupService
Definition: SetupService.php:42
‪TYPO3\CMS\Install\Command
Definition: BackendUserGroupType.php:18
‪$output
‪$output
Definition: annotationChecker.php:114
‪TYPO3\CMS\Install\Command\SetupDefaultBackendUserGroupsCommand\$userGroupEnum
‪BackendUserGroupType $userGroupEnum
Definition: SetupDefaultBackendUserGroupsCommand.php:29
‪TYPO3\CMS\Install\Command\SetupDefaultBackendUserGroupsCommand\__construct
‪__construct(string $name, private readonly SetupService $setupService,)
Definition: SetupDefaultBackendUserGroupsCommand.php:32
‪TYPO3\CMS\Install\Command\SetupDefaultBackendUserGroupsCommand\configure
‪configure()
Definition: SetupDefaultBackendUserGroupsCommand.php:39
‪TYPO3\CMS\Install\Command\SetupDefaultBackendUserGroupsCommand\$availableUserGroups
‪array $availableUserGroups
Definition: SetupDefaultBackendUserGroupsCommand.php:30
‪TYPO3\CMS\Install\Command\SetupDefaultBackendUserGroupsCommand
Definition: SetupDefaultBackendUserGroupsCommand.php:28
‪TYPO3\CMS\Install\Command\BackendUserGroupType
‪BackendUserGroupType
Definition: BackendUserGroupType.php:25