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
|
6 |
|
public static function getResultLog($resultRow) |
34
|
|
|
{ |
35
|
6 |
|
$content = ''; |
36
|
6 |
|
if (is_array($resultRow) && array_key_exists('result_data', $resultRow)) { |
37
|
5 |
|
$requestContent = self::getJsonCompatibilityConverter()->convert($resultRow['result_data']) ?: ['content' => '']; |
38
|
5 |
|
if (! array_key_exists('content', $requestContent)) { |
|
|
|
|
39
|
1 |
|
return $content; |
40
|
|
|
} |
41
|
4 |
|
$requestResult = self::getJsonCompatibilityConverter()->convert($requestContent['content']); |
42
|
|
|
|
43
|
4 |
|
if (is_array($requestResult) && array_key_exists('log', $requestResult)) { |
44
|
2 |
|
$content = implode(chr(10), $requestResult['log']); |
45
|
|
|
} |
46
|
|
|
} |
47
|
5 |
|
return $content; |
48
|
|
|
} |
49
|
|
|
|
50
|
7 |
|
public static function getResStatus($requestContent): string |
51
|
|
|
{ |
52
|
7 |
|
if (empty($requestContent)) { |
53
|
2 |
|
return '-'; |
54
|
|
|
} |
55
|
5 |
|
if (! array_key_exists('content', $requestContent)) { |
56
|
1 |
|
return 'Content index does not exists in requestContent array'; |
57
|
|
|
} |
58
|
|
|
|
59
|
4 |
|
$requestResult = self::getJsonCompatibilityConverter()->convert($requestContent['content']); |
60
|
4 |
|
if (is_array($requestResult)) { |
61
|
3 |
|
if (empty($requestResult['errorlog'])) { |
62
|
1 |
|
return 'OK'; |
63
|
|
|
} |
64
|
2 |
|
return implode("\n", $requestResult['errorlog']); |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
if (is_bool($requestResult)) { |
|
|
|
|
68
|
1 |
|
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
|
4 |
|
public static function getResFeVars(array $resultData): array |
78
|
|
|
{ |
79
|
4 |
|
if (empty($resultData)) { |
80
|
1 |
|
return []; |
81
|
|
|
} |
82
|
3 |
|
$requestResult = self::getJsonCompatibilityConverter()->convert($resultData['content']); |
83
|
3 |
|
return $requestResult['vars'] ?? []; |
84
|
|
|
} |
85
|
|
|
|
86
|
12 |
|
private static function getJsonCompatibilityConverter(): JsonCompatibilityConverter |
87
|
|
|
{ |
88
|
12 |
|
return GeneralUtility::makeInstance(JsonCompatibilityConverter::class); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|