2727 * This script must be included by the "CLI module dispatcher"
2828 *
2929 * @author Georg Ringer <[email protected] > 30- * @package TYPO3
30+ * @package TYPO3
3131 * @subpackage tx_coreapi
3232 */
3333class Tx_Coreapi_Cli_Dispatcher {
@@ -51,12 +51,14 @@ class Tx_Coreapi_Cli_Dispatcher {
5151 */
5252 public function __construct () {
5353 if (!isset ($ _SERVER ['argv ' ][1 ])) {
54- die ( ' ERROR: No service defined ' );
54+ $ this -> error ( ' No service defined ' );
5555 }
5656
5757 $ split = explode (': ' , $ _SERVER ['argv ' ][1 ]);
58- if (count ($ split ) !== 2 ) {
59- die ('ERROR: Only one : is allowed in first argument ' );
58+ if (count ($ split ) === 1 ) {
59+ $ this ->error ('CLI calls need to be like coreapi cache:clearallcaches ' );
60+ } elseif (count ($ split ) !== 2 ) {
61+ $ this ->error ('Only one : is allowed in first argument ' );
6062 }
6163
6264 $ this ->service = strtolower ($ split [0 ]);
@@ -80,7 +82,7 @@ public function start() {
8082 $ this ->siteApi ();
8183 break ;
8284 default :
83- die (sprintf ('ERROR: Service "%s" not supported ' , $ this ->service ));
85+ $ this -> error (sprintf ('Service "%s" not supported ' , $ this ->service ));
8486 }
8587 } catch (Exception $ e ) {
8688 $ errorMessage = sprintf ('ERROR: Error in service "%s" and command "%s"": %s! ' , $ this ->service , $ this ->command , $ e ->getMessage ());
@@ -106,7 +108,7 @@ protected function cacheApi() {
106108 $ this ->outputLine ('Page cache cleared ' );
107109 break ;
108110 default :
109- die (sprintf ('ERROR: Command "%s" not supported ' , $ this ->command ));
111+ $ this -> error (sprintf ('Command "%s" not supported ' , $ this ->command ));
110112 }
111113 }
112114
@@ -123,7 +125,7 @@ protected function databaseApi() {
123125 }
124126 break ;
125127 default :
126- die (sprintf ('ERROR: Command "%s" not supported ' , $ this ->command ));
128+ $ this -> error (sprintf ('Command "%s" not supported ' , $ this ->command ));
127129 }
128130 }
129131
@@ -195,7 +197,7 @@ protected function extensionApi() {
195197 $ this ->outputTable ($ out );
196198 break ;
197199 default :
198- die (sprintf ('ERROR: Command "%s" not supported ' , $ this ->command ));
200+ $ this -> error (sprintf ('Command "%s" not supported ' , $ this ->command ));
199201 }
200202
201203 }
@@ -217,7 +219,7 @@ protected function siteApi() {
217219 $ siteApiService ->createSysNews ($ _SERVER ['argv ' ][2 ], $ _SERVER ['argv ' ][3 ]);
218220 break ;
219221 default :
220- die (sprintf ('ERROR: Command "%s" not supported ' , $ this ->command ));
222+ $ this -> error (sprintf ('Command "%s" not supported ' , $ this ->command ));
221223 }
222224 }
223225
@@ -250,8 +252,17 @@ protected function outputTable(array $input) {
250252 $ this ->outputLine (str_repeat ('- ' , self ::MAXIMUM_LINE_LENGTH ));
251253 }
252254
253- }
255+ /**
256+ * End call
257+ *
258+ * @param string $message Error message
259+ * @return void
260+ */
261+ protected function error ($ message ) {
262+ die ('ERROR: ' . $ message );
263+ }
254264
265+ }
255266
256267if ((TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_CLI ) && basename (PATH_thisScript) == 'cli_dispatch.phpsh ' ) {
257268 $ dispatcher = t3lib_div::makeInstance ('Tx_Coreapi_Cli_Dispatcher ' );
0 commit comments