Skip to content
This repository was archived by the owner on Aug 15, 2023. It is now read-only.

Commit bcc9f89

Browse files
author
Georg Ringer
committed
Further standalone CLI
1 parent b6f29d8 commit bcc9f89

File tree

4 files changed

+132
-52
lines changed

4 files changed

+132
-52
lines changed

Classes/Cli/Dispatcher.php

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,41 +26,57 @@
2626
* Starts all due tasks, used by the command line interface
2727
* This script must be included by the "CLI module dispatcher"
2828
*
29-
* @author Georg Ringer <[email protected]>
30-
* @package TYPO3
31-
* @subpackage tx_coreapi
29+
* @author Georg Ringer <[email protected]>
30+
* @package TYPO3
31+
* @subpackage tx_coreapi
3232
*/
3333
class Tx_Coreapi_Cli_Dispatcher {
3434

3535
const MAXIMUM_LINE_LENGTH = 79;
3636

37+
/**
38+
* @var string service
39+
*/
3740
protected $service = '';
38-
protected $command = '';
3941

42+
/**
43+
* @var string command
44+
*/
45+
protected $command = '';
4046

47+
/**
48+
* Constructor with basic checks
49+
*
50+
* @return void
51+
*/
4152
public function __construct() {
4253
if (!isset($_SERVER['argv'][1])) {
4354
die('ERROR: No service defined');
4455
}
45-
$this->service = strtolower($_SERVER['argv'][1]);
4656

47-
if (!isset($_SERVER['argv'][2])) {
48-
die('ERROR: No command defined');
57+
$split = explode(':', $_SERVER['argv'][1]);
58+
if (count($split) !== 2) {
59+
die('ERROR: Only one : is allowed in first argument');
4960
}
50-
$this->command = strtolower($_SERVER['argv'][2]);
61+
62+
$this->service = strtolower($split[0]);
63+
$this->command = strtolower($split[1]);
5164
}
5265

5366

5467
public function start() {
5568
try {
5669
switch ($this->service) {
57-
case 'databaseapi':
70+
case 'cache':
71+
$this->cacheApi();
72+
break;
73+
case 'database':
5874
$this->databaseApi();
5975
break;
60-
case 'extensionapi':
76+
case 'extension':
6177
$this->extensionApi();
6278
break;
63-
case 'siteapi':
79+
case 'site':
6480
$this->siteApi();
6581
break;
6682
default:
@@ -72,11 +88,39 @@ public function start() {
7288
}
7389
}
7490

91+
protected function cacheApi() {
92+
$cacheApiService = t3lib_div::makeInstance('Tx_Coreapi_Service_CacheApiService');
93+
$cacheApiService->initializeObject();
94+
95+
switch ($this->command) {
96+
case 'clearallcaches':
97+
$cacheApiService->clearAllCaches();
98+
$this->outputLine('All caches cleared');
99+
break;
100+
case 'clearconfigurationcache':
101+
$cacheApiService->clearConfigurationCache();
102+
$this->outputLine('Configuration cache cleared');
103+
break;
104+
case 'clearpagecache':
105+
$cacheApiService->clearPageCache();
106+
$this->outputLine('Page cache cleared');
107+
break;
108+
default:
109+
die(sprintf('ERROR: Command "%s" not supported', $this->command));
110+
}
111+
}
112+
75113
protected function databaseApi() {
76114
$databaseApiService = t3lib_div::makeInstance('Tx_Coreapi_Service_DatabaseApiService');
115+
77116
switch ($this->command) {
78117
case 'databasecompare':
79-
// todo
118+
if ($_SERVER['argv'][2] === 'help') {
119+
$actions = $databaseApiService->databaseCompareAvailableActions();
120+
$this->outputTable($actions);
121+
} else {
122+
$databaseApiService->databaseCompare($_SERVER['argv'][2]);
123+
}
80124
break;
81125
default:
82126
die(sprintf('ERROR: Command "%s" not supported', $this->command));
@@ -94,9 +138,9 @@ protected function extensionApi() {
94138
switch ($this->command) {
95139
case 'info':
96140
// @todo: remove duplicated code
97-
$data = $extensionApiService->getExtensionInformation($_SERVER['argv'][3]);
141+
$data = $extensionApiService->getExtensionInformation($_SERVER['argv'][2]);
98142
$this->outputLine('');
99-
$this->outputLine('EXTENSION "%s": %s %s', array(strtoupper($_SERVER['argv'][3]), $data['em_conf']['version'], $data['em_conf']['state']));
143+
$this->outputLine('EXTENSION "%s": %s %s', array(strtoupper($_SERVER['argv'][2]), $data['em_conf']['version'], $data['em_conf']['state']));
100144
$this->outputLine(str_repeat('-', self::MAXIMUM_LINE_LENGTH));
101145

102146
$outputInformation = array();
@@ -141,7 +185,7 @@ protected function extensionApi() {
141185
$extensionApiService->updateMirrors();
142186
break;
143187
case 'listinstalled':
144-
$extensions = $extensionApiService->getInstalledExtensions($_SERVER['argv'][3]);
188+
$extensions = $extensionApiService->getInstalledExtensions($_SERVER['argv'][2]);
145189
$out = array();
146190

147191
foreach($extensions as $key => $details) {
@@ -170,7 +214,7 @@ protected function siteApi() {
170214
$this->outputTable($infos);
171215
break;
172216
case 'createsysnews':
173-
$siteApiService->createSysNews($_SERVER['argv'][3], $_SERVER['argv'][4]);
217+
$siteApiService->createSysNews($_SERVER['argv'][2], $_SERVER['argv'][3]);
174218
break;
175219
default:
176220
die(sprintf('ERROR: Command "%s" not supported', $this->command));
@@ -205,6 +249,7 @@ protected function outputTable(array $input) {
205249
}
206250
$this->outputLine(str_repeat('-', self::MAXIMUM_LINE_LENGTH));
207251
}
252+
208253
}
209254

210255

Classes/Command/ApiCommandController.php

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,23 @@ class Tx_Coreapi_Command_ApiCommandController extends Tx_Extbase_MVC_Controller_
3333
/**
3434
* Database compare
3535
*
36-
* Leave the argument 'actions' empty to see the available ones
36+
* Leave the argument 'actions' empty or use "help" to see the available ones
3737
*
3838
* @param string $actions List of actions which will be executed
3939
*/
4040
public function databaseCompareCommand($actions = '') {
41-
$availableActions = array_flip($this->objectManager->get('Tx_Extbase_Reflection_ClassReflection', 'Tx_Coreapi_Service_DatabaseApiService')->getConstants());
42-
43-
if (empty($actions)) {
44-
$this->outputLine('Available actions are:');
45-
foreach ($availableActions as $number => $action) {
46-
if (t3lib_div::isFirstPartOfStr($action, 'ACTION_')) {
47-
$this->outputLine(' - ' . $action . ' => ' . $number);
48-
}
49-
}
50-
$this->quit();
51-
}
52-
5341
/** @var $service Tx_Coreapi_Service_DatabaseApiService */
5442
$service = $this->objectManager->get('Tx_Coreapi_Service_DatabaseApiService');
55-
$allowedActions = array();
56-
$actionSplit = t3lib_div::trimExplode(',', $actions);
57-
foreach($actionSplit as $split) {
58-
if (!isset($availableActions[$split])) {
59-
$this->output('Action "%s" is not available!', array($split));
60-
$this->quit();
43+
44+
if ($actions === 'help' || strlen($actions) === 0) {
45+
$actions = $service->databaseCompareAvailableActions();
46+
foreach ($actions as $number => $action) {
47+
$this->outputLine(' - ' . $action . ' => ' . $number);
6148
}
62-
$allowedActions[$split] = 1;
49+
$this->quit();
6350
}
6451

65-
$result = $service->databaseCompare($allowedActions);
52+
$result = $service->databaseCompare($actions);
6653
if (empty($result)) {
6754
$this->outputLine('DB has been compared');
6855
} else {

Classes/Command/CacheApiCommandController.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Tx_Coreapi_Command_CacheApiCommandController extends Tx_Extbase_MVC_Contro
3535
*
3636
* @return void
3737
*/
38-
public function clearAllCacheCommand() {
38+
public function clearAllCachesCommand() {
3939
/** @var $service Tx_Coreapi_Service_CacheApiService */
4040
$service = $this->objectManager->get('Tx_Coreapi_Service_CacheApiService');
4141
$service->clearAllCaches();
@@ -53,7 +53,20 @@ public function clearConfigurationCacheCommand() {
5353
$service = $this->objectManager->get('Tx_Coreapi_Service_CacheApiService');
5454
$service->clearConfigurationCache();
5555

56-
$this->outputLine('Configuration Cache has been cleared.');
56+
$this->outputLine('Configuration cache has been cleared.');
57+
}
58+
59+
/**
60+
* Clear page cache
61+
*
62+
* @return void
63+
*/
64+
public function clearPageCacheCommand() {
65+
/** @var $service Tx_Coreapi_Service_CacheApiService */
66+
$service = $this->objectManager->get('Tx_Coreapi_Service_CacheApiService');
67+
$service->clearPageCache();
68+
69+
$this->outputLine('Page cache has been cleared.');
5770
}
5871

5972
}

Classes/Service/DatabaseApiService.php

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
2-
/***************************************************************
2+
3+
/* * *************************************************************
34
* Copyright notice
45
*
56
* (c) 2012 Georg Ringer <[email protected]>
@@ -20,7 +21,7 @@
2021
* GNU General Public License for more details.
2122
*
2223
* This copyright notice MUST APPEAR in all copies of the script!
23-
***************************************************************/
24+
* ************************************************************* */
2425

2526
/**
2627
* DB API service
@@ -29,7 +30,6 @@
2930
* @subpackage tx_coreapi
3031
*/
3132
class Tx_Coreapi_Service_DatabaseApiService {
32-
3333
const ACTION_UPDATE_CLEAR_TABLE = 1;
3434
const ACTION_UPDATE_ADD = 2;
3535
const ACTION_UPDATE_CHANGE = 3;
@@ -54,11 +54,32 @@ public function __construct() {
5454
/**
5555
* Database compare
5656
*
57-
* @param array $allowedActions
57+
* @param string $actions comma seperated list of IDs
5858
* @return array
5959
*/
60-
public function databaseCompare(array $allowedActions) {
60+
public function databaseCompare($actions) {
6161
$errors = array();
62+
63+
64+
/** @var $service Tx_Coreapi_Service_DatabaseApiService */
65+
$service = t3lib_div::makeInstance('Tx_Coreapi_Service_DatabaseApiService');
66+
$availableActions = array_flip(t3lib_div::makeInstance('Tx_Extbase_Reflection_ClassReflection', 'Tx_Coreapi_Service_DatabaseApiService')->getConstants());
67+
68+
69+
if (empty($actions)) {
70+
throw new InvalidArgumentException('No compare modes defined');
71+
}
72+
73+
$allowedActions = array();
74+
$actionSplit = t3lib_div::trimExplode(',', $actions);
75+
foreach ($actionSplit as $split) {
76+
if (!isset($availableActions[$split])) {
77+
throw new InvalidArgumentException(sprintf('Action "%s" is not available!', $split));
78+
}
79+
$allowedActions[$split] = 1;
80+
}
81+
82+
6283
$tblFileContent = t3lib_div::getUrl(PATH_t3lib . 'stddb/tables.sql');
6384

6485
foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $extKey => $loadedExtConf) {
@@ -83,35 +104,35 @@ public function databaseCompare(array $allowedActions) {
83104
$allowedRequestKeys = $this->getRequestKeys($update_statements, $remove_statements);
84105
$results = array();
85106

86-
if ($allowedActions[self::ACTION_UPDATE_CLEAR_TABLE] == 1) {
107+
if ($actions[self::ACTION_UPDATE_CLEAR_TABLE] == 1) {
87108
$results[] = $this->sqlHandler->performUpdateQueries($update_statements['clear_table'], $allowedRequestKeys);
88109
}
89110

90-
if ($allowedActions[self::ACTION_UPDATE_ADD] == 1) {
111+
if ($actions[self::ACTION_UPDATE_ADD] == 1) {
91112
$results[] = $this->sqlHandler->performUpdateQueries($update_statements['add'], $allowedRequestKeys);
92113
}
93114

94-
if ($allowedActions[self::ACTION_UPDATE_CHANGE] == 1) {
115+
if ($actions[self::ACTION_UPDATE_CHANGE] == 1) {
95116
$results[] = $this->sqlHandler->performUpdateQueries($update_statements['change'], $allowedRequestKeys);
96117
}
97118

98-
if ($allowedActions[self::ACTION_REMOVE_CHANGE] == 1) {
119+
if ($actions[self::ACTION_REMOVE_CHANGE] == 1) {
99120
$results[] = $this->sqlHandler->performUpdateQueries($remove_statements['change'], $allowedRequestKeys);
100121
}
101122

102-
if ($allowedActions[self::ACTION_REMOVE_DROP] == 1) {
123+
if ($actions[self::ACTION_REMOVE_DROP] == 1) {
103124
$results[] = $this->sqlHandler->performUpdateQueries($remove_statements['drop'], $allowedRequestKeys);
104125
}
105126

106-
if ($allowedActions[self::ACTION_UPDATE_CREATE_TABLE] == 1) {
127+
if ($actions[self::ACTION_UPDATE_CREATE_TABLE] == 1) {
107128
$results[] = $this->sqlHandler->performUpdateQueries($update_statements['create_table'], $allowedRequestKeys);
108129
}
109130

110-
if ($allowedActions[self::ACTION_REMOVE_CHANGE_TABLE] == 1) {
131+
if ($actions[self::ACTION_REMOVE_CHANGE_TABLE] == 1) {
111132
$results[] = $this->sqlHandler->performUpdateQueries($remove_statements['change_table'], $allowedRequestKeys);
112133
}
113134

114-
if ($allowedActions[self::ACTION_REMOVE_DROP_TABLE] == 1) {
135+
if ($actions[self::ACTION_REMOVE_DROP_TABLE] == 1) {
115136
$results[] = $this->sqlHandler->performUpdateQueries($remove_statements['drop_table'], $allowedRequestKeys);
116137
}
117138

@@ -127,6 +148,20 @@ public function databaseCompare(array $allowedActions) {
127148
return $errors;
128149
}
129150

151+
/**
152+
* Get all available actions
153+
* @return array
154+
*/
155+
public function databaseCompareAvailableActions() {
156+
$availableActions = array_flip(t3lib_div::makeInstance('Tx_Extbase_Reflection_ClassReflection', 'Tx_Coreapi_Service_DatabaseApiService')->getConstants());
157+
158+
foreach ($availableActions as $number => $action) {
159+
if (!t3lib_div::isFirstPartOfStr($action, 'ACTION_')) {
160+
unset($availableActions[$number]);
161+
}
162+
}
163+
return $availableActions;
164+
}
130165

131166
/**
132167
* Get all request keys, even for those requests which are not used

0 commit comments

Comments
 (0)