[BUGFIX] Fix wrong handling of php and TYPO3 dependencies
[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 textfile 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 \TYPO3\CMS\Extensionmanager\Controller\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\Service\ExtensionManagementService
51 * @inject
52 */
53 protected $managementService;
54
55 /**
56 * Toggle extension installation state action
57 *
58 * @param string $extension
59 */
60 protected function toggleExtensionInstallationStateAction($extension) {
61 $installedExtensions = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getLoadedExtensionListArray();
62 try {
63 if (in_array($extension, $installedExtensions)) {
64 // uninstall
65 $this->installUtility->uninstall($extension);
66 } else {
67 // install
68 $this->managementService->resolveDependenciesAndInstall(
69 $this->installUtility->enrichExtensionWithDetails($extension)
70 );
71 }
72 } catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
73 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
74 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
75 htmlspecialchars($e->getMessage()),
76 '',
77 \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR,
78 TRUE
79 );
80 $this->getControllerContext()->getFlashMessageQueue()->enqueue($flashMessage);
81 }
82 $this->redirect('index', 'List', NULL, array(self::TRIGGER_RefreshModuleMenu => TRUE));
83 }
84
85 /**
86 * Remove an extension (if it is still installed, uninstall it first)
87 *
88 * @param string $extension
89 */
90 protected function removeExtensionAction($extension) {
91 $success = TRUE;
92 $message = '';
93 try {
94 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extension)) {
95 $this->installUtility->uninstall($extension);
96 }
97 $this->installUtility->removeExtension($extension);
98 } catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
99 $message = $e->getMessage();
100 $success = FALSE;
101 }
102 $this->view->assign('success', $success)->assign('message', $message)->assign('extension', $extension);
103 }
104
105 /**
106 * Download an extension as a zip file
107 *
108 * @param string $extension
109 */
110 protected function downloadExtensionZipAction($extension) {
111 $fileName = $this->fileHandlingUtility->createZipFileFromExtension($extension);
112 $this->fileHandlingUtility->sendZipFileToBrowserAndDelete($fileName);
113 }
114
115 /**
116 * Download data of an extension as sql statements
117 *
118 * @param string $extension
119 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
120 */
121 protected function downloadExtensionDataAction($extension) {
122 $error = NULL;
123 $sqlData = $this->installUtility->getExtensionSqlDataDump($extension);
124 $dump = $sqlData['extTables'] . $sqlData['staticSql'];
125 $fileName = $extension . '_sqlDump.sql';
126 $filePath = PATH_site . 'typo3temp/' . $fileName;
127 $error = \TYPO3\CMS\Core\Utility\GeneralUtility::writeFileToTypo3tempDir($filePath, $dump);
128 if (is_string($error)) {
129 throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException($error, 1343048718);
130 }
131 $this->fileHandlingUtility->sendSqlDumpFileToBrowserAndDelete($filePath, $fileName);
132 }
133 }
134 ?>