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

tomasnorre / crawler / 11237471329

08 Oct 2024 02:20PM UTC coverage: 68.586% (-1.3%) from 69.862%
11237471329

push

github

web-flow
ci: Update coveralls workflow (#1109)

1834 of 2674 relevant lines covered (68.59%)

3.37 hits per line

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

85.87
/Classes/Service/BackendModuleLinkService.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace AOE\Crawler\Service;
6

7
/*
8
 * (c) 2023-     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
use AOE\Crawler\Controller\Backend\BackendModuleCrawlerProcessController;
22
use AOE\Crawler\Controller\Backend\Helper\UrlBuilder;
23
use Psr\Http\Message\UriInterface;
24
use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException;
25
use TYPO3\CMS\Backend\Template\ModuleTemplate;
26
use TYPO3\CMS\Core\Imaging\Icon;
27
use TYPO3\CMS\Core\Imaging\IconFactory;
28
use TYPO3\CMS\Core\Localization\LanguageService;
29

30
class BackendModuleLinkService
31
{
32
    public function __construct(
33
        private readonly IconFactory $iconFactory,
34
    ) {
35
    }
8✔
36

37
    /**
38
     * Returns a tag for the refresh icon
39
     *
40
     * @throws RouteNotFoundException
41
     */
42
    public function getRefreshLink(ModuleTemplate $moduleTemplate, int $pageUid): string
43
    {
44
        return $this->getLinkButton(
1✔
45
            $moduleTemplate,
1✔
46
            'actions-refresh',
1✔
47
            $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.refresh'),
1✔
48
            UrlBuilder::getBackendModuleUrl(
1✔
49
                [
1✔
50
                    'SET[\'crawleraction\']' => 'crawleraction',
1✔
51
                    'id' => $pageUid,
1✔
52
                ],
1✔
53
                BackendModuleCrawlerProcessController::BACKEND_MODULE
1✔
54
            )
1✔
55
        );
1✔
56
    }
57

58
    public function getFlushLink(ModuleTemplate $moduleTemplate): string
59
    {
60
        return $this->getLinkButton(
×
61
            $moduleTemplate,
×
62
            'actions-bolt',
×
63
            $this->getLanguageService()->sL(
×
64
                'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.process.flush'
×
65
            ),
×
66
            UrlBuilder::getBackendModuleUrl(
×
67
                [
×
68
                    'action' => 'flushProcess',
×
69
                ],
×
70
                BackendModuleCrawlerProcessController::BACKEND_MODULE
×
71
            )
×
72
        );
×
73
    }
74

75
    /**
76
     * @throws RouteNotFoundException
77
     */
78
    public function getAddLink(
79
        ModuleTemplate $moduleTemplate,
80
        int $currentActiveProcesses,
81
        int $maxActiveProcesses,
82
        bool $isCrawlerEnabled
83
    ): string {
84
        if (!$isCrawlerEnabled || $currentActiveProcesses >= $maxActiveProcesses) {
2✔
85
            return '';
1✔
86
        }
87

88
        return $this->getLinkButton(
1✔
89
            $moduleTemplate,
1✔
90
            'actions-add',
1✔
91
            $this->getLanguageService()->sL(
1✔
92
                'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.process.add'
1✔
93
            ),
1✔
94
            UrlBuilder::getBackendModuleUrl(
1✔
95
                [
1✔
96
                    'action' => 'addProcess',
1✔
97
                ],
1✔
98
                BackendModuleCrawlerProcessController::BACKEND_MODULE
1✔
99
            )
1✔
100
        );
1✔
101
    }
102

103
    /**
104
     * @throws RouteNotFoundException
105
     */
106
    public function getModeLink(ModuleTemplate $moduleTemplate, string $mode): string
107
    {
108
        if ($mode !== 'detail' && $mode !== 'simple') {
3✔
109
            return '';
1✔
110
        }
111

112
        if ($mode === 'detail') {
2✔
113
            $label = $this->getLanguageService()->sL(
1✔
114
                'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.show.running'
1✔
115
            );
1✔
116
            $linkMode = 'simple';
1✔
117
        } else {
118
            $label = $this->getLanguageService()->sL(
1✔
119
                'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.show.all'
1✔
120
            );
1✔
121
            $linkMode = 'detail';
1✔
122
        }
123

124
        return $this->getLinkButton(
2✔
125
            $moduleTemplate,
2✔
126
            'actions-document-view',
2✔
127
            $label,
2✔
128
            UrlBuilder::getBackendModuleUrl(
2✔
129
                [
2✔
130
                    'processListMode' => $linkMode,
2✔
131
                ],
2✔
132
                BackendModuleCrawlerProcessController::BACKEND_MODULE
2✔
133
            )
2✔
134
        );
2✔
135
    }
136

137
    /**
138
     * Returns a link for the panel to enable or disable the crawler
139
     *
140
     * @throws RouteNotFoundException
141
     */
142
    public function getEnableDisableLink(ModuleTemplate $moduleTemplate, bool $isCrawlerEnabled): string
143
    {
144
        if ($isCrawlerEnabled) {
2✔
145
            $iconIdentifier = 'tx-crawler-stop';
1✔
146
            $label = $this->getLanguageService()->sL(
1✔
147
                'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.disablecrawling'
1✔
148
            );
1✔
149
            $action = 'stopCrawling';
1✔
150
        } else {
151
            $iconIdentifier = 'tx-crawler-start';
1✔
152
            $label = $this->getLanguageService()->sL(
1✔
153
                'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.enablecrawling'
1✔
154
            );
1✔
155
            $action = 'resumeCrawling';
1✔
156
        }
157

158
        return $this->getLinkButton(
2✔
159
            $moduleTemplate,
2✔
160
            $iconIdentifier,
2✔
161
            $label,
2✔
162
            UrlBuilder::getBackendModuleUrl(
2✔
163
                [
2✔
164
                    'action' => $action,
2✔
165
                ],
2✔
166
                BackendModuleCrawlerProcessController::BACKEND_MODULE
2✔
167
            )
2✔
168
        );
2✔
169
    }
170

171
    private function getLinkButton(
172
        ModuleTemplate $moduleTemplate,
173
        string $iconIdentifier,
174
        string $title,
175
        UriInterface $href
176
    ): string {
177
        $buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
6✔
178
        return (string) $buttonBar->makeLinkButton()
6✔
179
            ->setHref((string) $href)
6✔
180
            ->setIcon($this->iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL))
6✔
181
            ->setTitle($title)
6✔
182
            ->setShowLabelText(true);
6✔
183
    }
184

185
    private function getLanguageService(): LanguageService
186
    {
187
        return $GLOBALS['LANG'];
6✔
188
    }
189
}
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