|
1
|
|
|
<?php |
|
2
|
|
|
namespace Aoe\T3deploy\Controller; |
|
3
|
|
|
|
|
4
|
|
|
/*************************************************************** |
|
5
|
|
|
* Copyright notice |
|
6
|
|
|
* |
|
7
|
|
|
* (c) 2018 AOE GmbH <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* All rights reserved |
|
10
|
|
|
* |
|
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
|
12
|
|
|
* free software; you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU General Public License as published by |
|
14
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
15
|
|
|
* (at your option) any later version. |
|
16
|
|
|
* |
|
17
|
|
|
* The GNU General Public License can be found at |
|
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
|
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
|
|
|
use TYPO3\CMS\Core\Controller\CommandLineController; |
|
29
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* General CLI dispatcher for the t3deploy extension. |
|
33
|
|
|
* |
|
34
|
|
|
* @package t3deploy |
|
35
|
|
|
*/ |
|
36
|
|
|
class T3deployCliController extends CommandLineController |
|
37
|
|
|
{ |
|
38
|
|
|
const ExtKey = 't3deploy'; |
|
|
|
|
|
|
39
|
|
|
const Mask_ClassName = 'Aoe\\T3deploy\\Controller\\%sController'; |
|
|
|
|
|
|
40
|
|
|
const Mask_Action = '%sAction'; |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var array |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $classInstances = []; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Creates this object. |
|
49
|
|
|
*/ |
|
50
|
1 |
|
public function __construct() |
|
51
|
|
|
{ |
|
52
|
1 |
|
parent::__construct(); |
|
53
|
|
|
|
|
54
|
1 |
|
$this->setCliOptions(); |
|
55
|
|
|
|
|
56
|
1 |
|
$this->cli_help = array_merge($this->cli_help, [ |
|
57
|
1 |
|
'name' => __CLASS__, |
|
58
|
1 |
|
'synopsis' => self::ExtKey . ' controller action ###OPTIONS###', |
|
59
|
1 |
|
'description' => 'TYPO3 dispatcher for database related operations.', |
|
60
|
1 |
|
'examples' => 'typo3/cli_dispatch.phpsh ' . self::ExtKey . ' database updateStructure', |
|
61
|
1 |
|
'author' => '(c) 2012 - 2018 AOE GmbH <[email protected]>', |
|
62
|
|
|
]); |
|
63
|
1 |
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Sets the CLI arguments. |
|
67
|
|
|
* |
|
68
|
|
|
* @param array $arguments |
|
69
|
|
|
* @return void |
|
70
|
|
|
*/ |
|
71
|
1 |
|
public function setCliArguments(array $arguments) |
|
72
|
|
|
{ |
|
73
|
1 |
|
$this->cli_args = $arguments; |
|
74
|
1 |
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Gets or generates an instance of the given class name. |
|
78
|
|
|
* |
|
79
|
|
|
* @param string $className |
|
80
|
|
|
* @return object |
|
81
|
|
|
*/ |
|
82
|
1 |
|
public function getClassInstance($className) |
|
83
|
|
|
{ |
|
84
|
1 |
|
if (!isset($this->classInstances[$className])) { |
|
85
|
|
|
$this->classInstances[$className] = GeneralUtility::makeInstance($className); |
|
86
|
|
|
} |
|
87
|
1 |
|
return $this->classInstances[$className]; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Sets an instance for the given class name. |
|
92
|
|
|
* |
|
93
|
|
|
* @param string $className |
|
94
|
|
|
* @param object $classInstance |
|
95
|
|
|
* @return void |
|
96
|
|
|
*/ |
|
97
|
1 |
|
public function setClassInstance($className, $classInstance) |
|
98
|
|
|
{ |
|
99
|
1 |
|
$this->classInstances[$className] = $classInstance; |
|
100
|
1 |
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Dispatches the requested actions to the accordant controller. |
|
104
|
|
|
* |
|
105
|
|
|
* @return mixed |
|
106
|
|
|
* @throws \Exception |
|
107
|
|
|
*/ |
|
108
|
1 |
|
public function dispatch() |
|
109
|
|
|
{ |
|
110
|
1 |
|
$controller = (string)$this->cli_args['_DEFAULT'][1]; |
|
111
|
1 |
|
$action = (string)$this->cli_args['_DEFAULT'][2]; |
|
112
|
|
|
|
|
113
|
1 |
|
if (!$controller || !$action) { |
|
114
|
|
|
$this->cli_validateArgs(); |
|
115
|
|
|
$this->cli_help(); |
|
116
|
|
|
exit(1); |
|
|
|
|
|
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
1 |
|
$className = sprintf(self::Mask_ClassName, ucfirst($controller)); |
|
120
|
1 |
|
$actionName = sprintf(self::Mask_Action, $action); |
|
121
|
|
|
|
|
122
|
1 |
|
$instance = $this->getClassInstance($className); |
|
123
|
|
|
|
|
124
|
1 |
|
if (!is_callable([$instance, $actionName])) { |
|
125
|
|
|
throw new \Exception('The action ' . $action . ' is not implemented in controller ' . $controller); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
1 |
|
$result = call_user_func_array( |
|
129
|
1 |
|
[$instance, $actionName], |
|
130
|
1 |
|
[$this->cli_args] |
|
131
|
|
|
); |
|
132
|
|
|
|
|
133
|
1 |
|
return $result; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Sets the CLI options for help. |
|
138
|
|
|
* |
|
139
|
|
|
* @return void |
|
140
|
|
|
*/ |
|
141
|
1 |
|
protected function setCliOptions() |
|
142
|
|
|
{ |
|
143
|
1 |
|
$this->cli_options = [ |
|
144
|
|
|
['--verbose', 'Report changes'], |
|
145
|
|
|
['-v', 'Same as --verbose'], |
|
146
|
|
|
['--execute', 'Execute changes (updates, removals)'], |
|
147
|
|
|
['-e', 'Same as --execute'], |
|
148
|
|
|
['--remove', 'Include structure differences for removal'], |
|
149
|
|
|
['-r', 'Same as --remove'], |
|
150
|
|
|
['--drop-keys', 'Removes key modifications that will cause errors'], |
|
151
|
|
|
['--dump-file', 'Dump changes to file'], |
|
152
|
|
|
['--excludes', 'Exclude update types (add,change,create_table,change_table,drop,drop_table,clear_table)'] |
|
153
|
|
|
]; |
|
154
|
1 |
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|