TYPO3 CMS  TYPO3_6-2
ExtensionManagementService.php
Go to the documentation of this file.
1 <?php
3 
18 
25 
30  protected $downloadQueue;
31 
36  protected $dependencyUtility;
37 
42  protected $installUtility;
43 
49 
54  protected $downloadUtility;
55 
59  protected $skipSystemDependencyCheck = FALSE;
60 
65  public function markExtensionForInstallation($extensionKey) {
66  // We have to check for dependencies of the extension first, before marking it for installation
67  // because this extension might have dependencies, which need to be installed first
68  $extension = $this->getExtension($extensionKey);
69  $this->dependencyUtility->checkDependencies($extension);
70  $this->downloadQueue->addExtensionToInstallQueue($extension);
71  }
72 
80  public function markExtensionForCopy($extensionKey, $sourceFolder) {
81  $this->downloadQueue->addExtensionToCopyQueue($extensionKey, $sourceFolder);
82  }
83 
90  public function markExtensionForDownload(Extension $extension) {
91  // We have to check for dependencies of the extension first, before marking it for download
92  // because this extension might have dependencies, which need to be downloaded and installed first
93  $this->dependencyUtility->checkDependencies($extension);
94  if (!$this->dependencyUtility->hasDependencyErrors()) {
95  $this->downloadQueue->addExtensionToQueue($extension);
96  }
97  }
98 
103  public function markExtensionForUpdate(Extension $extension) {
104  // We have to check for dependencies of the extension first, before marking it for download
105  // because this extension might have dependencies, which need to be downloaded and installed first
106  $this->dependencyUtility->checkDependencies($extension);
107  $this->downloadQueue->addExtensionToQueue($extension, 'update');
108  }
109 
116  $this->skipSystemDependencyCheck = $skipSystemDependencyCheck;
117  }
118 
125  public function installExtension(Extension $extension) {
126  $this->downloadExtension($extension);
127 
128  if (!$this->checkDependencies($extension)) {
129  return FALSE;
130  }
131 
132  $updatedDependencies = array();
133  $installedDependencies = array();
134  $queue = $this->downloadQueue->getExtensionQueue();
135  $copyQueue = $this->downloadQueue->getExtensionCopyStorage();
136 
137  if (count($copyQueue) > 0) {
138  $this->copyDependencies($copyQueue);
139  }
140  $downloadedDependencies = array();
141  if (array_key_exists('download', $queue)) {
142  $downloadedDependencies = $this->downloadDependencies($queue['download']);
143  }
144  if (array_key_exists('update', $queue)) {
145  $this->downloadDependencies($queue['update']);
146  $updatedDependencies = $this->uninstallDependenciesToBeUpdated($queue['update']);
147  }
148  // add extension at the end of the download queue
149  $this->downloadQueue->addExtensionToInstallQueue($extension);
150  $installQueue = $this->downloadQueue->getExtensionInstallStorage();
151  if (count($installQueue) > 0) {
152  $installedDependencies = $this->installDependencies($installQueue);
153  }
154  return array_merge($downloadedDependencies, $updatedDependencies, $installedDependencies);
155  }
156 
162  public function getDependencyErrors() {
163  return $this->dependencyUtility->getDependencyErrors();
164  }
165 
171  public function getExtension($extensionKey) {
172  return $this->extensionModelUtility->mapExtensionArrayToModel(
173  $this->installUtility->enrichExtensionWithDetails($extensionKey)
174  );
175  }
176 
183  public function isAvailable($extensionKey) {
184  return $this->installUtility->isAvailable($extensionKey);
185  }
186 
192  protected function downloadExtension(Extension $extension) {
193  $this->downloadMainExtension($extension);
194  $this->setInExtensionRepository($extension->getExtensionKey());
195  }
196 
203  protected function checkDependencies(Extension $extension) {
204  $this->dependencyUtility->setSkipSystemDependencyCheck($this->skipSystemDependencyCheck);
205  $this->dependencyUtility->checkDependencies($extension);
206 
207  return !$this->dependencyUtility->hasDependencyErrors();
208  }
209 
217  protected function setInExtensionRepository($extensionKey) {
219  $path = $paths[$this->downloadUtility->getDownloadPath()];
220  $localExtensionStorage = $path . $extensionKey . '/Initialisation/Extensions/';
221  $this->dependencyUtility->setLocalExtensionStorage($localExtensionStorage);
222  }
223 
230  protected function copyDependencies(array $copyQueue) {
231  $installPaths = Extension::returnAllowedInstallPaths();
232  foreach ($copyQueue as $extensionKey => $sourceFolder) {
233  $destination = $installPaths['Local'] . $extensionKey;
235  \TYPO3\CMS\Core\Utility\GeneralUtility::copyDirectory($sourceFolder . $extensionKey, $destination);
236  $this->markExtensionForInstallation($extensionKey);
237  $this->downloadQueue->removeExtensionFromCopyQueue($extensionKey);
238  }
239  }
240 
248  protected function uninstallDependenciesToBeUpdated(array $updateQueue) {
249  $resolvedDependencies = array();
250  foreach ($updateQueue as $extensionToUpdate) {
251  $this->installUtility->uninstall($extensionToUpdate->getExtensionKey());
252  $resolvedDependencies['updated'][$extensionToUpdate->getExtensionKey()] = $extensionToUpdate;
253  }
254  return $resolvedDependencies;
255  }
256 
263  protected function installDependencies(array $installQueue) {
264  if (!empty($installQueue)) {
265  $this->emitWillInstallExtensionsSignal($installQueue);
266  }
267  $resolvedDependencies = array();
268  foreach ($installQueue as $extensionKey => $_) {
269  $this->installUtility->install($extensionKey);
270  $this->emitHasInstalledExtensionSignal($extensionKey);
271  if (!is_array($resolvedDependencies['installed'])) {
272  $resolvedDependencies['installed'] = array();
273  }
274  $resolvedDependencies['installed'][$extensionKey] = $extensionKey;
275  }
276  return $resolvedDependencies;
277  }
278 
286  protected function downloadDependencies(array $downloadQueue) {
287  $resolvedDependencies = array();
288  foreach ($downloadQueue as $extensionToDownload) {
289  $this->downloadUtility->download($extensionToDownload);
290  $this->downloadQueue->removeExtensionFromQueue($extensionToDownload);
291  $resolvedDependencies['downloaded'][$extensionToDownload->getExtensionKey()] = $extensionToDownload;
292  $this->markExtensionForInstallation($extensionToDownload->getExtensionKey());
293  }
294  return $resolvedDependencies;
295  }
296 
303  public function getAndResolveDependencies(Extension $extension) {
304  $this->dependencyUtility->setSkipSystemDependencyCheck($this->skipSystemDependencyCheck);
305  $this->dependencyUtility->checkDependencies($extension);
306  $installQueue = $this->downloadQueue->getExtensionInstallStorage();
307  if (is_array($installQueue) && count($installQueue) > 0) {
308  $installQueue = array('install' => $installQueue);
309  }
310  return array_merge($this->downloadQueue->getExtensionQueue(), $installQueue);
311  }
312 
321  public function downloadMainExtension(Extension $extension) {
322  // The extension object has a uid if the extension is not present in the system
323  // or an update of a present extension is triggered.
324  if ($extension->getUid()) {
325  $this->downloadUtility->download($extension);
326  }
327  }
328 
332  protected function emitWillInstallExtensionsSignal(array $installQueue) {
333  $this->getSignalSlotDispatcher()->dispatch(__CLASS__, 'willInstallExtensions', array($installQueue));
334  }
335 
339  protected function emitHasInstalledExtensionSignal($extensionKey) {
340  $this->getSignalSlotDispatcher()->dispatch(__CLASS__, 'hasInstalledExtensions', array($extensionKey));
341  }
342 
348  protected function getSignalSlotDispatcher() {
349  if (!isset($this->signalSlotDispatcher)) {
350  $this->signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')
351  ->get('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher');
352  }
354  }
355 
356 }
static copyDirectory($source, $destination)
$signalSlotDispatcher