1
|
|
|
<?php |
2
|
|
|
/*************************************************************** |
3
|
|
|
* Copyright notice |
4
|
|
|
* |
5
|
|
|
* (c) 2016 AOE GmbH <[email protected]> |
6
|
|
|
* All rights reserved |
7
|
|
|
* |
8
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
9
|
|
|
***************************************************************/ |
10
|
|
|
|
11
|
|
|
use \TYPO3\CMS\Core\Utility\GeneralUtility; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* General CLI dispatcher for the t3deploy extension. |
15
|
|
|
* |
16
|
|
|
* @package t3deploy |
17
|
|
|
* @author Oliver Hader <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class tx_t3deploy_dispatch extends \TYPO3\CMS\Core\Controller\CommandLineController { |
20
|
|
|
const ExtKey = 't3deploy'; |
|
|
|
|
21
|
|
|
const Mask_ClassName = 'tx_t3deploy_%sController'; |
|
|
|
|
22
|
|
|
const Mask_ClassFile = 'Classes/class.tx_t3deploy_%sController.php'; |
|
|
|
|
23
|
|
|
const Mask_Action = '%sAction'; |
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected $classInstances = array(); |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Creates this object. |
32
|
|
|
*/ |
33
|
|
|
public function __construct() { |
34
|
|
|
parent::__construct(); |
35
|
|
|
|
36
|
|
|
$this->setCliOptions(); |
37
|
|
|
|
38
|
|
|
$this->cli_help = array_merge($this->cli_help, array( |
39
|
|
|
'name' => 'tx_t3deploy_dispatch', |
40
|
|
|
'synopsis' => self::ExtKey . ' controller action ###OPTIONS###', |
41
|
|
|
'description' => 'TYPO3 dispatcher for database related operations.', |
42
|
|
|
'examples' => 'typo3/cli_dispatch.phpsh ' . self::ExtKey . ' database updateStructure', |
43
|
|
|
'author' => '(c) 2012 - 2016 AOE GmbH <[email protected]>', |
44
|
|
|
)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Sets the CLI arguments. |
49
|
|
|
* |
50
|
|
|
* @param array $arguments |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
|
|
public function setCliArguments(array $arguments) { |
54
|
|
|
$this->cli_args = $arguments; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Gets or generates an instance of the given class name. |
59
|
|
|
* |
60
|
|
|
* @param string $className |
61
|
|
|
* @return object |
62
|
|
|
*/ |
63
|
|
|
public function getClassInstance($className) { |
64
|
|
|
if (!isset($this->classInstances[$className])) { |
65
|
|
|
$this->classInstances[$className] = GeneralUtility::makeInstance($className); |
66
|
|
|
} |
67
|
|
|
return $this->classInstances[$className]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Sets an instance for the given class name. |
72
|
|
|
* |
73
|
|
|
* @param string $className |
74
|
|
|
* @param object $classInstance |
75
|
|
|
* @return void |
76
|
|
|
*/ |
77
|
|
|
public function setClassInstance($className, $classInstance) { |
78
|
|
|
$this->classInstances[$className] = $classInstance; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Dispatches the requested actions to the accordant controller. |
83
|
|
|
* |
84
|
|
|
* @return mixed |
85
|
|
|
* @throws Exception |
86
|
|
|
*/ |
87
|
|
|
public function dispatch() { |
88
|
|
|
$controller = (string)$this->cli_args['_DEFAULT'][1]; |
89
|
|
|
$action = (string)$this->cli_args['_DEFAULT'][2]; |
90
|
|
|
|
91
|
|
|
if (!$controller || !$action) { |
92
|
|
|
$this->cli_validateArgs(); |
93
|
|
|
$this->cli_help(); |
94
|
|
|
exit(1); |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$className = sprintf(self::Mask_ClassName, $controller); |
98
|
|
|
$classFile = sprintf(self::Mask_ClassFile, $controller); |
99
|
|
|
$actionName = sprintf(self::Mask_Action, $action); |
100
|
|
|
|
101
|
|
|
if (!class_exists($className)) { |
102
|
|
|
GeneralUtility::requireOnce(PATH_tx_t3deploy . $classFile); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$instance = $this->getClassInstance($className); |
106
|
|
|
|
107
|
|
|
if (!is_callable(array($instance, $actionName))) { |
108
|
|
|
throw new Exception('The action ' . $action . ' is not implemented in controller ' . $controller); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$result = call_user_func_array( |
112
|
|
|
array($instance, $actionName), |
113
|
|
|
array($this->cli_args) |
114
|
|
|
); |
115
|
|
|
|
116
|
|
|
return $result; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Sets the CLI options for help. |
121
|
|
|
* |
122
|
|
|
* @return void |
123
|
|
|
*/ |
124
|
|
|
protected function setCliOptions() { |
125
|
|
|
$this->cli_options = array( |
126
|
|
|
array('--verbose', 'Report changes'), |
127
|
|
|
array('-v', 'Same as --verbose'), |
128
|
|
|
array('--execute', 'Execute changes (updates, removals)'), |
129
|
|
|
array('-e', 'Same as --execute'), |
130
|
|
|
array('--remove', 'Include structure differences for removal'), |
131
|
|
|
array('-r', 'Same as --remove'), |
132
|
|
|
array('--drop-keys', 'Removes key modifications that will cause errors'), |
133
|
|
|
array('--dump-file', 'Dump changes to file'), |
134
|
|
|
array('--excludes', 'Exclude update types (add,change,create_table,change_table,drop,drop_table,clear_table)') |
135
|
|
|
); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|