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

tomasnorre / crawler / 18366940435

09 Oct 2025 05:55AM UTC coverage: 69.666% (+0.4%) from 69.284%
18366940435

push

github

web-flow
[TASK] Add RequestHelper to cleanup the BackendControllers (#1198)

23 of 46 new or added lines in 4 files covered. (50.0%)

1920 of 2756 relevant lines covered (69.67%)

3.24 hits per line

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

0.0
/Classes/Controller/Backend/BackendModuleCrawlerProcessController.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\Controller\Backend\Helper\RequestHelper;
23
use AOE\Crawler\Crawler;
24
use AOE\Crawler\Domain\Repository\ProcessRepository;
25
use AOE\Crawler\Domain\Repository\QueueRepository;
26
use AOE\Crawler\Exception\ProcessException;
27
use AOE\Crawler\Hooks\CrawlerHookInterface;
28
use AOE\Crawler\Service\BackendModuleLinkService;
29
use AOE\Crawler\Service\ProcessService;
30
use AOE\Crawler\Utility\MessageUtility;
31
use Psr\Http\Message\ResponseInterface;
32
use Psr\Http\Message\ServerRequestInterface;
33
use TYPO3\CMS\Backend\Template\ModuleTemplate;
34
use TYPO3\CMS\Core\Utility\GeneralUtility;
35
use TYPO3\CMS\Core\Utility\MathUtility;
36

37
/**
38
 * @internal since v12.0.0
39
 */
40
final class BackendModuleCrawlerProcessController extends AbstractBackendModuleController implements BackendModuleControllerInterface
41
{
42
    public const BACKEND_MODULE = 'web_site_crawler_process';
43

44
    public function __construct(
45
        private readonly ProcessService $processService,
46
        private readonly ProcessRepository $processRepository,
47
        private readonly QueueRepository $queueRepository,
48
        private readonly BackendModuleLinkService $backendModuleLinkService,
49
        private readonly Crawler $crawler
50
    ) {
51
    }
×
52

53
    public function handleRequest(ServerRequestInterface $request): ResponseInterface
54
    {
55
        $this->pageUid = (int) ($request->getQueryParams()['id'] ?? -1);
×
56
        $this->moduleTemplate = $this->setupView($request, $this->pageUid);
×
57
        $this->moduleTemplate->assign('currentPageId', $this->pageUid);
×
58
        $this->moduleTemplate = $this->moduleTemplate->makeDocHeaderModuleMenu(
×
59
            [
×
60
                'id' => $request->getQueryParams()['id'] ?? -1,
×
61
            ]
×
62
        );
×
63
        $this->moduleTemplate = $this->assignValues($request);
×
64
        $this->runRefreshHooks();
×
65

66
        return $this->moduleTemplate->renderResponse('Backend/ProcessOverview');
×
67
    }
68

69
    private function assignValues(ServerRequestInterface $request): ModuleTemplate
70
    {
71
        try {
72
            $this->handleProcessOverviewActions($request);
×
73
        } catch (\Throwable $e) {
×
74
            $this->isErrorDetected = true;
×
75
            MessageUtility::addErrorMessage($e->getMessage());
×
76
        }
77

NEW
78
        $mode = RequestHelper::getStringFromRequest($request, 'processListMode', 'simple');
×
79
        $allProcesses = $mode === 'simple' ? $this->processRepository->findAllActive() : $this->processRepository->findAll();
×
80
        $isCrawlerEnabled = !$this->crawler->isDisabled() && !$this->isErrorDetected;
×
81
        $currentActiveProcesses = $this->processRepository->findAllActive()->count();
×
82
        $maxActiveProcesses = MathUtility::forceIntegerInRange($this->extensionSettings['processLimit'], 1, 99, 1);
×
83

84
        return $this->moduleTemplate->assignMultiple([
×
85
            'pageId' => $this->pageUid,
×
86
            'refreshLink' => $this->backendModuleLinkService->getRefreshLink($this->moduleTemplate, $this->pageUid),
×
87
            'addLink' => $this->backendModuleLinkService->getAddLink(
×
88
                $this->moduleTemplate,
×
89
                $currentActiveProcesses,
×
90
                $maxActiveProcesses,
×
91
                $isCrawlerEnabled
×
92
            ),
×
93
            'modeLink' => $this->backendModuleLinkService->getModeLink($this->moduleTemplate, $mode),
×
94
            'flushLink' => $this->backendModuleLinkService->getFlushLink($this->moduleTemplate),
×
95
            'enableDisableToggle' => $this->backendModuleLinkService->getEnableDisableLink(
×
96
                $this->moduleTemplate,
×
97
                $isCrawlerEnabled
×
98
            ),
×
99
            'processCollection' => $allProcesses,
×
100
            'cliPath' => $this->processService->getCrawlerCliPath(),
×
101
            'isCrawlerEnabled' => $isCrawlerEnabled,
×
102
            'totalUnprocessedItemCount' => $this->queueRepository->countAllPendingItems(),
×
103
            'assignedUnprocessedItemCount' => $this->queueRepository->countAllAssignedPendingItems(),
×
104
            'activeProcessCount' => $currentActiveProcesses,
×
105
            'maxActiveProcessCount' => $maxActiveProcesses,
×
106
            'mode' => $mode,
×
107
            'displayActions' => 0,
×
108
        ]);
×
109
    }
110

111
    /**
112
     * Method to handle incoming actions of the process overview
113
     *
114
     * @throws ProcessException
115
     */
116
    private function handleProcessOverviewActions(ServerRequestInterface $request): void
117
    {
NEW
118
        $action = RequestHelper::getStringFromRequest($request, 'action');
×
119

120
        switch ($action) {
121
            case 'stopCrawling':
×
122
                //set the cli status to disable (all processes will be terminated)
123
                $this->crawler->setDisabled(true);
×
124
                break;
×
125
            case 'addProcess':
×
126
                if ($this->processService->startProcess() === false) {
×
127
                    throw new ProcessException($this->getLanguageService()->sL(
×
128
                        'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.newprocesserror'
×
129
                    ));
×
130
                }
131
                MessageUtility::addNoticeMessage(
×
132
                    $this->getLanguageService()->sL(
×
133
                        'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.newprocess'
×
134
                    )
×
135
                );
×
136
                break;
×
137
            case 'flushProcess':
×
138
                $processes = $this->processRepository->findAll();
×
139
                foreach ($processes as $process) {
×
140
                    $this->processRepository->removeByProcessId($process->getProcessId());
×
141
                }
142
                break;
×
143
            case 'resumeCrawling':
×
144
            default:
145
                //set the cli status to end (all processes will be terminated)
146
                $this->crawler->setDisabled(false);
×
147
                break;
×
148
        }
149
    }
150

151
    /**
152
     * Activate hooks
153
     */
154
    private function runRefreshHooks(): void
155
    {
156
        foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['refresh_hooks'] ?? [] as $objRef) {
×
157
            /** @var CrawlerHookInterface $hookObj */
158
            $hookObj = GeneralUtility::makeInstance($objRef);
×
159
            if (is_object($hookObj)) {
×
160
                $hookObj->crawler_init();
×
161
            }
162
        }
163
    }
164
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc