Commit 70c26bab authored by Oliver Bartsch's avatar Oliver Bartsch
Browse files

[TASK] Add composer status information on upload in GUI

parent b79e2fdb
Pipeline #10563 passed with stages
in 5 minutes and 46 seconds
......@@ -523,6 +523,12 @@ class ExtensionController extends \T3o\TerFe2\Controller\AbstractController
if ($extensionVersion->doesExtensionVersionExist()) {
$this->forwardWithError($this->translate('msg.createVersionVersionExists'), 'uploadVersion');
}
$composerStatus = '';
if (($composerManifest = $this->getComposerManifest($files)) === []) {
$composerStatus = 'missing';
} elseif (($composerManifest['extra']['typo3/cms']['extension-key'] ?? '') !== $extensionKey) {
$composerStatus = 'missingExtensionKey';
}
$extensionInfo->extensionKey = $extensionKey;
$extensionInfo->infoData->uploadComment = $form['comment'];
try {
......@@ -531,7 +537,7 @@ class ExtensionController extends \T3o\TerFe2\Controller\AbstractController
$uploader = new ApiUser($this->frontendUser['username']);
$uploader->authenticate();
$extensionVersion->upload($uploader, $extensionInfo, $files);
$this->redirect('index', 'Registerkey', null, ['uploaded' => true], $this->settings['pages']['manageKeysPID']);
$this->redirect('index', 'Registerkey', null, ['uploaded' => true, 'composerStatus' => $composerStatus], $this->settings['pages']['manageKeysPID']);
} catch (\Exception $exception) {
$this->forwardWithError('Error ' . $exception->getCode() . ': ' . $exception->getMessage(), 'uploadVersion');
}
......@@ -662,4 +668,21 @@ class ExtensionController extends \T3o\TerFe2\Controller\AbstractController
{
return $this->getBaseUrl() . '/' . ExtensionUtility::getExtensionIcon($extension->getExtKey(), $extension->getLastVersion()->getVersionString());
}
private function getComposerManifest(array $files): array
{
$composerManifest = [];
foreach ($files as $file) {
$fileName = trim($file->name, '/\\');
if ($fileName === 'composer.json') {
try {
$composerManifest = json_decode(base64_decode($file->content), true, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
// Ignore invalid json since this will just return an empty manifest
}
break;
}
}
return $composerManifest;
}
}
......@@ -75,8 +75,9 @@ class RegisterkeyController extends \T3o\TerFe2\Controller\AbstractTerBasedContr
* Initialize all actions
*
* @param bool $uploaded TRUE if an extension version was successfully uploaded
* @param string $composerStatus Contains information about the composer status, e.g. missing
*/
public function indexAction($uploaded = false)
public function indexAction(bool $uploaded = false, string $composerStatus = '')
{
// get extensions by user if a user is logged in
if ($GLOBALS['TSFE']->fe_user->user['uid']) {
......@@ -89,6 +90,7 @@ class RegisterkeyController extends \T3o\TerFe2\Controller\AbstractTerBasedContr
$this->view->assign('expiringExtensions', $expiringExtensions);
$this->view->assign('likedExtensions', $likedExtensions);
$this->view->assign('uploaded', $uploaded);
$this->view->assign('composerStatus', $composerStatus);
}
}
......
......@@ -246,6 +246,12 @@
<trans-unit id="msg.createVersionUploadSuccess" xml:space="preserve">
<source>Thank you for the upload of your new extension version. It may take up to 15 minutes until it appears in TER.</source>
</trans-unit>
<trans-unit id="msg.composerStatus.missing" xml:space="preserve">
<source>Your uploaded extension version does not contain a composer.json file. This will be mandatory in the future.</source>
</trans-unit>
<trans-unit id="msg.composerStatus.missingExtensionKey" xml:space="preserve">
<source>The composer.json of your uploaded extension version does not contain the extension key. This will be mandatory in the future.</source>
</trans-unit>
<trans-unit id="msg.createVersionUploadFailed" xml:space="preserve">
<source>Extension upload failed.</source>
</trans-unit>
......
......@@ -10,6 +10,20 @@
</p>
</div>
</f:if>
<f:if condition="{composerStatus}">
<div class="alert alert-warning">
<p>
<f:translate key="LLL:EXT:ter_fe2/Resources/Private/Language/locallang.xlf:msg.composerStatus.{composerStatus}" />
More information can be found in the official
<f:link.typolink parameter="https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ExtensionArchitecture/ComposerJson/Index.html">
TYPO3 documentation
</f:link.typolink>.
</p>
</div>
</f:if>
<header class="mb-4 mt-4">
<h1>Managing my extensions</h1>
</header>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment