52124da32eef43669012237bc0ed1c10a1c9a38a
[Packages/TYPO3.CMS.git] / typo3 / sysext / integrity / Classes / AdminCommand.php
1 <?php
2 namespace TYPO3\CMS\Integrity;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
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 textfile 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 /**
30 * Core functions for admin
31 *
32 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
33 */
34 /**
35 * Core functions for administration
36 *
37 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
38 * @package TYPO3
39 * @subpackage tx_lowlevel
40 */
41 class AdminCommand extends \TYPO3\CMS\Core\Controller\CommandLineController {
42
43 /**
44 * @todo Define visibility
45 */
46 public $adminModules = array(
47 'setBElock' => 'Set the Backend Lock',
48 'clearBElock' => 'Clears the Backend Lock',
49 'msg' => 1
50 );
51
52 /**
53 * Constructor
54 *
55 * @todo Define visibility
56 */
57 public function __construct() {
58 // Running parent class constructor
59 parent::__construct();
60 // Adding options to help archive:
61 $this->cli_options[] = array('--redirect=[URL]', 'For toolkey "setBElock": The URL to which the redirection will occur.');
62 // Setting help texts:
63 $this->cli_help['name'] = 'lowlevel_admin -- Various functions for administration and maintenance of TYPO3 from the command line';
64 $this->cli_help['synopsis'] = 'toolkey ###OPTIONS###';
65 $this->cli_help['description'] = 'The \'toolkey\' keywords are:
66
67 ' . implode('
68 ', array_keys($this->adminModules));
69 $this->cli_help['examples'] = '/.../cli_dispatch.phpsh lowlevel_admin setBElock --redirect=http://url_which_explains_why.com/';
70 $this->cli_help['author'] = 'Kasper Skaarhoej, (c) 2009';
71 }
72
73 /**************************
74 *
75 * CLI functionality
76 *
77 *************************/
78 /**
79 * CLI engine
80 *
81 * @param array $argv Command line arguments
82 * @return string
83 * @todo Define visibility
84 */
85 public function cli_main($argv) {
86 // Force user to admin state and set workspace to "Live":
87 $GLOBALS['BE_USER']->user['admin'] = 1;
88 $GLOBALS['BE_USER']->setWorkspace(0);
89 // Print help
90 $analysisType = (string) $this->cli_args['_DEFAULT'][1];
91 if (!$analysisType) {
92 $this->cli_validateArgs();
93 $this->cli_help();
94 die;
95 }
96 // Analysis type:
97 switch ((string) $analysisType) {
98 case 'setBElock':
99 if (@is_file((PATH_typo3conf . 'LOCK_BACKEND'))) {
100 $this->cli_echo('A lockfile already exists. Overwriting it...
101 ');
102 }
103 $lockFileContent = $this->cli_argValue('--redirect');
104 \TYPO3\CMS\Core\Utility\GeneralUtility::writeFile(PATH_typo3conf . 'LOCK_BACKEND', $lockFileContent);
105 $this->cli_echo('Wrote lock-file to \'' . PATH_typo3conf . 'LOCK_BACKEND\' with content \'' . $lockFileContent . '\'');
106 break;
107 case 'clearBElock':
108 if (@is_file((PATH_typo3conf . 'LOCK_BACKEND'))) {
109 unlink(PATH_typo3conf . 'LOCK_BACKEND');
110 if (@is_file((PATH_typo3conf . 'LOCK_BACKEND'))) {
111 $this->cli_echo('ERROR: Could not remove lock file \'' . PATH_typo3conf . 'LOCK_BACKEND\'!!
112 ', 1);
113 } else {
114 $this->cli_echo('Removed lock file \'' . PATH_typo3conf . 'LOCK_BACKEND\'
115 ');
116 }
117 } else {
118 $this->cli_echo('No lock file \'' . PATH_typo3conf . 'LOCK_BACKEND\' was found; hence no lock can be removed.\'
119 ');
120 }
121 break;
122 default:
123 $this->cli_echo('Unknown toolkey, \'' . $analysisType . '\'');
124 break;
125 }
126 $this->cli_echo(LF);
127 }
128
129 }
130
131
132 ?>