1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ApacheSolrForTypo3\Tika\Service\Extractor; |
6
|
|
|
|
7
|
|
|
/* |
8
|
|
|
* This file is part of the TYPO3 CMS project. |
9
|
|
|
* |
10
|
|
|
* It is free software; you can redistribute it and/or modify it under |
11
|
|
|
* the terms of the GNU General Public License, either version 2 |
12
|
|
|
* of the License, or any later version. |
13
|
|
|
* |
14
|
|
|
* For the full copyright and license information, please read the |
15
|
|
|
* LICENSE.txt file that was distributed with this source code. |
16
|
|
|
* |
17
|
|
|
* The TYPO3 project - inspiring people to share! |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
use ApacheSolrForTypo3\Tika\Service\File\SizeValidator; |
21
|
|
|
use ApacheSolrForTypo3\Tika\Util; |
22
|
|
|
use Psr\Log\LoggerAwareInterface; |
23
|
|
|
use Psr\Log\LoggerAwareTrait; |
24
|
|
|
use Psr\Log\LogLevel; |
25
|
|
|
use TYPO3\CMS\Core\Resource\Index\ExtractorInterface; |
26
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Class AbstractExtractor |
30
|
|
|
* |
31
|
|
|
* @copyright (c) 2015 Ingo Renner <[email protected]> |
32
|
|
|
*/ |
33
|
|
|
abstract class AbstractExtractor implements ExtractorInterface, LoggerAwareInterface |
34
|
|
|
{ |
35
|
|
|
use LoggerAwareTrait; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
protected array $configuration; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Priority in handling extraction |
44
|
|
|
* |
45
|
|
|
* @var int |
46
|
|
|
*/ |
47
|
|
|
protected int $priority = 0; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var SizeValidator |
51
|
|
|
*/ |
52
|
|
|
protected SizeValidator $fileSizeValidator; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Constructor |
56
|
|
|
* @param array|null $extensionConfiguration |
57
|
|
|
* @param SizeValidator|null $fileSizeValidator |
58
|
|
|
*/ |
59
|
3 |
|
public function __construct(array $extensionConfiguration = null, SizeValidator $fileSizeValidator = null) |
60
|
|
|
{ |
61
|
3 |
|
$this->configuration = $extensionConfiguration ?? Util::getTikaExtensionConfiguration(); |
62
|
3 |
|
$this->fileSizeValidator = $fileSizeValidator ?? GeneralUtility::makeInstance( |
63
|
3 |
|
SizeValidator::class, |
64
|
3 |
|
$this->configuration |
65
|
3 |
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Returns an array of supported file types |
70
|
|
|
* |
71
|
|
|
* @return array |
72
|
|
|
*/ |
73
|
|
|
public function getFileTypeRestrictions(): array |
74
|
|
|
{ |
75
|
|
|
return []; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Get all supported DriverClasses |
80
|
|
|
* |
81
|
|
|
* @return string[] names of supported drivers/driver classes |
82
|
|
|
*/ |
83
|
|
|
public function getDriverRestrictions(): array |
84
|
|
|
{ |
85
|
|
|
return $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['tika']['extractor']['driverRestrictions']; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Returns the data priority of the extraction Service. |
90
|
|
|
* |
91
|
|
|
* @return int |
92
|
|
|
*/ |
93
|
|
|
public function getPriority(): int |
94
|
|
|
{ |
95
|
|
|
return $this->priority; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Returns the execution priority of the extraction Service |
100
|
|
|
* |
101
|
|
|
* @return int |
102
|
|
|
*/ |
103
|
|
|
public function getExecutionPriority(): int |
104
|
|
|
{ |
105
|
|
|
return $this->priority; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Logs a message and optionally data to log file |
110
|
|
|
* |
111
|
|
|
* @param string $message Log message |
112
|
|
|
* @param array $data Optional data |
113
|
|
|
*/ |
114
|
|
|
protected function log(string $message, array $data = []): void |
115
|
|
|
{ |
116
|
|
|
if (!$this->configuration['logging']) { |
117
|
|
|
return; |
118
|
|
|
} |
119
|
|
|
$this->logger->/** @scrutinizer ignore-call */ log( |
120
|
|
|
LogLevel::DEBUG, // Previous value 0 |
121
|
|
|
$message, |
122
|
|
|
$data |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|