‪TYPO3CMS  10.4
ImportExportController.php
Go to the documentation of this file.
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 
17 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
34 
42 {
48  protected ‪$id;
49 
55  protected ‪$pageinfo;
56 
62  protected ‪$perms_clause;
63 
67  protected ‪$lang;
68 
72  protected ‪$iconFactory;
73 
79  protected ‪$moduleName = 'xMOD_tximpexp';
80 
86  protected ‪$moduleTemplate;
87 
93  protected ‪$shortcutName;
94 
98  protected ‪$standaloneView;
99 
105  protected ‪$returnUrl;
106 
110  public function ‪__construct()
111  {
112  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
113  $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
114 
115  $templatePath = ‪ExtensionManagementUtility::extPath('impexp') . 'Resources/Private/';
116 
117  $this->standaloneView = GeneralUtility::makeInstance(StandaloneView::class);
118  $this->standaloneView->setTemplateRootPaths([$templatePath . 'Templates/ImportExport/']);
119  $this->standaloneView->setLayoutRootPaths([$templatePath . 'Layouts/']);
120  $this->standaloneView->setPartialRootPaths([$templatePath . 'Partials/']);
121  $this->standaloneView->getRequest()->setControllerExtensionName('impexp');
122 
123  $this->id = (int)GeneralUtility::_GP('id');
124  $this->perms_clause = $this->‪getBackendUser()->‪getPagePermsClause(‪Permission::PAGE_SHOW);
125  $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
126  $this->lang = $this->‪getLanguageService();
127  }
128 
164  public function ‪mainAction(ServerRequestInterface $request): ResponseInterface
165  {
166  // @todo: This method will become abstract in TYPO3 v11.
167  trigger_error('Route identifier xMOD_tximpexp is deprecated and will be removed in TYPO3 v11. Consider using tx_impexp_export or tx_impexp_import instead.', E_USER_DEPRECATED);
168 
169  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
170  $inData = GeneralUtility::_GP('tx_impexp');
171  $routeName = 'tx_impexp_export';
172  if ($inData === null || $inData['action'] === 'import') {
173  $routeName = 'tx_impexp_import';
174  }
175  unset($inData['action']);
176  $target = (string)$uriBuilder->buildUriFromRoute($routeName, ['tx_impexp' => $inData]);
177  return new ‪RedirectResponse($target, 308);
178  }
179 
183  protected function ‪getButtons(): void
184  {
185  $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
186  if ($this->‪getBackendUser()->mayMakeShortcut()) {
187  $shortcutButton = $buttonBar->makeShortcutButton()
188  ->setGetVariables(['tx_impexp'])
189  ->setDisplayName($this->shortcutName)
190  ->setModuleName($this->moduleName);
191  $buttonBar->addButton($shortcutButton);
192  }
193  // back button
194  if ($this->returnUrl) {
195  $backButton = $buttonBar->makeLinkButton()
196  ->setHref($this->returnUrl)
197  ->setTitle($this->lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.goBack'))
198  ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', ‪Icon::SIZE_SMALL));
199  $buttonBar->addButton($backButton);
200  }
201  }
202 
210  protected function ‪getDefaultImportExportFolder(): ?Folder
211  {
212  $defaultImportExportFolder = null;
213 
214  $defaultTemporaryFolder = $this->‪getBackendUser()->‪getDefaultUploadTemporaryFolder();
215  if ($defaultTemporaryFolder !== null) {
216  $importExportFolderName = 'importexport';
217  $createFolder = !$defaultTemporaryFolder->‪hasFolder($importExportFolderName);
218  if ($createFolder === true) {
219  try {
220  $defaultImportExportFolder = $defaultTemporaryFolder->createFolder($importExportFolderName);
221  } catch (‪Exception $folderAccessException) {
222  }
223  } else {
224  $defaultImportExportFolder = $defaultTemporaryFolder->getSubfolder($importExportFolderName);
225  }
226  }
227 
228  return $defaultImportExportFolder;
229  }
230 
234  protected function ‪getBackendUser(): BackendUserAuthentication
235  {
236  return ‪$GLOBALS['BE_USER'];
237  }
238 
242  protected function ‪getLanguageService(): LanguageService
243  {
244  return ‪$GLOBALS['LANG'];
245  }
246 }
‪TYPO3\CMS\Impexp\Controller\ImportExportController\mainAction
‪ResponseInterface mainAction(ServerRequestInterface $request)
Definition: ImportExportController.php:154
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:30
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$id
‪int $id
Definition: ImportExportController.php:47
‪TYPO3\CMS\Impexp\Controller
Definition: ExportController.php:18
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getPagePermsClause
‪string getPagePermsClause($perms)
Definition: BackendUserAuthentication.php:499
‪TYPO3\CMS\Core\Exception
Definition: Exception.php:22
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:26
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getDefaultUploadTemporaryFolder
‪TYPO3 CMS Core Resource Folder null getDefaultUploadTemporaryFolder()
Definition: BackendUserAuthentication.php:2001
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:33
‪TYPO3\CMS\Backend\Template\ModuleTemplate
Definition: ModuleTemplate.php:43
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$pageinfo
‪array $pageinfo
Definition: ImportExportController.php:53
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:24
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Impexp\Controller\ImportExportController
Definition: ImportExportController.php:42
‪TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException
Definition: RouteNotFoundException.php:22
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$standaloneView
‪StandaloneView $standaloneView
Definition: ImportExportController.php:89
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$moduleTemplate
‪ModuleTemplate $moduleTemplate
Definition: ImportExportController.php:79
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$lang
‪LanguageService $lang
Definition: ImportExportController.php:63
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:37
‪TYPO3\CMS\Impexp\Controller\ImportExportController\getButtons
‪getButtons()
Definition: ImportExportController.php:173
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$shortcutName
‪string $shortcutName
Definition: ImportExportController.php:85
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$returnUrl
‪string $returnUrl
Definition: ImportExportController.php:95
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:33
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$perms_clause
‪string $perms_clause
Definition: ImportExportController.php:59
‪TYPO3\CMS\Impexp\Controller\ImportExportController\getLanguageService
‪LanguageService getLanguageService()
Definition: ImportExportController.php:232
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:28
‪TYPO3\CMS\Impexp\Controller\ImportExportController\__construct
‪__construct()
Definition: ImportExportController.php:100
‪TYPO3\CMS\Fluid\View\StandaloneView
Definition: StandaloneView.php:34
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$moduleName
‪string $moduleName
Definition: ImportExportController.php:73
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Impexp\Controller\ImportExportController\getDefaultImportExportFolder
‪Folder null getDefaultImportExportFolder()
Definition: ImportExportController.php:200
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\extPath
‪static string extPath($key, $script='')
Definition: ExtensionManagementUtility.php:127
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Impexp\Controller\ImportExportController\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: ImportExportController.php:224
‪TYPO3\CMS\Core\Resource\Exception
Definition: AbstractFileOperationException.php:16
‪TYPO3\CMS\Core\Resource\Folder\hasFolder
‪bool hasFolder($name)
Definition: Folder.php:412
‪TYPO3\CMS\Impexp\Controller\ImportExportController\$iconFactory
‪IconFactory $iconFactory
Definition: ImportExportController.php:67