Passed
Push — master ( b7e4d9...72e0fa )
by
unknown
16:17
created

ExtensionComposerStatus::getRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
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
namespace TYPO3\CMS\Extensionmanager\Report;
19
20
use Psr\Http\Message\ServerRequestInterface;
21
use TYPO3\CMS\Backend\Routing\UriBuilder;
22
use TYPO3\CMS\Core\Localization\LanguageService;
23
use TYPO3\CMS\Core\Package\ComposerDeficitDetector;
24
use TYPO3\CMS\Core\Utility\GeneralUtility;
25
use TYPO3\CMS\Reports\RequestAwareStatusProviderInterface;
26
use TYPO3\CMS\Reports\Status as ReportStatus;
27
28
/**
29
 * Extension composer status reports
30
 *
31
 * @internal This class is a specific EXT:reports implementation and is not part of the Public TYPO3 API.
32
 */
33
class ExtensionComposerStatus implements RequestAwareStatusProviderInterface
34
{
35
    /**
36
     * @var ComposerDeficitDetector
37
     */
38
    protected $composerDeficitDetector;
39
40
    /**
41
     * @var UriBuilder
42
     */
43
    protected $uriBuilder;
44
45
    public function __construct(ComposerDeficitDetector $composerDeficitDetector = null, UriBuilder $uriBuilder = null)
46
    {
47
        $this->composerDeficitDetector = $composerDeficitDetector ?? GeneralUtility::makeInstance(ComposerDeficitDetector::class);
48
        $this->uriBuilder = $uriBuilder ?? GeneralUtility::makeInstance(UriBuilder::class);
49
    }
50
51
    public function getStatus(ServerRequestInterface $request = null): array
52
    {
53
        $status = [];
54
        $extensionsWithComposerDeficit = $this->composerDeficitDetector->getExtensionsWithComposerDeficit();
55
        $languageService = $this->getLanguageService();
56
        $languageService->includeLLFile('EXT:extensionmanager/Resources/Private/Language/locallang.xlf');
57
        $labelPrefix = 'report.status.composerManifest.';
58
        $deficits = [
59
            ComposerDeficitDetector::EXTENSION_COMPOSER_MANIFEST_MISSING => 'composerJsonMissing',
60
            ComposerDeficitDetector::EXTENSION_KEY_MISSING => 'extensionKeyMissing'
61
        ];
62
63
        $queryParameters = [
64
            'tx_extensionmanager_tools_extensionmanagerextensionmanager' => [
65
                'action' => 'list',
66
                'controller' => 'ExtensionComposerStatus',
67
            ]
68
        ];
69
70
        if ($request !== null) {
71
            $queryParameters['tx_extensionmanager_tools_extensionmanagerextensionmanager']['returnUrl'] =
72
                $request->getAttribute('normalizedParams')->getRequestUri();
73
        }
74
75
        $dispatchAction = 'TYPO3.ModuleMenu.showModule';
76
        $dispatchArgs = [
77
            'tools_ExtensionmanagerExtensionmanager',
78
            '&' . http_build_query($queryParameters)
79
        ];
80
81
        foreach ($deficits as $key => $deficit) {
82
            $message = '';
83
            $extensionsToReport = count(array_filter($extensionsWithComposerDeficit, static function ($extensionDeficit) use ($key) {
84
                return $extensionDeficit === $key;
85
            }));
86
87
            if ($extensionsToReport) {
88
                $linkTitle = $languageService->getLL($labelPrefix . 'update');
89
                $linkAttributes = GeneralUtility::implodeAttributes([
90
                    'href' => '#',
91
                    'title' => $linkTitle,
92
                    'class' => 'text-decoration-underline',
93
                    // relies on module 'TYPO3/CMS/Backend/ActionDispatcher'
94
                    'data-dispatch-action' => $dispatchAction,
95
                    'data-dispatch-args' => GeneralUtility::jsonEncodeForHtmlAttribute($dispatchArgs),
96
                ], true);
97
                $message = sprintf($languageService->getLL($labelPrefix . $deficit . '.message'), $extensionsToReport)
98
                    . '<br /><a ' . $linkAttributes . '>' . htmlspecialchars($linkTitle) . '</a>';
99
            }
100
101
            $status[] = GeneralUtility::makeInstance(
102
                ReportStatus::class,
103
                $this->getLanguageService()->getLL($labelPrefix . $deficit),
104
                $this->getLanguageService()->getLL($extensionsToReport ? 'status_checkFailed' : 'status_none'),
105
                $message,
106
                $extensionsToReport ? ReportStatus::WARNING : ReportStatus::OK
107
            );
108
        }
109
110
        return $status;
111
    }
112
113
    protected function getLanguageService(): LanguageService
114
    {
115
        return $GLOBALS['LANG'];
116
    }
117
}
118