3fcdc15ec71e786c8cb305744063dabdc40c4eb1
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Controller / ActionController.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Susanne Moog, <typo3@susannemoog.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Controller for handling extension related actions like
31 * installing, removing, downloading of data or files
32 *
33 * @author Susanne Moog <typo3@susannemoog.de>
34 */
35 class ActionController extends AbstractController {
36
37 /**
38 * @var \TYPO3\CMS\Extensionmanager\Utility\InstallUtility
39 * @inject
40 */
41 protected $installUtility;
42
43 /**
44 * @var \TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility
45 * @inject
46 */
47 protected $fileHandlingUtility;
48
49 /**
50 * @var \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility
51 * @inject
52 */
53 protected $extensionModelUtility;
54
55 /**
56 * @var \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService
57 * @inject
58 */
59 protected $managementService;
60
61 /**
62 * Toggle extension installation state action
63 *
64 * @param string $extensionKey
65 */
66 protected function toggleExtensionInstallationStateAction($extensionKey) {
67 $installedExtensions = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getLoadedExtensionListArray();
68 try {
69 if (in_array($extensionKey, $installedExtensions)) {
70 // uninstall
71 $this->installUtility->uninstall($extensionKey);
72 } else {
73 // install
74 $extension = $this->extensionModelUtility->mapExtensionArrayToModel(
75 $this->installUtility->enrichExtensionWithDetails($extensionKey)
76 );
77 if ($this->managementService->installExtension($extension) === FALSE) {
78 $this->redirect('unresolvedDependencies', 'List', NULL, array('extensionKey' => $extensionKey));
79 }
80 }
81 } catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
82 $this->addFlashMessage(htmlspecialchars($e->getMessage()), '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
83 } catch (\TYPO3\Flow\Package\Exception\PackageStatesFileNotWritableException $e) {
84 $this->addFlashMessage(htmlspecialchars($e->getMessage()), '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
85 }
86 $this->redirect('index', 'List', NULL, array(self::TRIGGER_RefreshModuleMenu => TRUE));
87 }
88
89 /**
90 * Install an extension and omit dependency checking
91 *
92 * @param string $extensionKey
93 * @return void
94 */
95 public function installExtensionWithoutSystemDependencyCheckAction($extensionKey) {
96 $this->managementService->setSkipSystemDependencyCheck(TRUE);
97 $this->forward('toggleExtensionInstallationState', NULL, NULL, array('extensionKey' => $extensionKey));
98 }
99
100 /**
101 * Remove an extension (if it is still installed, uninstall it first)
102 *
103 * @param string $extension
104 * @return string
105 */
106 protected function removeExtensionAction($extension) {
107 try {
108 $this->installUtility->removeExtension($extension);
109 $this->addFlashMessage(
110 \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
111 'extensionList.remove.message',
112 'extensionmanager',
113 array(
114 'extension' => $extension,
115 )
116 )
117 );
118 } catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
119 $this->addFlashMessage(htmlspecialchars($e->getMessage()), '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
120 }
121
122 return '';
123 }
124
125 /**
126 * Download an extension as a zip file
127 *
128 * @param string $extension
129 */
130 protected function downloadExtensionZipAction($extension) {
131 $fileName = $this->fileHandlingUtility->createZipFileFromExtension($extension);
132 $this->fileHandlingUtility->sendZipFileToBrowserAndDelete($fileName);
133 }
134
135 /**
136 * Download data of an extension as sql statements
137 *
138 * @param string $extension
139 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
140 */
141 protected function downloadExtensionDataAction($extension) {
142 $error = NULL;
143 $sqlData = $this->installUtility->getExtensionSqlDataDump($extension);
144 $dump = $sqlData['extTables'] . $sqlData['staticSql'];
145 $fileName = $extension . '_sqlDump.sql';
146 $filePath = PATH_site . 'typo3temp/' . $fileName;
147 $error = \TYPO3\CMS\Core\Utility\GeneralUtility::writeFileToTypo3tempDir($filePath, $dump);
148 if (is_string($error)) {
149 throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException($error, 1343048718);
150 }
151 $this->fileHandlingUtility->sendSqlDumpFileToBrowserAndDelete($filePath, $fileName);
152 }
153 }