Passed
Push — master ( ce34db...aabc2a )
by
unknown
13:08
created

ExtensionComposerStatus::getLanguageService()   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
        $request = $request ?? $this->getRequest();
55
        $extensionsWithComposerDeficit = $this->composerDeficitDetector->getExtensionsWithComposerDeficit();
56
        $languageService = $this->getLanguageService();
57
        $languageService->includeLLFile('EXT:extensionmanager/Resources/Private/Language/locallang.xlf');
58
        $labelPrefix = 'report.status.composerManifest.';
59
        $deficits = [
60
            ComposerDeficitDetector::EXTENSION_COMPOSER_MANIFEST_MISSING => 'composerJsonMissing',
61
            ComposerDeficitDetector::EXTENSION_KEY_MISSING => 'extensionKeyMissing'
62
        ];
63
        $dispatchAction = 'TYPO3.ModuleMenu.showModule';
64
        $dispatchArgs = [
65
            'tools_ExtensionmanagerExtensionmanager',
66
            '&' . http_build_query([
67
                'tx_extensionmanager_tools_extensionmanagerextensionmanager' => [
68
                    'action' => 'list',
69
                    'controller' => 'ExtensionComposerStatus',
70
                    'returnUrl' => $request->getAttribute('normalizedParams')->getRequestUri()
71
                ]
72
            ])
73
        ];
74
75
        foreach ($deficits as $key => $deficit) {
76
            $message = '';
77
            $extensionsToReport = count(array_filter($extensionsWithComposerDeficit, static function ($extensionDeficit) use ($key) {
78
                return $extensionDeficit === $key;
79
            }));
80
81
            if ($extensionsToReport) {
82
                $linkTitle = $languageService->getLL($labelPrefix . 'update');
83
                $linkAttributes = GeneralUtility::implodeAttributes([
84
                    'href' => '#',
85
                    'title' => $linkTitle,
86
                    'class' => 'text-decoration-underline',
87
                    // relies on module 'TYPO3/CMS/Backend/ActionDispatcher'
88
                    'data-dispatch-action' => $dispatchAction,
89
                    'data-dispatch-args' => GeneralUtility::jsonEncodeForHtmlAttribute($dispatchArgs),
90
                ], true);
91
                $message = sprintf($languageService->getLL($labelPrefix . $deficit . '.message'), $extensionsToReport)
92
                    . '<br /><a ' . $linkAttributes . '>' . htmlspecialchars($linkTitle) . '</a>';
93
            }
94
95
            $status[] = GeneralUtility::makeInstance(
96
                ReportStatus::class,
97
                $this->getLanguageService()->getLL($labelPrefix . $deficit),
98
                $this->getLanguageService()->getLL($extensionsToReport ? 'status_checkFailed' : 'status_none'),
99
                $message,
100
                $extensionsToReport ? ReportStatus::WARNING : ReportStatus::OK
101
            );
102
        }
103
104
        return $status;
105
    }
106
107
    protected function getLanguageService(): LanguageService
108
    {
109
        return $GLOBALS['LANG'];
110
    }
111
112
    protected function getRequest(): ServerRequestInterface
113
    {
114
        return $GLOBALS['TYPO3_REQUEST'];
115
    }
116
}
117