78e947d7c8140f578087958c7821729231c50889
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Domain / Model / DownloadQueue.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Domain\Model;
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 * Download Queue - storage for extensions to be downloaded
31 *
32 * @author Susanne Moog <typo3@susannemoog.de>
33 */
34 class DownloadQueue implements \TYPO3\CMS\Core\SingletonInterface {
35
36 /**
37 * Storage for extensions to be downloaded
38 *
39 * @var array<Tx_Extensionmanager_Domain_Model_Extension>
40 */
41 protected $extensionStorage = array();
42
43 /**
44 * Storage for extensions to be installed
45 *
46 * @var array
47 */
48 protected $extensionInstallStorage = array();
49
50 /**
51 * Storage for extensions to be copied
52 *
53 * @var array
54 */
55 protected $extensionCopyStorage = array();
56
57 /**
58 * @var \TYPO3\CMS\Extensionmanager\Utility\ListUtility
59 * @inject
60 */
61 protected $listUtility;
62
63 /**
64 * Adds an extension to the download queue.
65 * If the extension was already requested in a different version
66 * an exception is thrown.
67 *
68 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
69 * @param string $stack
70 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
71 * @return void
72 */
73 public function addExtensionToQueue(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $stack = 'download') {
74 if (!is_string($stack) || !in_array($stack, array('download', 'update'))) {
75 throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Stack has to be either "download" or "update"', 1342432103);
76 }
77 if (array_key_exists($extension->getExtensionKey(), $this->extensionStorage)) {
78 if (!($this->extensionStorage[$extension->getExtensionKey()] === $extension)) {
79 throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(
80 $extension->getExtensionKey() . ' was requested to be downloaded in different versions.',
81 1342432101
82 );
83 }
84 }
85 $this->extensionStorage[$stack][$extension->getExtensionKey()] = $extension;
86 }
87
88 /**
89 * @return array
90 */
91 public function getExtensionQueue() {
92 return $this->extensionStorage;
93 }
94
95 /**
96 * Remove an extension from download queue
97 *
98 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
99 * @param string $stack Stack to remove extension from (download, update or install)
100 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
101 * @return void
102 */
103 public function removeExtensionFromQueue(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $stack = 'download') {
104 if (!is_string($stack) || !in_array($stack, array('download', 'update'))) {
105 throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Stack has to be either "download" or "update"', 1342432104);
106 }
107 if (array_key_exists($stack, $this->extensionStorage) && is_array($this->extensionStorage[$stack])) {
108 if (array_key_exists($extension->getExtensionKey(), $this->extensionStorage[$stack])) {
109 unset($this->extensionStorage[$stack][$extension->getExtensionKey()]);
110 }
111 }
112 }
113
114 /**
115 * Adds an extension to the install queue for later installation
116 *
117 * @param string $extensionKey
118 * @return void
119 */
120 public function addExtensionToInstallQueue($extensionKey) {
121 $this->extensionInstallStorage[$extensionKey] = $extensionKey;
122 }
123
124 /**
125 * Removes an extension from the install queue
126 *
127 * @param string $extensionKey
128 * @return void
129 */
130 public function removeExtensionFromInstallQueue($extensionKey) {
131 if (array_key_exists($extensionKey, $this->extensionInstallStorage)) {
132 unset($this->extensionInstallStorage[$extensionKey]);
133 }
134 }
135
136 /**
137 * Adds an extension to the copy queue for later copying
138 *
139 * @param string $extensionKey
140 * @param string $sourceFolder
141 * @return void
142 */
143 public function addExtensionToCopyQueue($extensionKey, $sourceFolder) {
144 $this->extensionCopyStorage[$extensionKey] = $sourceFolder;
145 }
146
147 /**
148 * Remove an extension from extension copy storage
149 *
150 * @param $extensionKey
151 * @return void
152 */
153 public function removeExtensionFromCopyQueue($extensionKey) {
154 if (array_key_exists($extensionKey, $this->extensionCopyStorage)) {
155 unset($this->extensionCopyStorage[$extensionKey]);
156 }
157 }
158
159 /**
160 * Gets the extension installation queue
161 *
162 * @return array
163 */
164 public function getExtensionInstallStorage() {
165 return $this->extensionInstallStorage;
166 }
167
168 /**
169 * Gets the extension copy queue
170 *
171 * @return array
172 */
173 public function getExtensionCopyStorage() {
174 return $this->extensionCopyStorage;
175 }
176
177 }