• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tomasnorre / crawler / 4092880773

pending completion
4092880773

push

github

GitHub
[TASK] Cleanup BackendModule Controllers (#1005)

246 of 246 new or added lines in 9 files covered. (100.0%)

1778 of 2545 relevant lines covered (69.86%)

3.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/Classes/Controller/Backend/AbstractBackendModuleController.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace AOE\Crawler\Controller\Backend;
6

7
/*
8
 * (c) 2022-     Tomas Norre Mikkelsen <tomasnorre@gmail.com>
9
 *
10
 * This file is part of the TYPO3 Crawler Extension.
11
 *
12
 * It is free software; you can redistribute it and/or modify it under
13
 * the terms of the GNU General Public License, either version 2
14
 * of the License, or any later version.
15
 *
16
 * For the full copyright and license information, please read the
17
 * LICENSE.txt file that was distributed with this source code.
18
 *
19
 * The TYPO3 project - inspiring people to share!
20
 */
21

22
use AOE\Crawler\Configuration\ExtensionConfigurationProvider;
23
use AOE\Crawler\Utility\MessageUtility;
24
use AOE\Crawler\Utility\PhpBinaryUtility;
25
use Psr\Http\Message\ServerRequestInterface;
26
use Symfony\Contracts\Service\Attribute\Required;
27
use TYPO3\CMS\Backend\Template\ModuleTemplate;
28
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
29
use TYPO3\CMS\Backend\Utility\BackendUtility;
30
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
31
use TYPO3\CMS\Core\Localization\LanguageService;
32
use TYPO3\CMS\Core\Type\Bitmask\Permission;
33
use TYPO3\CMS\Core\Utility\CommandUtility;
34
use TYPO3\CMS\Core\Utility\GeneralUtility;
35

36
/**
37
 * @internal since v12.0.0
38
 */
39
abstract class AbstractBackendModuleController
40
{
41
    protected bool $isErrorDetected = false;
42
    protected int $pageUid;
43
    protected ModuleTemplate $moduleTemplate;
44
    protected array $extensionSettings = [];
45

46
    #[Required]
47
    public function setExtensionSettings(): void
48
    {
49
        /** @var ExtensionConfigurationProvider $configurationProvider */
50
        $configurationProvider = GeneralUtility::makeInstance(ExtensionConfigurationProvider::class);
×
51
        $this->extensionSettings = $configurationProvider->getExtensionConfiguration();
×
52
    }
53

54
    protected function setupView(ServerRequestInterface $request, int $pageUid): ModuleTemplate
55
    {
56
        $moduleTemplate = (GeneralUtility::makeInstance(ModuleTemplateFactory::class))->create($request);
×
57
        $permissionClause = $this->getBackendUserAuthentication()->getPagePermsClause(Permission::PAGE_SHOW);
×
58
        $pageRecord = BackendUtility::readPageAccess($pageUid, $permissionClause);
×
59
        if ($pageRecord) {
×
60
            $moduleTemplate->getDocHeaderComponent()->setMetaInformation($pageRecord);
×
61
        }
62

63
        return $moduleTemplate;
×
64
    }
65

66
    protected function makeCrawlerProcessableChecks(array $extensionSettings): void
67
    {
68
        if (! $this->isPhpForkAvailable()) {
×
69
            $this->isErrorDetected = true;
×
70
            MessageUtility::addErrorMessage(
×
71
                $this->getLanguageService()->sL(
×
72
                    'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:message.noPhpForkAvailable'
×
73
                )
×
74
            );
×
75
        }
76

77
        $exitCode = 0;
×
78
        $out = [];
×
79
        CommandUtility::exec(PhpBinaryUtility::getPhpBinary() . ' -v', $out, $exitCode);
×
80
        if ($exitCode > 0) {
×
81
            $this->isErrorDetected = true;
×
82
            MessageUtility::addErrorMessage(
×
83
                sprintf($this->getLanguageService()->sL(
×
84
                    'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:message.phpBinaryNotFound'
×
85
                ), htmlspecialchars((string) $extensionSettings['phpPath'], ENT_QUOTES | ENT_HTML5))
×
86
            );
×
87
        }
88
    }
89

90
    protected function getModuleMenu(): array
91
    {
92
        return [
×
93
            'logDepth' => [
×
94
                0 => $this->getLanguageService()->sL(
×
95
                    'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_0'
×
96
                ),
×
97
                1 => $this->getLanguageService()->sL(
×
98
                    'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_1'
×
99
                ),
×
100
                2 => $this->getLanguageService()->sL(
×
101
                    'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_2'
×
102
                ),
×
103
                3 => $this->getLanguageService()->sL(
×
104
                    'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_3'
×
105
                ),
×
106
                4 => $this->getLanguageService()->sL(
×
107
                    'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_4'
×
108
                ),
×
109
                99 => $this->getLanguageService()->sL(
×
110
                    'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_infi'
×
111
                ),
×
112
            ],
×
113
            'crawlaction' => [
×
114
                'start' => $this->getLanguageService()->sL(
×
115
                    'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.start'
×
116
                ),
×
117
                'log' => $this->getLanguageService()->sL(
×
118
                    'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.log'
×
119
                ),
×
120
                'multiprocess' => $this->getLanguageService()->sL(
×
121
                    'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.multiprocess'
×
122
                ),
×
123
            ],
×
124
            'log_resultLog' => '',
×
125
            'log_feVars' => '',
×
126
            'processListMode' => '',
×
127
            'displayLog' => [
×
128
                'all' => $this->getLanguageService()->sL(
×
129
                    'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.all'
×
130
                ),
×
131
                'pending' => $this->getLanguageService()->sL(
×
132
                    'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.pending'
×
133
                ),
×
134
                'finished' => $this->getLanguageService()->sL(
×
135
                    'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.finished'
×
136
                ),
×
137
            ],
×
138
            'itemsPerPage' => [
×
139
                '5' => $this->getLanguageService()->sL(
×
140
                    'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.itemsPerPage.5'
×
141
                ),
×
142
                '10' => $this->getLanguageService()->sL(
×
143
                    'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.itemsPerPage.10'
×
144
                ),
×
145
                '50' => $this->getLanguageService()->sL(
×
146
                    'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.itemsPerPage.50'
×
147
                ),
×
148
                '0' => $this->getLanguageService()->sL(
×
149
                    'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.itemsPerPage.0'
×
150
                ),
×
151
            ],
×
152
        ];
×
153
    }
154

155
    protected function getLanguageService(): LanguageService
156
    {
157
        return $GLOBALS['LANG'];
×
158
    }
159

160
    protected function getBackendUserAuthentication(): BackendUserAuthentication
161
    {
162
        return $GLOBALS['BE_USER'];
×
163
    }
164

165
    /**
166
     * Indicate that the required PHP method "popen" is
167
     * available in the system.
168
     */
169
    private function isPhpForkAvailable(): bool
170
    {
171
        return function_exists('popen');
×
172
    }
173
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc