TYPO3 CMS  TYPO3_8-7
DownloadQueue.php
Go to the documentation of this file.
1 <?php
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 
67  public function addExtensionToQueue(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $stack = 'download')
68  {
69  if (!is_string($stack) || !in_array($stack, ['download', 'update'])) {
70  throw new ExtensionManagerException('Stack has to be either "download" or "update"', 1342432103);
71  }
72  if (!isset($this->extensionStorage[$stack])) {
73  $this->extensionStorage[$stack] = [];
74  }
75  if (array_key_exists($extension->getExtensionKey(), $this->extensionStorage[$stack])) {
76  if ($this->extensionStorage[$stack][$extension->getExtensionKey()] !== $extension) {
77  throw new ExtensionManagerException(
78  $extension->getExtensionKey() . ' was requested to be downloaded in different versions (' . $extension->getVersion()
79  . ' and ' . $this->extensionStorage[$stack][$extension->getExtensionKey()]->getVersion() . ').',
80  1342432101
81  );
82  }
83  }
84  $this->extensionStorage[$stack][$extension->getExtensionKey()] = $extension;
85  }
86 
90  public function getExtensionQueue()
91  {
93  }
94 
102  public function removeExtensionFromQueue(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $stack = 'download')
103  {
104  if (!is_string($stack) || !in_array($stack, ['download', 'update'])) {
105  throw new 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 
119  public function addExtensionToInstallQueue($extension)
120  {
121  $this->extensionInstallStorage[$extension->getExtensionKey()] = $extension;
122  }
123 
129  public function removeExtensionFromInstallQueue($extensionKey)
130  {
131  if (array_key_exists($extensionKey, $this->extensionInstallStorage)) {
132  unset($this->extensionInstallStorage[$extensionKey]);
133  }
134  }
135 
142  public function addExtensionToCopyQueue($extensionKey, $sourceFolder)
143  {
144  $this->extensionCopyStorage[$extensionKey] = $sourceFolder;
145  }
146 
152  public function removeExtensionFromCopyQueue($extensionKey)
153  {
154  if (array_key_exists($extensionKey, $this->extensionCopyStorage)) {
155  unset($this->extensionCopyStorage[$extensionKey]);
156  }
157  }
158 
164  public function getExtensionInstallStorage()
165  {
167  }
168 
174  public function getExtensionCopyStorage()
175  {
177  }
178 
185  public function isQueueEmpty($stack = 'download')
186  {
187  return empty($this->extensionStorage[$stack]);
188  }
189 
195  public function isCopyQueueEmpty()
196  {
197  return empty($this->extensionCopyStorage);
198  }
199 
205  public function isInstallQueueEmpty()
206  {
207  return empty($this->extensionInstallStorage);
208  }
209 
216  public function resetExtensionQueue($stack = null)
217  {
218  $storage = [];
219  if ($stack === null) {
220  $storage = $this->extensionStorage;
221  $this->extensionStorage = [];
222  } elseif (isset($this->extensionStorage[$stack])) {
223  $storage = $this->extensionStorage[$stack];
224  $this->extensionStorage[$stack] = [];
225  }
226 
227  return $storage;
228  }
229 
234  public function resetExtensionCopyStorage()
235  {
236  $storage = $this->extensionCopyStorage;
237  $this->extensionCopyStorage = [];
238 
239  return $storage;
240  }
241 
247  {
249  $this->extensionInstallStorage = [];
250 
251  return $storage;
252  }
253 }
addExtensionToQueue(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $stack='download')
removeExtensionFromQueue(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension, $stack='download')
injectListUtility(\TYPO3\CMS\Extensionmanager\Utility\ListUtility $listUtility)