[BUGFIX] Correctly check stack in DownloadQueue
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Domain / Model / DownloadQueue.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Domain\Model;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 /**
17 * Download Queue - storage for extensions to be downloaded
18 *
19 * @author Susanne Moog <typo3@susannemoog.de>
20 */
21 class DownloadQueue implements \TYPO3\CMS\Core\SingletonInterface {
22
23 /**
24 * Storage for extensions to be downloaded
25 *
26 * @var Extension[string][string]
27 */
28 protected $extensionStorage = array();
29
30 /**
31 * Storage for extensions to be installed
32 *
33 * @var array
34 */
35 protected $extensionInstallStorage = array();
36
37 /**
38 * Storage for extensions to be copied
39 *
40 * @var array
41 */
42 protected $extensionCopyStorage = array();
43
44 /**
45 * @var \TYPO3\CMS\Extensionmanager\Utility\ListUtility
46 * @inject
47 */
48 protected $listUtility;
49
50 /**
51 * Adds an extension to the download queue.
52 * If the extension was already requested in a different version
53 * an exception is thrown.
54 *
55 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
56 * @param string $stack
57 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
58 * @return void
59 */
60 public function addExtensionToQueue(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $stack = 'download') {
61 if (!is_string($stack) || !in_array($stack, array('download', 'update'))) {
62 throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Stack has to be either "download" or "update"', 1342432103);
63 }
64 if (!isset($this->extensionStorage[$stack])) {
65 $this->extensionStorage[$stack] = array();
66 }
67 if (array_key_exists($extension->getExtensionKey(), $this->extensionStorage[$stack])) {
68 if ($this->extensionStorage[$stack][$extension->getExtensionKey()] !== $extension) {
69 throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(
70 $extension->getExtensionKey() . ' was requested to be downloaded in different versions.',
71 1342432101
72 );
73 }
74 }
75 $this->extensionStorage[$stack][$extension->getExtensionKey()] = $extension;
76 }
77
78 /**
79 * @return array
80 */
81 public function getExtensionQueue() {
82 return $this->extensionStorage;
83 }
84
85 /**
86 * Remove an extension from download queue
87 *
88 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
89 * @param string $stack Stack to remove extension from (download, update or install)
90 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
91 * @return void
92 */
93 public function removeExtensionFromQueue(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $stack = 'download') {
94 if (!is_string($stack) || !in_array($stack, array('download', 'update'))) {
95 throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Stack has to be either "download" or "update"', 1342432104);
96 }
97 if (array_key_exists($stack, $this->extensionStorage) && is_array($this->extensionStorage[$stack])) {
98 if (array_key_exists($extension->getExtensionKey(), $this->extensionStorage[$stack])) {
99 unset($this->extensionStorage[$stack][$extension->getExtensionKey()]);
100 }
101 }
102 }
103
104 /**
105 * Adds an extension to the install queue for later installation
106 *
107 * @param string $extensionKey
108 * @return void
109 */
110 public function addExtensionToInstallQueue($extensionKey) {
111 $this->extensionInstallStorage[$extensionKey] = $extensionKey;
112 }
113
114 /**
115 * Removes an extension from the install queue
116 *
117 * @param string $extensionKey
118 * @return void
119 */
120 public function removeExtensionFromInstallQueue($extensionKey) {
121 if (array_key_exists($extensionKey, $this->extensionInstallStorage)) {
122 unset($this->extensionInstallStorage[$extensionKey]);
123 }
124 }
125
126 /**
127 * Adds an extension to the copy queue for later copying
128 *
129 * @param string $extensionKey
130 * @param string $sourceFolder
131 * @return void
132 */
133 public function addExtensionToCopyQueue($extensionKey, $sourceFolder) {
134 $this->extensionCopyStorage[$extensionKey] = $sourceFolder;
135 }
136
137 /**
138 * Remove an extension from extension copy storage
139 *
140 * @param $extensionKey
141 * @return void
142 */
143 public function removeExtensionFromCopyQueue($extensionKey) {
144 if (array_key_exists($extensionKey, $this->extensionCopyStorage)) {
145 unset($this->extensionCopyStorage[$extensionKey]);
146 }
147 }
148
149 /**
150 * Gets the extension installation queue
151 *
152 * @return array
153 */
154 public function getExtensionInstallStorage() {
155 return $this->extensionInstallStorage;
156 }
157
158 /**
159 * Gets the extension copy queue
160 *
161 * @return array
162 */
163 public function getExtensionCopyStorage() {
164 return $this->extensionCopyStorage;
165 }
166
167 }