‪TYPO3CMS  9.5
AbstractDownloadExtensionUpdate.php
Go to the documentation of this file.
1 <?php
2 
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 use Symfony\Component\Console\Output\OutputInterface;
26 
31 {
35  protected ‪$repositoryUrl = 'https://typo3.org/fileadmin/ter/@filename';
36 
40  protected ‪$output;
41 
45  protected ‪$extension;
46 
50  public function ‪setOutput(OutputInterface ‪$output): void
51  {
52  $this->output = ‪$output;
53  }
54 
61  public function ‪executeUpdate(): bool
62  {
63  return $this->‪installExtension($this->extension);
64  }
65 
74  protected function ‪installExtension(‪ExtensionModel ‪$extension): bool
75  {
76  $updateSuccessful = true;
78  $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
79 
81  $extensionListUtility = $objectManager->get(ListUtility::class);
82  $availableExtensions = $extensionListUtility->getAvailableExtensions();
83 
84  $extensionKey = ‪$extension->‪getKey();
85  $isExtensionAvailable = !empty($availableExtensions[$extensionKey]);
86  $isComposerMode = ‪Environment::isComposerMode();
87 
88  if (!$isComposerMode && !$isExtensionAvailable) {
90  $extensionTerUtility = $objectManager->get(TerUtility::class);
91  $t3xContent = $this->‪fetchExtension($extensionKey, ‪$extension->‪getVersionString());
92  if (empty($t3xContent)) {
93  $updateSuccessful = false;
94  $this->output->writeln('<error>The extension ' . $extensionKey . ' could not be downloaded.</error>');
95  }
96  $t3xExtracted = $extensionTerUtility->decodeExchangeData($t3xContent);
97  if (empty($t3xExtracted) || !is_array($t3xExtracted) || empty($t3xExtracted['extKey'])) {
98  $updateSuccessful = false;
99  $this->output->writeln('<error>The extension ' . $extensionKey . ' could not be extracted.</error>');
100  }
101 
103  $extensionFileHandlingUtility = $objectManager->get(FileHandlingUtility::class);
104  $extensionFileHandlingUtility->unpackExtensionFromExtensionDataArray($t3xExtracted);
105 
106  // The listUtility now needs to have the regenerated list of packages
107  $extensionListUtility->reloadAvailableExtensions();
108  }
109 
110  if ($isComposerMode && !$isExtensionAvailable) {
111  $updateSuccessful = false;
112  $this->output->writeln(
113  '<warning>The extension ' . $extensionKey
114  . ' can not be downloaded since Composer is used for package management. Please require this '
115  . 'extension as package via Composer: "composer require ' . ‪$extension->‪getComposerName()
116  . ':^' . ‪$extension->‪getVersionString() . '"</warning>'
117  );
118  }
119 
120  if ($updateSuccessful) {
122  $extensionInstallUtility = $objectManager->get(InstallUtility::class);
123  $extensionInstallUtility->install($extensionKey);
124  }
125 
126  return $updateSuccessful;
127  }
128 
137  protected function ‪fetchExtension($extensionKey, $version): string
138  {
139  if (empty($extensionKey) || empty($version)) {
140  throw new \InvalidArgumentException(
141  'No extension key for fetching an extension was given.',
142  1344687432
143  );
144  }
145 
146  $filename = $extensionKey[0] . '/' . $extensionKey[1] . '/' . $extensionKey . '_' . $version . '.t3x';
147  $url = str_replace('@filename', $filename, $this->repositoryUrl);
148 
149  return $this->‪fetchUrl($url);
150  }
151 
162  protected function ‪fetchUrl($url): string
163  {
164  if (empty($url)) {
165  throw new \InvalidArgumentException(
166  'No URL for downloading an extension given.',
167  1344687436
168  );
169  }
170 
171  $fileContent = GeneralUtility::getUrl($url);
172 
173  // Can not fetch url, throw an exception
174  if ($fileContent === false) {
175  throw new \RuntimeException(
176  'Can not fetch URL "' . $url . '". Possible reasons are network problems or misconfiguration.',
177  1344685036
178  );
179  }
180 
181  return $fileContent;
182  }
183 }
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate\fetchUrl
‪string fetchUrl($url)
Definition: AbstractDownloadExtensionUpdate.php:159
‪TYPO3\CMS\Install\Updates\ExtensionModel\getComposerName
‪string getComposerName()
Definition: ExtensionModel.php:78
‪TYPO3\CMS\Install\Updates\ChattyInterface
Definition: ChattyInterface.php:25
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate\$repositoryUrl
‪string $repositoryUrl
Definition: AbstractDownloadExtensionUpdate.php:34
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility
Definition: ListUtility.php:35
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate\$output
‪OutputInterface $output
Definition: AbstractDownloadExtensionUpdate.php:38
‪TYPO3\CMS\Extensionmanager\Utility\Connection\TerUtility
Definition: TerUtility.php:29
‪TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility
Definition: FileHandlingUtility.php:33
‪TYPO3\CMS\Install\Updates
Definition: AbstractDownloadExtensionUpdate.php:3
‪TYPO3\CMS\Install\Updates\ExtensionModel\getVersionString
‪string getVersionString()
Definition: ExtensionModel.php:70
‪TYPO3\CMS\Extensionmanager\Utility\InstallUtility
Definition: InstallUtility.php:32
‪TYPO3\CMS\Install\Updates\ExtensionModel
Definition: ExtensionModel.php:25
‪TYPO3\CMS\Install\Updates\ExtensionModel\getKey
‪string getKey()
Definition: ExtensionModel.php:54
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate\installExtension
‪bool installExtension(ExtensionModel $extension)
Definition: AbstractDownloadExtensionUpdate.php:71
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate\$extension
‪TYPO3 CMS Install Updates ExtensionModel $extension
Definition: AbstractDownloadExtensionUpdate.php:42
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate
Definition: AbstractDownloadExtensionUpdate.php:31
‪TYPO3\CMS\Core\Core\Environment\isComposerMode
‪static bool isComposerMode()
Definition: Environment.php:117
‪TYPO3\CMS\Install\Updates\UpgradeWizardInterface
Definition: UpgradeWizardInterface.php:22
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate\fetchExtension
‪string fetchExtension($extensionKey, $version)
Definition: AbstractDownloadExtensionUpdate.php:134
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25
‪TYPO3\CMS\Install\Updates\ConfirmableInterface
Definition: ConfirmableInterface.php:23
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate\setOutput
‪setOutput(OutputInterface $output)
Definition: AbstractDownloadExtensionUpdate.php:47
‪TYPO3\CMS\Install\Updates\AbstractDownloadExtensionUpdate\executeUpdate
‪bool executeUpdate()
Definition: AbstractDownloadExtensionUpdate.php:58