Skip to content
This repository was archived by the owner on Aug 15, 2023. It is now read-only.

Commit 8d7f48d

Browse files
author
Stefano Kowalke
committed
Lock/Unlock the TYPO3 backend
This takes the Commands from typo3_console from @helhum. Is on hold as long we don't have a solution of the focus of both projects. Resolves: #22
1 parent 9d051a3 commit 8d7f48d

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
namespace Etobi\CoreAPI\Command;
3+
4+
/***************************************************************
5+
* Copyright notice
6+
*
7+
* (c) 2014 Helmut Hummel <[email protected]>
8+
* All rights reserved
9+
*
10+
* This script is part of the TYPO3 project. The TYPO3 project is
11+
* free software; you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation; either version 2 of the License, or
14+
* (at your option) any later version.
15+
*
16+
* The GNU General Public License can be found at
17+
* http://www.gnu.org/copyleft/gpl.html.
18+
* A copy is found in the text file GPL.txt and important notices to the license
19+
* from the author is found in LICENSE.txt distributed with these scripts.
20+
*
21+
*
22+
* This script is distributed in the hope that it will be useful,
23+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
24+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25+
* GNU General Public License for more details.
26+
*
27+
* This copyright notice MUST APPEAR in all copies of the script!
28+
***************************************************************/
29+
use TYPO3\CMS\Extbase\Mvc\Controller\CommandController;
30+
31+
/**
32+
* API Command Controller
33+
*/
34+
class BackendApiCommandController extends CommandController {
35+
/**
36+
* Locks backend access for all users by writing a lock file that is checked when the backend is accessed.
37+
*
38+
* @param string $redirectUrl URL to redirect to when the backend is accessed
39+
*/
40+
public function lockCommand($redirectUrl = NULL) {
41+
if (@is_file((PATH_typo3conf . 'LOCK_BACKEND'))) {
42+
$this->outputLine('A lockfile already exists. Overwriting it...');
43+
}
44+
45+
\TYPO3\CMS\Core\Utility\GeneralUtility::writeFile(PATH_typo3conf . 'LOCK_BACKEND', (string)$redirectUrl);
46+
47+
if ($redirectUrl === NULL) {
48+
$this->outputLine('Wrote lock file to \'typo3conf/LOCK_BACKEND\'');
49+
} else {
50+
$this->outputLine('Wrote lock file to \'typo3conf/LOCK_BACKEND\' with instruction to redirect to: \'' . $redirectUrl . '\'');
51+
}
52+
}
53+
54+
/**
55+
* Unlocks the backend access by deleting the lock file
56+
*/
57+
public function unlockCommand() {
58+
if (@is_file((PATH_typo3conf . 'LOCK_BACKEND'))) {
59+
unlink(PATH_typo3conf . 'LOCK_BACKEND');
60+
if (@is_file((PATH_typo3conf . 'LOCK_BACKEND'))) {
61+
$this->outputLine('ERROR: Could not remove lock file \'typo3conf/LOCK_BACKEND\'!');
62+
$this->sendAndExit(1);
63+
} else {
64+
$this->outputLine('Removed lock file \'typo3conf/LOCK_BACKEND\'');
65+
}
66+
} else {
67+
$this->outputLine('No lock file \'typo3conf/LOCK_BACKEND\' was found, hence no lock could be removed.');
68+
$this->sendAndExit(2);
69+
}
70+
}
71+
}

ext_autoload.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
$extensionClassesPath = $extensionPath . 'Classes/';
55

66
return array(
7+
'Etobi\CoreAPI\Command\BackendApiCommandController' => $extensionClassesPath . 'Command/BackendApiCommandController.php',
78
'Etobi\CoreAPI\Command\DatabaseApiCommandController' => $extensionClassesPath . 'Command/DatabaseApiCommandController.php',
89
'Etobi\CoreAPI\Command\SiteApiCommandController' => $extensionClassesPath . 'Command/SiteApiCommandController.php',
910
'Etobi\CoreAPI\Command\CacheApiCommandController' => $extensionClassesPath . 'Command/CacheApiCommandController.php',

ext_localconf.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
if (TYPO3_MODE === 'BE') {
55
// Register commands
6+
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = 'Etobi\CoreAPI\Command\BackendApiCommandController';
67
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = 'Etobi\CoreAPI\Command\DatabaseApiCommandController';
78
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = 'Etobi\CoreAPI\Command\CacheApiCommandController';
89
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = 'Etobi\CoreAPI\Command\SiteApiCommandController';

0 commit comments

Comments
 (0)