|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
7
|
|
|
* |
|
8
|
|
|
* @license GNU General Public License version 3 or later. |
|
9
|
|
|
* For the full copyright and license information, please read the |
|
10
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Kitodo\Dlf\Hooks\Form\FieldInformation; |
|
14
|
|
|
|
|
15
|
|
|
use Kitodo\Dlf\Common\Helper; |
|
16
|
|
|
use Kitodo\Dlf\Common\Solr; |
|
17
|
|
|
use TYPO3\CMS\Backend\Form\AbstractNode; |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* FieldInformation renderType for TYPO3 FormEngine |
|
21
|
|
|
* |
|
22
|
|
|
* @author Sebastian Meyer <[email protected]> |
|
23
|
|
|
* @package TYPO3 |
|
24
|
|
|
* @subpackage dlf |
|
25
|
|
|
* @access public |
|
26
|
|
|
*/ |
|
27
|
|
|
class SolrCoreStatus extends AbstractNode |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Shows Solr core status for given 'index_name' |
|
31
|
|
|
* |
|
32
|
|
|
* @access public |
|
33
|
|
|
* |
|
34
|
|
|
* @return array As defined in initializeResultArray() of AbstractNode |
|
35
|
|
|
* Allowed tags are: "<a><br><br/><div><em><i><p><strong><span><code>" |
|
36
|
|
|
*/ |
|
37
|
|
|
public function render(): array |
|
38
|
|
|
{ |
|
39
|
|
|
$result = $this->initializeResultArray(); |
|
40
|
|
|
// Show only when editing existing records. |
|
41
|
|
|
if ($this->data['command'] !== 'new') { |
|
42
|
|
|
$core = $this->data['databaseRow']['index_name']; |
|
43
|
|
|
// Load localization file. |
|
44
|
|
|
$GLOBALS['LANG']->includeLLFile('EXT:dlf/Resources/Private/Language/FlashMessages.xml'); |
|
45
|
|
|
// Get Solr instance. |
|
46
|
|
|
$solr = Solr::getInstance($core); |
|
47
|
|
|
if ($solr->ready) { |
|
48
|
|
|
// Get core data. |
|
49
|
|
|
$coreAdminQuery = $solr->service->createCoreAdmin(); |
|
50
|
|
|
$action = $coreAdminQuery->createStatus(); |
|
51
|
|
|
$action->setCore($core); |
|
52
|
|
|
$coreAdminQuery->setAction($action); |
|
53
|
|
|
$response = $solr->service->coreAdmin($coreAdminQuery)->getStatusResult(); |
|
54
|
|
|
if ($response) { |
|
|
|
|
|
|
55
|
|
|
$uptimeInSeconds = floor($response->getUptime() / 1000); |
|
56
|
|
|
$dateTimeFrom = new \DateTime('@0'); |
|
57
|
|
|
$dateTimeTo = new \DateTime("@$uptimeInSeconds"); |
|
58
|
|
|
$uptime = $dateTimeFrom->diff($dateTimeTo)->format('%a ' . $GLOBALS['LANG']->getLL('flash.days') . ', %H:%I:%S'); |
|
59
|
|
|
$numDocuments = $response->getNumberOfDocuments(); |
|
60
|
|
|
$startTime = $response->getStartTime() ? strftime('%c', $response->getStartTime()->getTimestamp()) : 'N/A'; |
|
61
|
|
|
$lastModified = $response->getLastModified() ? strftime('%c', $response->getLastModified()->getTimestamp()) : 'N/A'; |
|
62
|
|
|
// Create flash message. |
|
63
|
|
|
Helper::addMessage( |
|
64
|
|
|
sprintf($GLOBALS['LANG']->getLL('flash.coreStatus'), $startTime, $uptime, $lastModified, $numDocuments), |
|
65
|
|
|
'', // We must not set a title/header, because <h4> isn't allowed in FieldInformation. |
|
66
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::INFO |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
} else { |
|
70
|
|
|
// Could not fetch core status. |
|
71
|
|
|
Helper::addMessage( |
|
72
|
|
|
htmlspecialchars($GLOBALS['LANG']->getLL('solr.error')), |
|
73
|
|
|
'', // We must not set a title/header, because <h4> isn't allowed in FieldInformation. |
|
74
|
|
|
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR |
|
75
|
|
|
); |
|
76
|
|
|
} |
|
77
|
|
|
// Add message to result array. |
|
78
|
|
|
$result['html'] = Helper::renderFlashMessages(); |
|
79
|
|
|
} |
|
80
|
|
|
return $result; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths