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