‪TYPO3CMS  11.5
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 
46  public function ‪setOutput(OutputInterface ‪$output): void
47  {
48  $this->output = ‪$output;
49  }
50 
57  public function ‪executeUpdate(): bool
58  {
59  return $this->‪installExtension($this->extension);
60  }
61 
70  protected function ‪installExtension(‪ExtensionModel ‪$extension): bool
71  {
72  $updateSuccessful = true;
73 
74  $extensionListUtility = GeneralUtility::makeInstance(ListUtility::class);
75  $availableExtensions = $extensionListUtility->getAvailableExtensions();
76 
77  $extensionKey = ‪$extension->‪getKey();
78  $isExtensionAvailable = !empty($availableExtensions[$extensionKey]);
79  $isComposerMode = ‪Environment::isComposerMode();
80 
81  if (!$isComposerMode && !$isExtensionAvailable) {
82  $extensionFileHandlingUtility = GeneralUtility::makeInstance(FileHandlingUtility::class);
83  $remoteRegistry = GeneralUtility::makeInstance(RemoteRegistry::class);
84  if ($remoteRegistry->hasDefaultRemote()) {
85  $terRemote = $remoteRegistry->getDefaultRemote();
86  try {
87  $terRemote->downloadExtension($extensionKey, ‪$extension->‪getVersionString(), $extensionFileHandlingUtility);
88  } catch (‪DownloadFailedException $e) {
89  $updateSuccessful = false;
90  $this->output->writeln('<error>The extension ' . $extensionKey . ' could not be downloaded.</error>');
91  } catch (‪VerificationFailedException $e) {
92  $updateSuccessful = false;
93  $this->output->writeln('<error>The extension ' . $extensionKey . ' could not be extracted.</error>');
94  }
95  } else {
96  $updateSuccessful = false;
97  $this->output->writeln(
98  '<error>The extension ' . $extensionKey . ' could not be downloaded because no remote is available.</error>'
99  );
100  }
101  // The listUtility now needs to have the regenerated list of packages
102  $extensionListUtility->reloadAvailableExtensions();
103  }
104 
105  if ($isComposerMode && !$isExtensionAvailable) {
106  $updateSuccessful = false;
107  $this->output->writeln(
108  '<warning>The extension ' . $extensionKey
109  . ' can not be downloaded since Composer is used for package management. Please require this '
110  . 'extension as package via Composer: "composer require ' . ‪$extension->‪getComposerName()
111  . ':^' . ‪$extension->‪getVersionString() . '"</warning>'
112  );
113  }
114 
115  if ($updateSuccessful) {
116  $extensionInstallUtility = GeneralUtility::makeInstance(InstallUtility::class);
117  $extensionInstallUtility->install($extensionKey);
118  }
119 
120  return $updateSuccessful;
121  }
122 }
‪TYPO3\CMS\Install\Updates\ExtensionModel\getComposerName
‪string getComposerName()
Definition: ExtensionModel.php:93
‪TYPO3\CMS\Install\Updates\ChattyInterface
Definition: ChattyInterface.php:26
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility
Definition: ListUtility.php:40
‪TYPO3\CMS\Extensionmanager\Remote\VerificationFailedException
Definition: VerificationFailedException.php:25
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate\$output
‪OutputInterface $output
Definition: AbstractDownloadExtensionUpdate.php:35
‪TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility
Definition: FileHandlingUtility.php:36
‪TYPO3\CMS\Install\Updates
Definition: AbstractDownloadExtensionUpdate.php:16
‪TYPO3\CMS\Install\Updates\ExtensionModel\getVersionString
‪string getVersionString()
Definition: ExtensionModel.php:85
‪TYPO3\CMS\Extensionmanager\Utility\InstallUtility
Definition: InstallUtility.php:56
‪TYPO3\CMS\Install\Updates\ExtensionModel
Definition: ExtensionModel.php:26
‪TYPO3\CMS\Install\Updates\ExtensionModel\getKey
‪string getKey()
Definition: ExtensionModel.php:69
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate\installExtension
‪bool installExtension(ExtensionModel $extension)
Definition: AbstractDownloadExtensionUpdate.php:68
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate\$extension
‪TYPO3 CMS Install Updates ExtensionModel $extension
Definition: AbstractDownloadExtensionUpdate.php:39
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate
Definition: AbstractDownloadExtensionUpdate.php:32
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static bool isComposerMode()
Definition: Environment.php:152
‪TYPO3\CMS\Install\Updates\UpgradeWizardInterface
Definition: UpgradeWizardInterface.php:24
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:43
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Extensionmanager\Remote\DownloadFailedException
Definition: DownloadFailedException.php:25
‪TYPO3\CMS\Install\Updates\ConfirmableInterface
Definition: ConfirmableInterface.php:24
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate\setOutput
‪setOutput(OutputInterface $output)
Definition: AbstractDownloadExtensionUpdate.php:44
‪TYPO3\CMS\Extensionmanager\Remote\RemoteRegistry
Definition: RemoteRegistry.php:26
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate\executeUpdate
‪bool executeUpdate()
Definition: AbstractDownloadExtensionUpdate.php:55