‪TYPO3CMS  ‪main
GeneratorCommand.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\Attribute\AsCommand;
21 use Symfony\Component\Console\Command\Command;
22 use Symfony\Component\Console\Input\InputArgument;
23 use Symfony\Component\Console\Input\InputInterface;
24 use Symfony\Component\Console\Input\InputOption;
25 use Symfony\Component\Console\Output\OutputInterface;
31 
37 #[AsCommand('styleguide:generate', 'Generate page tree for Styleguide TCA backend and/or Styleguide frontend')]
38 final class ‪GeneratorCommand extends Command
39 {
40  protected function ‪configure(): void
41  {
42  $this->addArgument('type', InputArgument::OPTIONAL, 'Create page tree data, valid arguments are "tca", "frontend" and "all"', 'all');
43  $this->addOption('delete', 'd', InputOption::VALUE_NONE, 'Delete page tree and its records for the selected type');
44  $this->addOption('create', 'c', InputOption::VALUE_NONE, 'Create page tree and its records for the selected type');
45  }
46 
52  protected function ‪execute(InputInterface $input, OutputInterface ‪$output): int
53  {
54  // Make sure the _cli_ user is loaded
56 
57  if (!$input->getOption('create') && !$input->getOption('delete')) {
58  ‪$output->writeln('<comment>Please specify an option "--create" or "--delete"</comment>');
59  }
60 
61  switch ($input->getArgument('type')) {
62  case 'tca':
63  if ($input->getOption('create')) {
64  $this->‪createTca($output);
65  }
66 
67  if ($input->getOption('delete')) {
68  $this->‪deleteTca($output);
69  }
70  break;
71 
72  case 'frontend':
73  if ($input->getOption('create')) {
74  $this->‪createFrontend($output);
75  }
76 
77  if ($input->getOption('delete')) {
78  $this->‪deleteFrontend($output);
79  }
80  break;
81 
82  case 'all':
83  if ($input->getOption('create')) {
84  $this->‪createTca($output);
85  $this->‪createFrontend($output);
86  }
87 
88  if ($input->getOption('delete')) {
89  $this->‪deleteTca($output);
90  $this->‪deleteFrontend($output);
91  }
92 
93  break;
94  default:
95  ‪$output->writeln('<error>Please specify a valid action. Choose "tca", "frontend" or "all"</error>');
96  return 1;
97  }
98 
99  return 0;
100  }
101 
102  private function ‪createTca(OutputInterface ‪$output): int
103  {
105  ‪$finder = GeneralUtility::makeInstance(RecordFinder::class);
106  if (count(‪$finder->findUidsOfStyleguideEntryPages())) {
107  ‪$output->writeln('<comment>TCA page tree already exists!</comment>');
108  } else {
109  $generator = GeneralUtility::makeInstance(Generator::class);
110  $generator->create();
111  ‪$output->writeln('<info>TCA page tree created!</info>');
112  }
113 
114  return 0;
115  }
116 
117  private function ‪deleteTca(OutputInterface ‪$output): int
118  {
120  $generator = GeneralUtility::makeInstance(Generator::class);
121  $generator->delete();
122  ‪$output->writeln('<info>TCA page tree deleted!</info>');
123 
124  return 0;
125  }
126 
127  private function ‪createFrontend(OutputInterface ‪$output): int
128  {
130  $recordFinder = GeneralUtility::makeInstance(RecordFinder::class);
131 
132  if (count($recordFinder->findUidsOfFrontendPages())) {
133  ‪$output->writeln('<info>Frontend page tree already exists!</info>');
134  } else {
136  $frontend = GeneralUtility::makeInstance(GeneratorFrontend::class);
137  $frontend->create();
138  ‪$output->writeln('<info>Frontend page tree created!</info>');
139  }
140 
141  return 0;
142  }
143 
144  private function ‪deleteFrontend(OutputInterface ‪$output): int
145  {
147  $frontend = GeneralUtility::makeInstance(GeneratorFrontend::class);
148  $frontend->delete();
149 
150  ‪$output->writeln('<info>Frontend page tree deleted!</info>');
151 
152  return 0;
153  }
154 }
‪$finder
‪if(PHP_SAPI !=='cli') $finder
Definition: header-comment.php:22
‪TYPO3\CMS\Styleguide\Command\GeneratorCommand
Definition: GeneratorCommand.php:39
‪TYPO3\CMS\Styleguide\Command\GeneratorCommand\execute
‪int execute(InputInterface $input, OutputInterface $output)
Definition: GeneratorCommand.php:52
‪TYPO3\CMS\Styleguide\Command\GeneratorCommand\configure
‪configure()
Definition: GeneratorCommand.php:40
‪TYPO3\CMS\Styleguide\Command\GeneratorCommand\deleteTca
‪deleteTca(OutputInterface $output)
Definition: GeneratorCommand.php:117
‪TYPO3\CMS\Styleguide\Command\GeneratorCommand\deleteFrontend
‪deleteFrontend(OutputInterface $output)
Definition: GeneratorCommand.php:144
‪$output
‪$output
Definition: annotationChecker.php:114
‪TYPO3\CMS\Styleguide\TcaDataGenerator\Generator
Definition: Generator.php:34
‪TYPO3\CMS\Styleguide\Command
Definition: GeneratorCommand.php:18
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:62
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Styleguide\TcaDataGenerator\GeneratorFrontend
Definition: GeneratorFrontend.php:33
‪TYPO3\CMS\Styleguide\Command\GeneratorCommand\createTca
‪createTca(OutputInterface $output)
Definition: GeneratorCommand.php:102
‪TYPO3\CMS\Styleguide\TcaDataGenerator\RecordFinder
Definition: RecordFinder.php:38
‪TYPO3\CMS\Core\Core\Bootstrap\initializeBackendAuthentication
‪static initializeBackendAuthentication()
Definition: Bootstrap.php:527
‪TYPO3\CMS\Styleguide\Command\GeneratorCommand\createFrontend
‪createFrontend(OutputInterface $output)
Definition: GeneratorCommand.php:127