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

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

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

52
    public function handleRequest(ServerRequestInterface $request): ResponseInterface
53
    {
54
        $this->pageUid = (int) ($request->getQueryParams()['id'] ?? -1);
×
55
        $this->moduleTemplate = $this->setupView($request, $this->pageUid);
×
56
        $this->moduleTemplate->assign('currentPageId', $this->pageUid);
×
57
        $this->moduleTemplate->setTitle('Crawler', $GLOBALS['LANG']->getLL('module.menu.log'));
×
58
        $this->moduleTemplate = $this->moduleTemplate->makeDocHeaderModuleMenu(
×
59
            ['id' => $request->getQueryParams()['id'] ?? -1]
×
60
        );
×
61
        $this->moduleTemplate = $this->assignValues();
×
62
        $this->runRefreshHooks();
×
63

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

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

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

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

108
    /**
109
     * Method to handle incoming actions of the process overview
110
     *
111
     * @throws ProcessException
112
     */
113
    private function handleProcessOverviewActions(): void
114
    {
115
        switch (GeneralUtility::_GP('action')) {
×
116
            case 'stopCrawling':
×
117
                //set the cli status to disable (all processes will be terminated)
118
                $this->crawler->setDisabled(true);
×
119
                break;
×
120
            case 'addProcess':
×
121
                if ($this->processService->startProcess() === false) {
×
122
                    throw new ProcessException($this->getLanguageService()->sL(
×
123
                        'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.newprocesserror'
×
124
                    ));
×
125
                }
126
                MessageUtility::addNoticeMessage(
×
127
                    $this->getLanguageService()->sL(
×
128
                        'LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.newprocess'
×
129
                    )
×
130
                );
×
131
                break;
×
132
            case 'resumeCrawling':
×
133
            default:
134
                //set the cli status to end (all processes will be terminated)
135
                $this->crawler->setDisabled(false);
×
136
                break;
×
137
        }
138
    }
139

140
    /**
141
     * Activate hooks
142
     */
143
    private function runRefreshHooks(): void
144
    {
145
        foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['refresh_hooks'] ?? [] as $objRef) {
×
146
            /** @var CrawlerHookInterface $hookObj */
147
            $hookObj = GeneralUtility::makeInstance($objRef);
×
148
            if (is_object($hookObj)) {
×
149
                $hookObj->crawler_init();
×
150
            }
151
        }
152
    }
153
}
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