|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AOE\Crawler\Backend\RequestForm; |
|
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 AOE\Crawler\Controller\CrawlerController; |
|
23
|
|
|
use AOE\Crawler\Utility\MessageUtility; |
|
24
|
|
|
use AOE\Crawler\Utility\PhpBinaryUtility; |
|
25
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
|
26
|
|
|
use TYPO3\CMS\Core\Utility\CommandUtility; |
|
27
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
28
|
|
|
|
|
29
|
|
|
class AbstractRequestForm |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* @var CrawlerController |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $crawlerController; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var bool |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $isErrorDetected = false; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var array |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $extensionSettings = []; |
|
45
|
|
|
|
|
46
|
|
|
protected function findCrawler(): CrawlerController |
|
47
|
|
|
{ |
|
48
|
|
|
if (! $this->crawlerController instanceof CrawlerController) { |
|
|
|
|
|
|
49
|
|
|
$this->crawlerController = GeneralUtility::makeInstance(CrawlerController::class); |
|
50
|
|
|
} |
|
51
|
|
|
return $this->crawlerController; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
1 |
|
protected function getLanguageService(): LanguageService |
|
55
|
|
|
{ |
|
56
|
1 |
|
return $GLOBALS['LANG']; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Verify that the crawler is executable. |
|
61
|
|
|
*/ |
|
62
|
1 |
|
protected function makeCrawlerProcessableChecks(array $extensionSettings): void |
|
63
|
|
|
{ |
|
64
|
1 |
|
if (! $this->isPhpForkAvailable()) { |
|
65
|
|
|
$this->isErrorDetected = true; |
|
66
|
|
|
MessageUtility::addErrorMessage($this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:message.noPhpForkAvailable')); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
1 |
|
$exitCode = 0; |
|
70
|
1 |
|
$out = []; |
|
71
|
1 |
|
CommandUtility::exec( |
|
72
|
1 |
|
PhpBinaryUtility::getPhpBinary() . ' -v', |
|
73
|
1 |
|
$out, |
|
74
|
1 |
|
$exitCode |
|
75
|
|
|
); |
|
76
|
1 |
|
if ($exitCode > 0) { |
|
77
|
|
|
$this->isErrorDetected = true; |
|
78
|
|
|
MessageUtility::addErrorMessage(sprintf($this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:message.phpBinaryNotFound'), htmlspecialchars($extensionSettings['phpPath'], ENT_QUOTES | ENT_HTML5))); |
|
79
|
|
|
} |
|
80
|
1 |
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Indicate that the required PHP method "popen" is |
|
84
|
|
|
* available in the system. |
|
85
|
|
|
*/ |
|
86
|
1 |
|
private function isPhpForkAvailable(): bool |
|
87
|
|
|
{ |
|
88
|
1 |
|
return function_exists('popen'); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|