[TASK] Re-work/simplify copyright header in PHP files - Part 9
[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 array<Tx_Extensionmanager_Domain_Model_Extension>
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 (array_key_exists($extension->getExtensionKey(), $this->extensionStorage)) {
65 if (!($this->extensionStorage[$extension->getExtensionKey()] === $extension)) {
66 throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(
67 $extension->getExtensionKey() . ' was requested to be downloaded in different versions.',
68 1342432101
69 );
70 }
71 }
72 $this->extensionStorage[$stack][$extension->getExtensionKey()] = $extension;
73 }
74
75 /**
76 * @return array
77 */
78 public function getExtensionQueue() {
79 return $this->extensionStorage;
80 }
81
82 /**
83 * Remove an extension from download queue
84 *
85 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension
86 * @param string $stack Stack to remove extension from (download, update or install)
87 * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
88 * @return void
89 */
90 public function removeExtensionFromQueue(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $stack = 'download') {
91 if (!is_string($stack) || !in_array($stack, array('download', 'update'))) {
92 throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Stack has to be either "download" or "update"', 1342432104);
93 }
94 if (array_key_exists($stack, $this->extensionStorage) && is_array($this->extensionStorage[$stack])) {
95 if (array_key_exists($extension->getExtensionKey(), $this->extensionStorage[$stack])) {
96 unset($this->extensionStorage[$stack][$extension->getExtensionKey()]);
97 }
98 }
99 }
100
101 /**
102 * Adds an extension to the install queue for later installation
103 *
104 * @param string $extensionKey
105 * @return void
106 */
107 public function addExtensionToInstallQueue($extensionKey) {
108 $this->extensionInstallStorage[$extensionKey] = $extensionKey;
109 }
110
111 /**
112 * Removes an extension from the install queue
113 *
114 * @param string $extensionKey
115 * @return void
116 */
117 public function removeExtensionFromInstallQueue($extensionKey) {
118 if (array_key_exists($extensionKey, $this->extensionInstallStorage)) {
119 unset($this->extensionInstallStorage[$extensionKey]);
120 }
121 }
122
123 /**
124 * Adds an extension to the copy queue for later copying
125 *
126 * @param string $extensionKey
127 * @param string $sourceFolder
128 * @return void
129 */
130 public function addExtensionToCopyQueue($extensionKey, $sourceFolder) {
131 $this->extensionCopyStorage[$extensionKey] = $sourceFolder;
132 }
133
134 /**
135 * Remove an extension from extension copy storage
136 *
137 * @param $extensionKey
138 * @return void
139 */
140 public function removeExtensionFromCopyQueue($extensionKey) {
141 if (array_key_exists($extensionKey, $this->extensionCopyStorage)) {
142 unset($this->extensionCopyStorage[$extensionKey]);
143 }
144 }
145
146 /**
147 * Gets the extension installation queue
148 *
149 * @return array
150 */
151 public function getExtensionInstallStorage() {
152 return $this->extensionInstallStorage;
153 }
154
155 /**
156 * Gets the extension copy queue
157 *
158 * @return array
159 */
160 public function getExtensionCopyStorage() {
161 return $this->extensionCopyStorage;
162 }
163
164 }