TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
DownloadQueue.php
Go to the documentation of this file.
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 
18 
23 {
29  protected $extensionStorage = [];
30 
36  protected $extensionInstallStorage = [];
37 
43  protected $extensionCopyStorage = [];
44 
48  protected $listUtility;
49 
53  public function injectListUtility(\TYPO3\CMS\Extensionmanager\Utility\ListUtility $listUtility)
54  {
55  $this->listUtility = $listUtility;
56  }
57 
68  public function addExtensionToQueue(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $stack = 'download')
69  {
70  if (!is_string($stack) || !in_array($stack, ['download', 'update'])) {
71  throw new ExtensionManagerException('Stack has to be either "download" or "update"', 1342432103);
72  }
73  if (!isset($this->extensionStorage[$stack])) {
74  $this->extensionStorage[$stack] = [];
75  }
76  if (array_key_exists($extension->getExtensionKey(), $this->extensionStorage[$stack])) {
77  if ($this->extensionStorage[$stack][$extension->getExtensionKey()] !== $extension) {
78  throw new ExtensionManagerException(
79  $extension->getExtensionKey() . ' was requested to be downloaded in different versions (' . $extension->getVersion()
80  . ' and ' . $this->extensionStorage[$stack][$extension->getExtensionKey()]->getVersion() . ').',
81  1342432101
82  );
83  }
84  }
85  $this->extensionStorage[$stack][$extension->getExtensionKey()] = $extension;
86  }
87 
91  public function getExtensionQueue()
92  {
94  }
95 
104  public function removeExtensionFromQueue(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $stack = 'download')
105  {
106  if (!is_string($stack) || !in_array($stack, ['download', 'update'])) {
107  throw new ExtensionManagerException('Stack has to be either "download" or "update"', 1342432104);
108  }
109  if (array_key_exists($stack, $this->extensionStorage) && is_array($this->extensionStorage[$stack])) {
110  if (array_key_exists($extension->getExtensionKey(), $this->extensionStorage[$stack])) {
111  unset($this->extensionStorage[$stack][$extension->getExtensionKey()]);
112  }
113  }
114  }
115 
122  public function addExtensionToInstallQueue($extension)
123  {
124  $this->extensionInstallStorage[$extension->getExtensionKey()] = $extension;
125  }
126 
133  public function removeExtensionFromInstallQueue($extensionKey)
134  {
135  if (array_key_exists($extensionKey, $this->extensionInstallStorage)) {
136  unset($this->extensionInstallStorage[$extensionKey]);
137  }
138  }
139 
147  public function addExtensionToCopyQueue($extensionKey, $sourceFolder)
148  {
149  $this->extensionCopyStorage[$extensionKey] = $sourceFolder;
150  }
151 
158  public function removeExtensionFromCopyQueue($extensionKey)
159  {
160  if (array_key_exists($extensionKey, $this->extensionCopyStorage)) {
161  unset($this->extensionCopyStorage[$extensionKey]);
162  }
163  }
164 
170  public function getExtensionInstallStorage()
171  {
173  }
174 
180  public function getExtensionCopyStorage()
181  {
183  }
184 
191  public function isQueueEmpty($stack = 'download')
192  {
193  return empty($this->extensionStorage[$stack]);
194  }
195 
201  public function isCopyQueueEmpty()
202  {
203  return empty($this->extensionCopyStorage);
204  }
205 
211  public function isInstallQueueEmpty()
212  {
213  return empty($this->extensionInstallStorage);
214  }
215 
222  public function resetExtensionQueue($stack = null)
223  {
224  $storage = [];
225  if ($stack === null) {
226  $storage = $this->extensionStorage;
227  $this->extensionStorage = [];
228  } elseif (isset($this->extensionStorage[$stack])) {
229  $storage = $this->extensionStorage[$stack];
230  $this->extensionStorage[$stack] = [];
231  }
232 
233  return $storage;
234  }
235 
240  public function resetExtensionCopyStorage()
241  {
242  $storage = $this->extensionCopyStorage;
243  $this->extensionCopyStorage = [];
244 
245  return $storage;
246  }
247 
253  {
255  $this->extensionInstallStorage = [];
256 
257  return $storage;
258  }
259 }
addExtensionToQueue(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $stack= 'download')
injectListUtility(\TYPO3\CMS\Extensionmanager\Utility\ListUtility $listUtility)
removeExtensionFromQueue(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $stack= 'download')