|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/*************************************************************** |
|
4
|
|
|
* Copyright notice |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2016 AOE GmbH <[email protected]> |
|
7
|
|
|
* |
|
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 3 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
|
|
|
* |
|
19
|
|
|
* This script is distributed in the hope that it will be useful, |
|
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22
|
|
|
* GNU General Public License for more details. |
|
23
|
|
|
* |
|
24
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
|
25
|
|
|
***************************************************************/ |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @package FeatureFlag |
|
30
|
|
|
* @subpackage System_Typo3 |
|
31
|
|
|
*/ |
|
32
|
|
|
class Tx_FeatureFlag_System_Typo3_Cli extends \TYPO3\CMS\Core\Controller\CommandLineController |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $extKey = 'feature_flag'; |
|
38
|
|
|
/** |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $prefixId = 'tx_featureflag_system_typo3_cli'; |
|
42
|
|
|
/** |
|
43
|
|
|
* @var string |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $scriptRelPath = 'Classes/System/Typo3/Cli.php'; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var TYPO3\CMS\Scheduler\Scheduler |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $scheduler; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var Tx_FeatureFlag_Service |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $service; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* constructor |
|
59
|
|
|
*/ |
|
60
|
|
|
public function __construct() |
|
61
|
|
|
{ |
|
62
|
|
|
parent::__construct(); |
|
63
|
|
|
if (!defined('TYPO3_cliMode')) { |
|
64
|
|
|
die('Access denied: CLI only.'); |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
$this->cli_options = array_merge($this->cli_options, array()); |
|
|
|
|
|
|
67
|
|
|
$this->cli_help = array_merge($this->cli_help, array( |
|
|
|
|
|
|
68
|
|
|
'name' => $this->prefixId, |
|
69
|
|
|
'synopsis' => $this->extKey . ' command', |
|
70
|
|
|
'description' => 'This script can flag all configured tables by feature flags.', |
|
71
|
|
|
'examples' => 'typo3/cli_dispatch.phpsh ' . $this->extKey . ' [flagEntries]', |
|
72
|
|
|
'author' => '(c) 2013 AOE GmbH <[email protected]>', |
|
73
|
|
|
)); |
|
74
|
|
|
$this->conf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$this->extKey]); |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
$this->scheduler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Scheduler\\Scheduler'); |
|
77
|
|
|
|
|
78
|
|
|
$this->service = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class) |
|
79
|
|
|
->get(Tx_FeatureFlag_Service::class); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param $argv |
|
84
|
|
|
* @return int |
|
85
|
|
|
*/ |
|
86
|
|
|
public function main($argv) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->init(); |
|
89
|
|
|
try { |
|
90
|
|
|
switch ($this->getAction()) { |
|
91
|
|
|
case 'activate': |
|
92
|
|
|
$this->setFeatureStatus($this->getArgument(), true); |
|
93
|
|
|
break; |
|
94
|
|
|
case 'deactivate': |
|
95
|
|
|
$this->setFeatureStatus($this->getArgument(), false); |
|
96
|
|
|
break; |
|
97
|
|
|
case 'flagEntries': |
|
98
|
|
|
$this->flagEntries(); |
|
99
|
|
|
break; |
|
100
|
|
|
case 'flushCaches': |
|
101
|
|
|
$this->flushCaches(); |
|
102
|
|
|
break; |
|
103
|
|
|
default: |
|
104
|
|
|
$this->cli_help(); |
|
105
|
|
|
break; |
|
106
|
|
|
} |
|
107
|
|
|
} catch (Exception $e) { |
|
108
|
|
|
return 1; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
return 0; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @return string |
|
116
|
|
|
*/ |
|
117
|
|
|
private function getAction() |
|
118
|
|
|
{ |
|
119
|
|
|
return (string)$this->cli_args['_DEFAULT'][1]; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @return string |
|
124
|
|
|
*/ |
|
125
|
|
|
private function getArgument() |
|
126
|
|
|
{ |
|
127
|
|
|
return (string)$this->cli_args['_DEFAULT'][2]; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @return void |
|
132
|
|
|
*/ |
|
133
|
|
|
private function init() |
|
134
|
|
|
{ |
|
135
|
|
|
$this->cli_validateArgs(); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* check if scheduler is installed |
|
140
|
|
|
* |
|
141
|
|
|
* @return boolean |
|
142
|
|
|
*/ |
|
143
|
|
|
private function isSchedulerInstalled() |
|
144
|
|
|
{ |
|
145
|
|
|
return is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys']['scheduler']); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @return int |
|
150
|
|
|
*/ |
|
151
|
|
|
private function getSchedulerTaskUid() |
|
152
|
|
|
{ |
|
153
|
|
|
foreach ($this->scheduler->fetchTasksWithCondition() as $task) { |
|
|
|
|
|
|
154
|
|
|
if ($task instanceof Tx_FeatureFlag_System_Typo3_Task_FlagEntries) { |
|
155
|
|
|
$taskUid = $task->getTaskUid(); |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
if (null === $taskUid) { |
|
|
|
|
|
|
160
|
|
|
throw new RuntimeException('scheduler task for feature_flag was not found'); |
|
161
|
|
|
} |
|
162
|
|
|
return $taskUid; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @throws RuntimeException |
|
167
|
|
|
*/ |
|
168
|
|
|
private function flagEntries() |
|
169
|
|
|
{ |
|
170
|
|
|
if ($this->isSchedulerInstalled()) { |
|
171
|
|
|
$taskUid = $this->getSchedulerTaskUid(); |
|
172
|
|
|
$task = $this->scheduler->fetchTask($taskUid); |
|
173
|
|
|
|
|
174
|
|
|
if ($this->scheduler->isValidTaskObject($task)) { |
|
175
|
|
|
$this->scheduler->executeTask($task); |
|
176
|
|
|
} else { |
|
177
|
|
|
throw new RuntimeException('task-object of feature-flag-task is not valid!'); |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* Enable or disable features. $features can be a comma-separated list of feature names |
|
184
|
|
|
* @param String $features |
|
185
|
|
|
*/ |
|
186
|
|
|
private function setFeatureStatus($features, $enabled) |
|
187
|
|
|
{ |
|
188
|
|
|
$features = array_map('trim', explode(',', $features)); |
|
189
|
|
|
foreach ($features as $feature) { |
|
190
|
|
|
echo $feature; |
|
191
|
|
|
$this->service->updateFeatureFlag($feature, $enabled); |
|
192
|
|
|
} |
|
193
|
|
|
$this->service->flagEntries(); |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* Clear all page caches |
|
198
|
|
|
*/ |
|
199
|
|
|
private function flushCaches() |
|
200
|
|
|
{ |
|
201
|
|
|
/** @var Tx_FeatureFlag_System_Typo3_CacheManager $cacheManager */ |
|
202
|
|
|
$cacheManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class) |
|
203
|
|
|
->get(Tx_FeatureFlag_System_Typo3_CacheManager::class); |
|
204
|
|
|
$cacheManager->clearAllCaches(); |
|
205
|
|
|
} |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** @var Tx_FeatureFlag_System_Typo3_Cli $cli */ |
|
209
|
|
|
$cli = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_FeatureFlag_System_Typo3_Cli'); |
|
210
|
|
|
exit($cli->main($_SERVER['argv'])); |
|
211
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths