2179008bfae8267072af6b9bab4cbe253f7bf96f
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Utility / DownloadUtility.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Utility;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Susanne Moog <susanne.moog@typo3.org>
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 * Utility for dealing with ext_emconf
31 *
32 * @author Susanne Moog <susanne.moog@typo3.org>
33 */
34 class DownloadUtility implements \TYPO3\CMS\Core\SingletonInterface {
35
36 /**
37 * @var \TYPO3\CMS\Extensionmanager\Utility\Connection\TerUtility
38 * @inject
39 */
40 protected $terUtility;
41
42 /**
43 * @var \TYPO3\CMS\Extensionmanager\Utility\Repository\Helper
44 * @inject
45 */
46 protected $repositoryHelper;
47
48 /**
49 * @var string
50 */
51 protected $downloadPath = 'Local';
52
53 /**
54 * @var \TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility
55 * @inject
56 */
57 protected $fileHandlingUtility;
58
59 /**
60 * Download an extension
61 *
62 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
63 * @return void
64 */
65 public function download(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension) {
66 $mirrorUrl = $this->repositoryHelper->getMirrors()->getMirrorUrl();
67 $fetchedExtension = $this->terUtility->fetchExtension($extension->getExtensionKey(), $extension->getVersion(), $extension->getMd5hash(), $mirrorUrl);
68 if (isset($fetchedExtension['extKey']) && !empty($fetchedExtension['extKey']) && is_string($fetchedExtension['extKey'])) {
69 $this->fileHandlingUtility->unpackExtensionFromExtensionDataArray($fetchedExtension, $extension, $this->getDownloadPath());
70 }
71 }
72
73 /**
74 * Set the download path
75 *
76 * @param string $downloadPath
77 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
78 * @return void
79 */
80 public function setDownloadPath($downloadPath) {
81 if (!in_array($downloadPath, \TYPO3\CMS\Extensionmanager\Domain\Model\Extension::returnAllowedInstallTypes())) {
82 throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(htmlspecialchars($downloadPath) . ' not in allowed download paths', 1344766387);
83 }
84 $this->downloadPath = $downloadPath;
85 }
86
87 /**
88 * Get the download path
89 *
90 * @return string
91 */
92 public function getDownloadPath() {
93 return $this->downloadPath;
94 }
95
96 }