|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AOE\Crawler\Backend\Helper; |
|
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\Converter\JsonCompatibilityConverter; |
|
23
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
24
|
|
|
|
|
25
|
|
|
class ResultHandler |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Extract the log information from the current row and retrieve it as formatted string. |
|
29
|
|
|
* |
|
30
|
|
|
* @param array $resultRow |
|
31
|
|
|
* @return string |
|
32
|
|
|
*/ |
|
33
|
|
|
public static function getResultLog($resultRow) |
|
34
|
|
|
{ |
|
35
|
|
|
$content = ''; |
|
36
|
|
|
if (is_array($resultRow) && array_key_exists('result_data', $resultRow)) { |
|
37
|
|
|
$requestContent = self::getJsonCompatibilityConverter()->convert($resultRow['result_data']) ?: []; |
|
38
|
|
|
if (! array_key_exists('content', $requestContent)) { |
|
|
|
|
|
|
39
|
|
|
return $content; |
|
40
|
|
|
} |
|
41
|
|
|
$requestResult = self::getJsonCompatibilityConverter()->convert($requestContent['content']); |
|
42
|
|
|
|
|
43
|
|
|
if (is_array($requestResult) && array_key_exists('log', $requestResult)) { |
|
44
|
|
|
$content = implode(chr(10), $requestResult['log']); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
return $content; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public static function getResStatus($requestContent): string |
|
51
|
|
|
{ |
|
52
|
|
|
if (empty($requestContent)) { |
|
53
|
|
|
return '-'; |
|
54
|
|
|
} |
|
55
|
|
|
if (! array_key_exists('content', $requestContent)) { |
|
56
|
|
|
return 'Content index does not exists in requestContent array'; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$requestResult = self::getJsonCompatibilityConverter()->convert($requestContent['content']); |
|
60
|
|
|
if (is_array($requestResult)) { |
|
61
|
|
|
if (empty($requestResult['errorlog'])) { |
|
62
|
|
|
return 'OK'; |
|
63
|
|
|
} |
|
64
|
|
|
return implode("\n", $requestResult['errorlog']); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
if (is_bool($requestResult)) { |
|
|
|
|
|
|
68
|
|
|
return 'Error - no info, sorry!'; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return 'Error: ' . substr(preg_replace('/\s+/', ' ', strip_tags($requestResult)), 0, 10000) . '...'; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Find Fe vars |
|
76
|
|
|
*/ |
|
77
|
|
|
public static function getResFeVars(array $resultData): array |
|
78
|
|
|
{ |
|
79
|
|
|
if (empty($resultData)) { |
|
80
|
|
|
return []; |
|
81
|
|
|
} |
|
82
|
|
|
$requestResult = self::getJsonCompatibilityConverter()->convert($resultData['content']); |
|
83
|
|
|
return $requestResult['vars'] ?? []; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
private static function getJsonCompatibilityConverter(): JsonCompatibilityConverter |
|
87
|
|
|
{ |
|
88
|
|
|
return GeneralUtility::makeInstance(JsonCompatibilityConverter::class); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|