‪TYPO3CMS  ‪main
AbstractDownloadExtensionUpdate.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Symfony\Component\Console\Output\OutputInterface;
27 
32 {
36  protected ‪$output;
37 
41  protected ‪$extension;
42 
43  public function ‪setOutput(OutputInterface ‪$output): void
44  {
45  $this->output = ‪$output;
46  }
47 
52  public function ‪executeUpdate(): bool
53  {
54  return $this->‪installExtension($this->extension);
55  }
56 
64  protected function ‪installExtension(ExtensionModel ‪$extension): bool
65  {
66  $updateSuccessful = true;
67 
68  $extensionListUtility = GeneralUtility::makeInstance(ListUtility::class);
69  $availableExtensions = $extensionListUtility->getAvailableExtensions();
70 
71  $extensionKey = ‪$extension->‪getKey();
72  $isExtensionAvailable = !empty($availableExtensions[$extensionKey]);
73  $isComposerMode = ‪Environment::isComposerMode();
74 
75  if (!$isComposerMode && !$isExtensionAvailable) {
76  $extensionFileHandlingUtility = GeneralUtility::makeInstance(FileHandlingUtility::class);
77  $remoteRegistry = GeneralUtility::makeInstance(RemoteRegistry::class);
78  if ($remoteRegistry->hasDefaultRemote()) {
79  $terRemote = $remoteRegistry->getDefaultRemote();
80  try {
81  $terRemote->downloadExtension($extensionKey, ‪$extension->‪getVersionString(), $extensionFileHandlingUtility);
82  } catch (DownloadFailedException $e) {
83  $updateSuccessful = false;
84  $this->output->writeln('<error>The extension ' . $extensionKey . ' could not be downloaded.</error>');
85  } catch (VerificationFailedException $e) {
86  $updateSuccessful = false;
87  $this->output->writeln('<error>The extension ' . $extensionKey . ' could not be extracted.</error>');
88  }
89  } else {
90  $updateSuccessful = false;
91  $this->output->writeln(
92  '<error>The extension ' . $extensionKey . ' could not be downloaded because no remote is available.</error>'
93  );
94  }
95  // The listUtility now needs to have the regenerated list of packages
96  $extensionListUtility->reloadAvailableExtensions();
97  }
98 
99  if ($isComposerMode && !$isExtensionAvailable) {
100  $updateSuccessful = false;
101  $this->output->writeln(
102  '<warning>The extension ' . $extensionKey
103  . ' can not be downloaded since Composer is used for package management. Please require this '
104  . 'extension as package via Composer: "composer require ' . ‪$extension->‪getComposerName()
105  . ':^' . ‪$extension->‪getVersionString() . '"</warning>'
106  );
107  }
108 
109  if ($updateSuccessful) {
110  $extensionInstallUtility = GeneralUtility::makeInstance(InstallUtility::class);
111  $extensionInstallUtility->install($extensionKey);
112  }
113 
114  return $updateSuccessful;
115  }
116 }
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static isComposerMode()
Definition: Environment.php:137
‪TYPO3\CMS\Install\Updates\ChattyInterface
Definition: ChattyInterface.php:26
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility
Definition: ListUtility.php:40
‪TYPO3\CMS\Install\Updates\ExtensionModel\getVersionString
‪getVersionString()
Definition: ExtensionModel.php:76
‪TYPO3\CMS\Extensionmanager\Remote\VerificationFailedException
Definition: VerificationFailedException.php:26
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate\$output
‪OutputInterface $output
Definition: AbstractDownloadExtensionUpdate.php:35
‪TYPO3\CMS\Install\Updates\ExtensionModel\getComposerName
‪getComposerName()
Definition: ExtensionModel.php:81
‪TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility
Definition: FileHandlingUtility.php:38
‪TYPO3\CMS\Install\Updates
Definition: AbstractDownloadExtensionUpdate.php:16
‪TYPO3\CMS\Extensionmanager\Utility\InstallUtility
Definition: InstallUtility.php:57
‪TYPO3\CMS\Install\Updates\ExtensionModel
Definition: ExtensionModel.php:26
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate\installExtension
‪bool installExtension(ExtensionModel $extension)
Definition: AbstractDownloadExtensionUpdate.php:62
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate\$extension
‪TYPO3 CMS Install Updates ExtensionModel $extension
Definition: AbstractDownloadExtensionUpdate.php:39
‪TYPO3\CMS\Install\Updates\ExtensionModel\getKey
‪getKey()
Definition: ExtensionModel.php:66
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate
Definition: AbstractDownloadExtensionUpdate.php:32
‪TYPO3\CMS\Install\Updates\UpgradeWizardInterface
Definition: UpgradeWizardInterface.php:24
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:41
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate\executeUpdate
‪executeUpdate()
Definition: AbstractDownloadExtensionUpdate.php:50
‪TYPO3\CMS\Extensionmanager\Remote\DownloadFailedException
Definition: DownloadFailedException.php:26
‪TYPO3\CMS\Install\Updates\ConfirmableInterface
Definition: ConfirmableInterface.php:24
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate\setOutput
‪setOutput(OutputInterface $output)
Definition: AbstractDownloadExtensionUpdate.php:41
‪TYPO3\CMS\Extensionmanager\Remote\RemoteRegistry
Definition: RemoteRegistry.php:26