‪TYPO3CMS  ‪main
ExportCommand.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;
26 use Symfony\Component\Console\Style\SymfonyStyle;
30 
34 #[AsCommand('impexp:export', 'Exports a T3D / XML file with content of a page tree')]
35 class ‪ExportCommand extends Command
36 {
37  public function ‪__construct(protected readonly ‪Export $export)
38  {
39  parent::__construct();
40  }
41 
45  protected function ‪configure(): void
46  {
47  $this
48  ->addArgument(
49  'filename',
50  InputArgument::OPTIONAL,
51  'The filename to export to (without file extension).'
52  )
53  ->addOption(
54  'type',
55  null,
56  InputOption::VALUE_OPTIONAL,
57  'The file type (xml, t3d, t3d_compressed).',
58  $this->export->getExportFileType()
59  )
60  ->addOption(
61  'pid',
62  null,
63  InputOption::VALUE_OPTIONAL,
64  'The root page of the exported page tree.',
65  $this->export->getPid()
66  )
67  ->addOption(
68  'levels',
69  null,
70  InputOption::VALUE_OPTIONAL,
71  sprintf(
72  'The depth of the exported page tree. ' .
73  '"%d": "Records on this page", ' .
74  '"0": "This page", ' .
75  '"1": "1 level down", ' .
76  '.. ' .
77  '"%d": "Infinite levels".',
80  ),
81  $this->export->getLevels()
82  )
83  ->addOption(
84  'table',
85  null,
86  InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
87  'Include all records of this table. Examples: "_ALL", "tt_content", "sys_file_reference", etc.'
88  )
89  ->addOption(
90  'record',
91  null,
92  InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
93  'Include this specific record. Pattern is "{table}:{record}". Examples: "tt_content:12", etc.'
94  )
95  ->addOption(
96  'list',
97  null,
98  InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
99  'Include the records of this table and this page. Pattern is "{table}:{pid}". Examples: "be_users:0", etc.'
100  )
101  ->addOption(
102  'include-related',
103  null,
104  InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
105  'Include record relations to this table, including the related record. Examples: "_ALL", "sys_category", etc.'
106  )
107  ->addOption(
108  'include-static',
109  null,
110  InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
111  'Include record relations to this table, excluding the related record. Examples: "_ALL", "be_users", etc.'
112  )
113  ->addOption(
114  'exclude',
115  null,
116  InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
117  'Exclude this specific record. Pattern is "{table}:{record}". Examples: "fe_users:3", etc.'
118  )
119  ->addOption(
120  'exclude-disabled-records',
121  null,
122  InputOption::VALUE_NONE,
123  'Exclude records which are handled as disabled by their TCA configuration, e.g. by fields "disabled", "starttime" or "endtime".'
124  )
125  ->addOption(
126  'exclude-html-css',
127  null,
128  InputOption::VALUE_NONE,
129  'Exclude referenced HTML and CSS files.'
130  )
131  ->addOption(
132  'title',
133  null,
134  InputOption::VALUE_OPTIONAL,
135  'The meta title of the export.'
136  )
137  ->addOption(
138  'description',
139  null,
140  InputOption::VALUE_OPTIONAL,
141  'The meta description of the export.'
142  )
143  ->addOption(
144  'notes',
145  null,
146  InputOption::VALUE_OPTIONAL,
147  'The meta notes of the export.'
148  )
149  ->addOption(
150  'dependency',
151  null,
152  InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
153  'This TYPO3 extension is required for the exported records. Examples: "news", "powermail", etc.'
154  )
155  ->addOption(
156  'save-files-outside-export-file',
157  null,
158  InputOption::VALUE_NONE,
159  'Save files into separate folder instead of including them into the common export file. Folder name pattern is "{filename}.files".'
160  )
161  ;
162  }
163 
167  protected function ‪execute(InputInterface $input, OutputInterface ‪$output): int
168  {
169  // Ensure the _cli_ user is authenticated
171 
172  $io = new SymfonyStyle($input, ‪$output);
173 
174  try {
175  $this->export->setExportFileName(‪PathUtility::basename((string)$input->getArgument('filename')));
176  $this->export->setExportFileType((string)$input->getOption('type'));
177  $this->export->setPid((int)$input->getOption('pid'));
178  $this->export->setLevels((int)$input->getOption('levels'));
179  $this->export->setTables($input->getOption('table'));
180  $this->export->setRecord($input->getOption('record'));
181  $this->export->setList($input->getOption('list'));
182  $this->export->setRelOnlyTables($input->getOption('include-related'));
183  $this->export->setRelStaticTables($input->getOption('include-static'));
184  $this->export->setExcludeMap($input->getOption('exclude'));
185  $this->export->setExcludeDisabledRecords($input->getOption('exclude-disabled-records'));
186  $this->export->setIncludeExtFileResources(!$input->getOption('exclude-html-css'));
187  $this->export->setTitle((string)$input->getOption('title'));
188  $this->export->setDescription((string)$input->getOption('description'));
189  $this->export->setNotes((string)$input->getOption('notes'));
190  $this->export->setExtensionDependencies($input->getOption('dependency'));
191  $this->export->setSaveFilesOutsideExportFile($input->getOption('save-files-outside-export-file'));
192  $this->export->process();
193  $saveFile = $this->export->saveToFile();
194  $io->success('Exporting to ' . $saveFile->getPublicUrl() . ' succeeded.');
195  return Command::SUCCESS;
196  } catch (\‪Exception $e) {
197  $saveFolder = $this->export->getOrCreateDefaultImportExportFolder();
198  $io->error('Exporting to ' . $saveFolder->getPublicUrl() . ' failed.');
199  if ($io->isVerbose()) {
200  $io->writeln($e->getMessage());
201  }
202  return Command::FAILURE;
203  }
204  }
205 }
‪TYPO3\CMS\Impexp\Command
Definition: ExportCommand.php:18
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:27
‪TYPO3\CMS\Core\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Core\Utility\PathUtility\basename
‪static basename(string $path)
Definition: PathUtility.php:219
‪TYPO3\CMS\Impexp\Export\LEVELS_INFINITE
‪const LEVELS_INFINITE
Definition: Export.php:54
‪TYPO3\CMS\Impexp\Command\ExportCommand\execute
‪execute(InputInterface $input, OutputInterface $output)
Definition: ExportCommand.php:167
‪TYPO3\CMS\Impexp\Export\LEVELS_RECORDS_ON_THIS_PAGE
‪const LEVELS_RECORDS_ON_THIS_PAGE
Definition: Export.php:53
‪$output
‪$output
Definition: annotationChecker.php:114
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:62
‪TYPO3\CMS\Impexp\Export
Definition: Export.php:52
‪TYPO3\CMS\Impexp\Command\ExportCommand\configure
‪configure()
Definition: ExportCommand.php:45
‪TYPO3\CMS\Impexp\Command\ExportCommand
Definition: ExportCommand.php:36
‪TYPO3\CMS\Impexp\Command\ExportCommand\__construct
‪__construct(protected readonly Export $export)
Definition: ExportCommand.php:37
‪TYPO3\CMS\Core\Core\Bootstrap\initializeBackendAuthentication
‪static initializeBackendAuthentication()
Definition: Bootstrap.php:527