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