Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / lowlevel / class.tx_lowlevel_admin_core.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Core functions for admin
29 *
30 * $Id$
31 *
32 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
33 */
34 /**
35 * [CLASS/FUNCTION INDEX of SCRIPT]
36 *
37 */
38 /**
39 * Core functions for administration
40 *
41 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
42 * @package TYPO3
43 * @subpackage tx_lowlevel
44 */
45 class tx_lowlevel_admin_core extends t3lib_cli {
46
47 var $adminModules = array(
48 'setBElock' => 'Set the Backend Lock',
49 'clearBElock' => 'Clears the Backend Lock',
50 'msg' => 1
51 );
52
53 /**
54 * Constructor
55 *
56 * @return void
57 */
58 function tx_lowlevel_admin_core() {
59
60 // Running parent class constructor
61 parent::t3lib_cli();
62
63 // Adding options to help archive:
64 $this->cli_options[] = array('--redirect=[URL]', 'For toolkey "setBElock": The URL to which the redirection will occur.');
65
66 // Setting help texts:
67 $this->cli_help['name'] = 'lowlevel_admin -- Various functions for administration and maintenance of TYPO3 from the command line';
68 $this->cli_help['synopsis'] = 'toolkey ###OPTIONS###';
69 $this->cli_help['description'] = "The 'toolkey' keywords are:\n\n ".implode("\n ",array_keys($this->adminModules));
70 $this->cli_help['examples'] = "/.../cli_dispatch.phpsh lowlevel_admin setBElock --redirect=http://url_which_explains_why.com/";
71 $this->cli_help['author'] = "Kasper Skaarhoej, (c) 2009";
72 }
73
74
75
76
77
78
79
80
81
82 /**************************
83 *
84 * CLI functionality
85 *
86 *************************/
87
88 /**
89 * CLI engine
90 *
91 * @param array Command line arguments
92 * @return string
93 */
94 function cli_main($argv) {
95
96 // Force user to admin state and set workspace to "Live":
97 $GLOBALS['BE_USER']->user['admin'] = 1;
98 $GLOBALS['BE_USER']->setWorkspace(0);
99
100 // Print help
101 $analysisType = (string)$this->cli_args['_DEFAULT'][1];
102 if (!$analysisType) {
103 $this->cli_validateArgs();
104 $this->cli_help();
105 exit;
106 }
107
108 // Analysis type:
109 switch((string)$analysisType) {
110 case 'setBElock':
111 if (@is_file(PATH_typo3conf.'LOCK_BACKEND')) {
112 $this->cli_echo("A lockfile already exists. Overwriting it... \n");
113 }
114 $lockFileContent = $this->cli_argValue('--redirect');
115 t3lib_div::writeFile(PATH_typo3conf.'LOCK_BACKEND', $lockFileContent);
116 $this->cli_echo("Wrote lock-file to '".PATH_typo3conf."LOCK_BACKEND' with content '".$lockFileContent."'");
117 break;
118 case 'clearBElock':
119 if (@is_file(PATH_typo3conf.'LOCK_BACKEND')) {
120 unlink(PATH_typo3conf.'LOCK_BACKEND');
121 if (@is_file(PATH_typo3conf.'LOCK_BACKEND') ) {
122 $this->cli_echo("ERROR: Could not remove lock file '".PATH_typo3conf."LOCK_BACKEND'!!\n",1);
123 } else {
124 $this->cli_echo("Removed lock file '".PATH_typo3conf."LOCK_BACKEND'\n");
125 }
126 } else {
127 $this->cli_echo("No lock file '".PATH_typo3conf."LOCK_BACKEND' was found; hence no lock can be removed.'\n");
128 }
129 break;
130 default:
131 $this->cli_echo("Unknown toolkey, '".$analysisType."'");
132 break;
133 }
134 $this->cli_echo(LF);
135 }
136
137
138 }
139
140 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/lowlevel/class.tx_lowlevel_admin.php'])) {
141 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/lowlevel/class.tx_lowlevel_admin.php']);
142 }
143
144 ?>