|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the TYPO3 CMS project. |
|
5
|
|
|
* |
|
6
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
7
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
8
|
|
|
* of the License, or any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please read the |
|
11
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
12
|
|
|
* |
|
13
|
|
|
* The TYPO3 project - inspiring people to share! |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace TYPO3\CMS\Impexp\Controller; |
|
17
|
|
|
|
|
18
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
19
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
20
|
|
|
use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException; |
|
21
|
|
|
use TYPO3\CMS\Backend\Template\ModuleTemplate; |
|
22
|
|
|
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; |
|
23
|
|
|
use TYPO3\CMS\Core\Imaging\Icon; |
|
24
|
|
|
use TYPO3\CMS\Core\Imaging\IconFactory; |
|
25
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
|
26
|
|
|
use TYPO3\CMS\Core\Resource\Exception; |
|
27
|
|
|
use TYPO3\CMS\Core\Resource\Folder; |
|
28
|
|
|
use TYPO3\CMS\Core\Type\Bitmask\Permission; |
|
29
|
|
|
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; |
|
30
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
31
|
|
|
use TYPO3\CMS\Fluid\View\StandaloneView; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Main script class for the Import / Export facility. |
|
35
|
|
|
* |
|
36
|
|
|
* @internal this is a TYPO3 Backend controller implementation and not part of TYPO3's Core API. |
|
37
|
|
|
*/ |
|
38
|
|
|
abstract class ImportExportController |
|
39
|
|
|
{ |
|
40
|
|
|
/** |
|
41
|
|
|
* The integer value of the GET/POST var, 'id'. Used for submodules to the 'Web' module (page id) |
|
42
|
|
|
* |
|
43
|
|
|
* @var int |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $id; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Array containing the current page. |
|
49
|
|
|
* |
|
50
|
|
|
* @var array |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $pageinfo; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* A WHERE clause for selection records from the pages table based on read-permissions of the current backend user. |
|
56
|
|
|
* |
|
57
|
|
|
* @var string |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $perms_clause; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @var LanguageService |
|
63
|
|
|
*/ |
|
64
|
|
|
protected $lang; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @var IconFactory |
|
68
|
|
|
*/ |
|
69
|
|
|
protected $iconFactory; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* The name of the module |
|
73
|
|
|
* |
|
74
|
|
|
* @var string |
|
75
|
|
|
*/ |
|
76
|
|
|
protected $moduleName = ''; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* ModuleTemplate Container |
|
80
|
|
|
* |
|
81
|
|
|
* @var ModuleTemplate |
|
82
|
|
|
*/ |
|
83
|
|
|
protected $moduleTemplate; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* The name of the shortcut for this page |
|
87
|
|
|
* |
|
88
|
|
|
* @var string |
|
89
|
|
|
*/ |
|
90
|
|
|
protected $shortcutName; |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @var StandaloneView |
|
94
|
|
|
*/ |
|
95
|
|
|
protected $standaloneView; |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Return URL |
|
99
|
|
|
* |
|
100
|
|
|
* @var string |
|
101
|
|
|
*/ |
|
102
|
|
|
protected $returnUrl; |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Constructor |
|
106
|
|
|
*/ |
|
107
|
|
|
public function __construct() |
|
108
|
|
|
{ |
|
109
|
|
|
$this->iconFactory = GeneralUtility::makeInstance(IconFactory::class); |
|
110
|
|
|
$this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class); |
|
111
|
|
|
|
|
112
|
|
|
$templatePath = ExtensionManagementUtility::extPath('impexp') . 'Resources/Private/'; |
|
113
|
|
|
|
|
114
|
|
|
$this->standaloneView = GeneralUtility::makeInstance(StandaloneView::class); |
|
115
|
|
|
$this->standaloneView->setTemplateRootPaths([$templatePath . 'Templates/ImportExport/']); |
|
116
|
|
|
$this->standaloneView->setLayoutRootPaths([$templatePath . 'Layouts/']); |
|
117
|
|
|
$this->standaloneView->setPartialRootPaths([$templatePath . 'Partials/']); |
|
118
|
|
|
$this->standaloneView->getRequest()->setControllerExtensionName('impexp'); |
|
119
|
|
|
|
|
120
|
|
|
$this->id = (int)GeneralUtility::_GP('id'); |
|
121
|
|
|
$this->perms_clause = $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW); |
|
122
|
|
|
$this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl')); |
|
123
|
|
|
$this->lang = $this->getLanguageService(); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Injects the request object for the current request and gathers all data |
|
128
|
|
|
* |
|
129
|
|
|
* IMPORTING DATA: |
|
130
|
|
|
* |
|
131
|
|
|
* Incoming array has syntax: |
|
132
|
|
|
* GETvar 'id' = import page id (must be readable) |
|
133
|
|
|
* |
|
134
|
|
|
* file = pointing to filename relative to public web path |
|
135
|
|
|
* |
|
136
|
|
|
* [all relation fields are clear, but not files] |
|
137
|
|
|
* - page-tree is written first |
|
138
|
|
|
* - then remaining pages (to the root of import) |
|
139
|
|
|
* - then all other records are written either to related included pages or if not found to import-root (should be a sysFolder in most cases) |
|
140
|
|
|
* - then all internal relations are set and non-existing relations removed, relations to static tables preserved. |
|
141
|
|
|
* |
|
142
|
|
|
* EXPORTING DATA: |
|
143
|
|
|
* |
|
144
|
|
|
* Incoming array has syntax: |
|
145
|
|
|
* |
|
146
|
|
|
* file[] = file |
|
147
|
|
|
* dir[] = dir |
|
148
|
|
|
* list[] = table:pid |
|
149
|
|
|
* record[] = table:uid |
|
150
|
|
|
* |
|
151
|
|
|
* pagetree[id] = (single id) |
|
152
|
|
|
* pagetree[levels]=1,2,3, -1 = currently unpacked tree, -2 = only tables on page |
|
153
|
|
|
* pagetree[tables][]=table/_ALL |
|
154
|
|
|
* |
|
155
|
|
|
* external_ref[tables][]=table/_ALL |
|
156
|
|
|
* |
|
157
|
|
|
* @param ServerRequestInterface $request |
|
158
|
|
|
* @return ResponseInterface |
|
159
|
|
|
* @throws RouteNotFoundException |
|
160
|
|
|
*/ |
|
161
|
|
|
abstract public function mainAction(ServerRequestInterface $request): ResponseInterface; |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Create the panel of buttons for submitting the form or otherwise perform operations. |
|
165
|
|
|
*/ |
|
166
|
|
|
protected function getButtons(): void |
|
167
|
|
|
{ |
|
168
|
|
|
$buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar(); |
|
169
|
|
|
if ($this->getBackendUser()->mayMakeShortcut()) { |
|
170
|
|
|
$shortcutButton = $buttonBar->makeShortcutButton() |
|
171
|
|
|
->setGetVariables(['tx_impexp']) |
|
172
|
|
|
->setDisplayName($this->shortcutName) |
|
173
|
|
|
->setModuleName($this->moduleName); |
|
174
|
|
|
$buttonBar->addButton($shortcutButton); |
|
175
|
|
|
} |
|
176
|
|
|
// back button |
|
177
|
|
|
if ($this->returnUrl) { |
|
178
|
|
|
$backButton = $buttonBar->makeLinkButton() |
|
179
|
|
|
->setHref($this->returnUrl) |
|
180
|
|
|
->setTitle($this->lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.goBack')) |
|
181
|
|
|
->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL)); |
|
182
|
|
|
$buttonBar->addButton($backButton); |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Returns a \TYPO3\CMS\Core\Resource\Folder object for saving export files |
|
188
|
|
|
* to the server and is also used for uploading import files. |
|
189
|
|
|
* |
|
190
|
|
|
* @throws \InvalidArgumentException |
|
191
|
|
|
* @return Folder|null |
|
192
|
|
|
*/ |
|
193
|
|
|
protected function getDefaultImportExportFolder(): ?Folder |
|
194
|
|
|
{ |
|
195
|
|
|
$defaultImportExportFolder = null; |
|
196
|
|
|
|
|
197
|
|
|
$defaultTemporaryFolder = $this->getBackendUser()->getDefaultUploadTemporaryFolder(); |
|
198
|
|
|
if ($defaultTemporaryFolder !== null) { |
|
199
|
|
|
$importExportFolderName = 'importexport'; |
|
200
|
|
|
$createFolder = !$defaultTemporaryFolder->hasFolder($importExportFolderName); |
|
201
|
|
|
if ($createFolder === true) { |
|
202
|
|
|
try { |
|
203
|
|
|
$defaultImportExportFolder = $defaultTemporaryFolder->createFolder($importExportFolderName); |
|
204
|
|
|
} catch (Exception $folderAccessException) { |
|
|
|
|
|
|
205
|
|
|
} |
|
206
|
|
|
} else { |
|
207
|
|
|
$defaultImportExportFolder = $defaultTemporaryFolder->getSubfolder($importExportFolderName); |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
return $defaultImportExportFolder; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* @return BackendUserAuthentication |
|
216
|
|
|
*/ |
|
217
|
|
|
protected function getBackendUser(): BackendUserAuthentication |
|
218
|
|
|
{ |
|
219
|
|
|
return $GLOBALS['BE_USER']; |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* @return LanguageService |
|
224
|
|
|
*/ |
|
225
|
|
|
protected function getLanguageService(): LanguageService |
|
226
|
|
|
{ |
|
227
|
|
|
return $GLOBALS['LANG']; |
|
228
|
|
|
} |
|
229
|
|
|
} |
|
230
|
|
|
|