From 442241eb506484da1e0e98a319fd494b616241b6 Mon Sep 17 00:00:00 2001 From: Simon Gilli <25326036+gilbertsoft@users.noreply.github.com> Date: Tue, 24 May 2022 13:18:16 +0200 Subject: [PATCH] [TASK] Introduce typo3/cms-composer-installers v4 support --- Classes/Controller/ExportController.php | 55 ++++++++++++++++++++++--- ext_conf_template.txt | 2 + 2 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 ext_conf_template.txt diff --git a/Classes/Controller/ExportController.php b/Classes/Controller/ExportController.php index 2bbfef9..820fb8d 100644 --- a/Classes/Controller/ExportController.php +++ b/Classes/Controller/ExportController.php @@ -35,6 +35,7 @@ use MASK\Mask\Domain\Repository\StorageRepository; use Symfony\Component\Finder\Finder; use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; +use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Messaging\AbstractMessage; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -181,12 +182,7 @@ public function downloadAction($vendorName, $extensionName, $elements) */ public function installAction($vendorName, $extensionName, $elements) { - $paths = Extension::returnInstallPaths(); - if (empty($paths['Local']) || !file_exists($paths['Local'])) { - throw new \RuntimeException('Local extension install path is missing', 1500061028); - } - - $extensionPath = $paths['Local'] . $extensionName; + $extensionPath = $this->getExtensionsPath() . $extensionName; $files = $this->getFiles($vendorName, $extensionName, $elements); $this->writeExtensionFilesToPath($files, $extensionPath); @@ -318,6 +314,53 @@ protected function getFiles($vendorName, $extensionName, $elements) return $files; } + /** + * Return the extension install path including the trailing slash. + */ + protected function getExtensionsPath(): string + { + // For non Composer installs early return the local extensions path + if (!Environment::isComposerMode()) { + $path = Extension::returnInstallPaths()['Local'] ?? ''; + if (empty($path) || !file_exists($path)) { + throw new \RuntimeException('Local extension install path is missing.', 1500061028); + } + + return $path; + } + + // For Composer installs the composerPathRepository setting will be + // used with a fallback if possible to the local exensions path. + $composerPathRepository = GeneralUtility::makeInstance(ExtensionConfiguration::class) + ->get('mask_export', 'composerPathRepository'); + + if ($composerPathRepository === '') { + $path = Extension::returnInstallPaths()['Local'] ?? ''; + + $this->addFlashMessage( + 'The path to the Composer path repository should be properly configured in the extension settings.', + 'Warning', + AbstractMessage::WARNING + ); + } else { + if (substr($composerPathRepository, 0, 1) !== '/') { + $path = Environment::getComposerRootPath() . '/' . $composerPathRepository; + } else { + $path = Environment::getComposerRootPath() . $composerPathRepository; + } + } + + if (empty($path) || !file_exists($path)) { + throw new \RuntimeException('Path to the Composer path repository is missing. Please properly configure it in the extension settings.', 1653409378); + } + + if (substr($path, -1) !== '/') { + $path .= '/'; + } + + return $path; + } + protected function prepareConfiguration(string $vendorName, string $extensionName, array $elements) { $aggregatedConfiguration = $this->maskConfiguration; diff --git a/ext_conf_template.txt b/ext_conf_template.txt new file mode 100644 index 0000000..baae01b --- /dev/null +++ b/ext_conf_template.txt @@ -0,0 +1,2 @@ +# cat=Settings; type=string; label=Composer path repository: If set, this path will be used as export destination relative to the Composer root directory. Mandatory for typo3/cms-composer-installers v4 or higher. E.g. src/extensions +composerPathRepository =