/
ActionController.php
177 lines (158 loc) · 6.12 KB
/
ActionController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
namespace TYPO3\CMS\Extensionmanager\Controller;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Registry;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Controller for handling extension related actions like
* installing, removing, downloading of data or files
*/
class ActionController extends AbstractController
{
/**
* @var \TYPO3\CMS\Extensionmanager\Utility\InstallUtility
*/
protected $installUtility;
/**
* @var \TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility
*/
protected $fileHandlingUtility;
/**
* @var \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility
*/
protected $extensionModelUtility;
/**
* @var \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService
*/
protected $managementService;
/**
* @param \TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility
*/
public function injectInstallUtility(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility $installUtility)
{
$this->installUtility = $installUtility;
}
/**
* @param \TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility $fileHandlingUtility
*/
public function injectFileHandlingUtility(\TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility $fileHandlingUtility)
{
$this->fileHandlingUtility = $fileHandlingUtility;
}
/**
* @param \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility $extensionModelUtility
*/
public function injectExtensionModelUtility(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility $extensionModelUtility)
{
$this->extensionModelUtility = $extensionModelUtility;
}
/**
* @param \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService $managementService
*/
public function injectManagementService(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService $managementService)
{
$this->managementService = $managementService;
}
/**
* Toggle extension installation state action
*
* @param string $extensionKey
*/
protected function toggleExtensionInstallationStateAction($extensionKey)
{
$installedExtensions = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getLoadedExtensionListArray();
try {
if (in_array($extensionKey, $installedExtensions)) {
// uninstall
$this->installUtility->uninstall($extensionKey);
} else {
// install
$extension = $this->extensionModelUtility->mapExtensionArrayToModel(
$this->installUtility->enrichExtensionWithDetails($extensionKey, false)
);
if ($this->managementService->installExtension($extension) === false) {
$this->redirect('unresolvedDependencies', 'List', null, ['extensionKey' => $extensionKey]);
}
}
} catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
$this->addFlashMessage($e->getMessage(), '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
} catch (\TYPO3\CMS\Core\Package\Exception\PackageStatesFileNotWritableException $e) {
$this->addFlashMessage($e->getMessage(), '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
}
$this->redirect('index', 'List', null, [
self::TRIGGER_RefreshModuleMenu => true,
self::TRIGGER_RefreshTopbar => true
]);
}
/**
* Install an extension and omit dependency checking
*
* @param string $extensionKey
*/
public function installExtensionWithoutSystemDependencyCheckAction($extensionKey)
{
$this->managementService->setSkipDependencyCheck(true);
$this->forward('toggleExtensionInstallationState', null, null, ['extensionKey' => $extensionKey]);
}
/**
* Remove an extension (if it is still installed, uninstall it first)
*
* @param string $extension
* @return string
*/
protected function removeExtensionAction($extension)
{
try {
$this->installUtility->removeExtension($extension);
$this->addFlashMessage(
\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
'extensionList.remove.message',
'extensionmanager',
[
'extension' => $extension,
]
)
);
} catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
$this->addFlashMessage($e->getMessage(), '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
} catch (\TYPO3\CMS\Core\Package\Exception $e) {
$this->addFlashMessage($e->getMessage(), '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
}
return '';
}
/**
* Download an extension as a zip file
*
* @param string $extension
*/
protected function downloadExtensionZipAction($extension)
{
$fileName = $this->fileHandlingUtility->createZipFileFromExtension($extension);
$this->fileHandlingUtility->sendZipFileToBrowserAndDelete($fileName);
}
/**
* Reloads the static SQL data of an extension
*
* @param string $extension
*/
protected function reloadExtensionDataAction($extension)
{
$extension = $this->installUtility->enrichExtensionWithDetails($extension, false);
$registryKey = $extension['siteRelPath'] . 'ext_tables_static+adt.sql';
$registry = GeneralUtility::makeInstance(Registry::class);
$registry->remove('extensionDataImport', $registryKey);
$this->installUtility->processExtensionSetup($extension['key']);
$this->redirect('index', 'List');
}
}