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+ }
0 commit comments