[TASK] Cleanup CLI commands in EXT:backend
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Command / LockBackendCommand.php
1 <?php
2 namespace TYPO3\CMS\Backend\Command;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 use Symfony\Component\Console\Command\Command;
17 use Symfony\Component\Console\Input\InputArgument;
18 use Symfony\Component\Console\Input\InputInterface;
19 use Symfony\Component\Console\Output\OutputInterface;
20 use Symfony\Component\Console\Style\SymfonyStyle;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22
23 /**
24 * Core function for locking the TYPO3 Backend
25 */
26 class LockBackendCommand extends Command
27 {
28 /**
29 * Configure the command by defining the name, options and arguments
30 */
31 protected function configure()
32 {
33 $this
34 ->setDescription('Lock the TYPO3 Backend')
35 ->addArgument(
36 'redirect',
37 InputArgument::OPTIONAL,
38 'If set, then the TYPO3 Backend will redirect to the locking state (only used when locking the TYPO3 Backend'
39 );
40 }
41
42 /**
43 * Executes the command for adding the lock file
44 *
45 * @param InputInterface $input
46 * @param OutputInterface $output
47 * @return void
48 */
49 protected function execute(InputInterface $input, OutputInterface $output)
50 {
51 $io = new SymfonyStyle($input, $output);
52 $io->title($this->getDescription());
53 $lockFile = $this->getLockFileName();
54 if (@is_file($lockFile)) {
55 $io->note('A lock file already exists. Overwriting it.');
56 }
57 $output = 'Wrote lock file to "' . $lockFile . '"';
58 if ($input->getArgument('redirect')) {
59 $lockFileContent = $input->getArgument('redirect');
60 $output .= LF . 'with content "' . $lockFileContent . '".';
61 } else {
62 $lockFileContent = '';
63 $output .= '.';
64 }
65 GeneralUtility::writeFile($lockFile, $lockFileContent);
66 $io->success($output);
67 }
68
69 /**
70 * Location of the file name
71 *
72 * @return string
73 */
74 protected function getLockFileName()
75 {
76 return PATH_typo3conf . 'LOCK_BACKEND';
77 }
78 }