Skip to content

Commit 442241e

Browse files
committed
[TASK] Introduce typo3/cms-composer-installers v4 support
1 parent 4474b20 commit 442241e

2 files changed

Lines changed: 51 additions & 6 deletions

File tree

Classes/Controller/ExportController.php

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use MASK\Mask\Domain\Repository\StorageRepository;
3636
use Symfony\Component\Finder\Finder;
3737
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
38+
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
3839
use TYPO3\CMS\Core\Core\Environment;
3940
use TYPO3\CMS\Core\Messaging\AbstractMessage;
4041
use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -181,12 +182,7 @@ public function downloadAction($vendorName, $extensionName, $elements)
181182
*/
182183
public function installAction($vendorName, $extensionName, $elements)
183184
{
184-
$paths = Extension::returnInstallPaths();
185-
if (empty($paths['Local']) || !file_exists($paths['Local'])) {
186-
throw new \RuntimeException('Local extension install path is missing', 1500061028);
187-
}
188-
189-
$extensionPath = $paths['Local'] . $extensionName;
185+
$extensionPath = $this->getExtensionsPath() . $extensionName;
190186
$files = $this->getFiles($vendorName, $extensionName, $elements);
191187
$this->writeExtensionFilesToPath($files, $extensionPath);
192188

@@ -318,6 +314,53 @@ protected function getFiles($vendorName, $extensionName, $elements)
318314
return $files;
319315
}
320316

317+
/**
318+
* Return the extension install path including the trailing slash.
319+
*/
320+
protected function getExtensionsPath(): string
321+
{
322+
// For non Composer installs early return the local extensions path
323+
if (!Environment::isComposerMode()) {
324+
$path = Extension::returnInstallPaths()['Local'] ?? '';
325+
if (empty($path) || !file_exists($path)) {
326+
throw new \RuntimeException('Local extension install path is missing.', 1500061028);
327+
}
328+
329+
return $path;
330+
}
331+
332+
// For Composer installs the composerPathRepository setting will be
333+
// used with a fallback if possible to the local exensions path.
334+
$composerPathRepository = GeneralUtility::makeInstance(ExtensionConfiguration::class)
335+
->get('mask_export', 'composerPathRepository');
336+
337+
if ($composerPathRepository === '') {
338+
$path = Extension::returnInstallPaths()['Local'] ?? '';
339+
340+
$this->addFlashMessage(
341+
'The path to the Composer path repository should be properly configured in the extension settings.',
342+
'Warning',
343+
AbstractMessage::WARNING
344+
);
345+
} else {
346+
if (substr($composerPathRepository, 0, 1) !== '/') {
347+
$path = Environment::getComposerRootPath() . '/' . $composerPathRepository;
348+
} else {
349+
$path = Environment::getComposerRootPath() . $composerPathRepository;
350+
}
351+
}
352+
353+
if (empty($path) || !file_exists($path)) {
354+
throw new \RuntimeException('Path to the Composer path repository is missing. Please properly configure it in the extension settings.', 1653409378);
355+
}
356+
357+
if (substr($path, -1) !== '/') {
358+
$path .= '/';
359+
}
360+
361+
return $path;
362+
}
363+
321364
protected function prepareConfiguration(string $vendorName, string $extensionName, array $elements)
322365
{
323366
$aggregatedConfiguration = $this->maskConfiguration;

ext_conf_template.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# 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
2+
composerPathRepository =

0 commit comments

Comments
 (0)