IndexedSearchCrawlerFilesHook   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 27
ccs 0
cts 16
cp 0
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A crawler_execute() 0 19 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AOE\Crawler\Hooks;
6
7
/*
8
 * (c) 2020 AOE GmbH <[email protected]>
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 TYPO3\CMS\Core\Utility\GeneralUtility;
23
24
/**
25
 * Crawler hook for indexed search. Works with the "crawler" extension
26
 * This hook is specifically used to index external files found on pages through the crawler extension.
27
 * @see \TYPO3\CMS\IndexedSearch\Indexer::extractLinks()
28
 * @internal this is a TYPO3-internal hook implementation and not part of TYPO3's Core API.
29
 */
30
class IndexedSearchCrawlerFilesHook
31
{
32
    /**
33
     * Call back function for execution of a log element
34
     *
35
     * @param array $params Params from log element.
36
     * @return array|null Result array
37
     */
38
    public function crawler_execute($params)
39
    {
40
        if (! is_array($params['conf'])) {
41
            return null;
42
        }
43
        // Initialize the indexer class:
44
        $indexerObj = GeneralUtility::makeInstance(\TYPO3\CMS\IndexedSearch\Indexer::class);
45
        $indexerObj->conf = $params['conf'];
46
        $indexerObj->init();
47
        // Index document:
48
        if ($params['alturl']) {
49
            $fI = pathinfo($params['document']);
50
            $ext = strtolower($fI['extension']);
51
            $indexerObj->indexRegularDocument($params['alturl'], true, $params['document'], $ext);
52
        } else {
53
            $indexerObj->indexRegularDocument($params['document'], true);
54
        }
55
        // Return OK:
56
        return ['content' => []];
57
    }
58
}
59