‪TYPO3CMS  ‪main
LockBackendCommand.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Symfony\Component\Console\Attribute\AsCommand;
19 use Symfony\Component\Console\Command\Command;
20 use Symfony\Component\Console\Input\InputArgument;
21 use Symfony\Component\Console\Input\InputInterface;
22 use Symfony\Component\Console\Output\OutputInterface;
23 use Symfony\Component\Console\Style\SymfonyStyle;
26 
30 #[AsCommand('backend:lock', 'Lock the TYPO3 Backend')]
31 class ‪LockBackendCommand extends Command
32 {
36  protected function ‪configure()
37  {
38  $this
39  ->addArgument(
40  'redirect',
41  InputArgument::OPTIONAL,
42  'If set, then the TYPO3 Backend will redirect to the locking state (only used when locking the TYPO3 Backend'
43  );
44  }
45 
49  protected function ‪execute(InputInterface $input, OutputInterface ‪$output): int
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  $lockFileContent = is_string($lockFileContent) ? $lockFileContent : '';
61  ‪$output .= LF . 'with content "' . $lockFileContent . '".';
62  } else {
63  $lockFileContent = '';
64  ‪$output .= '.';
65  }
66  ‪GeneralUtility::writeFile($lockFile, $lockFileContent);
67  $io->success(‪$output);
68  return Command::SUCCESS;
69  }
70 
76  protected function ‪getLockFileName()
77  {
78  return ‪Environment::getLegacyConfigPath() . '/LOCK_BACKEND';
79  }
80 }
‪TYPO3\CMS\Backend\Command\LockBackendCommand\configure
‪configure()
Definition: LockBackendCommand.php:36
‪TYPO3\CMS\Backend\Command\LockBackendCommand
Definition: LockBackendCommand.php:32
‪TYPO3\CMS\Core\Core\Environment\getLegacyConfigPath
‪static getLegacyConfigPath()
Definition: Environment.php:268
‪TYPO3\CMS\Backend\Command
Definition: CreateBackendUserCommand.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility\writeFile
‪static bool writeFile(string $file, string $content, bool $changePermissions=false)
Definition: GeneralUtility.php:1469
‪TYPO3\CMS\Backend\Command\LockBackendCommand\execute
‪execute(InputInterface $input, OutputInterface $output)
Definition: LockBackendCommand.php:49
‪$output
‪$output
Definition: annotationChecker.php:114
‪TYPO3\CMS\Backend\Command\LockBackendCommand\getLockFileName
‪string getLockFileName()
Definition: LockBackendCommand.php:76
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52