Browse Source

Add Core status message

pull/576/head
Sebastian Meyer 11 months ago
parent
commit
f71e10b463
  1. 76
      Classes/Hooks/Form/FieldWizard/SolrCoreStatus.php
  2. 10
      Configuration/TCA/tx_dlf_solrcores.php
  3. 4
      Resources/Private/Language/FlashMessages.xml
  4. 5
      ext_localconf.php

76
Classes/Hooks/Form/FieldWizard/SolrCoreStatus.php

@ -0,0 +1,76 @@
<?php
/**
* (c) Kitodo. Key to digital objects e.V. <contact@kitodo.org>
*
* This file is part of the Kitodo and TYPO3 projects.
*
* @license GNU General Public License version 3 or later.
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
namespace Kitodo\Dlf\Hooks\Form\FieldWizard;
use Kitodo\Dlf\Common\Helper;
use Kitodo\Dlf\Common\Solr;
use TYPO3\CMS\Backend\Form\AbstractNode;
/**
* FieldWizard renderType for TYPO3 FormEngine
*
* @author Sebastian Meyer <sebastian.meyer@slub-dresden.de>
* @package TYPO3
* @subpackage dlf
* @access public
*/
class SolrCoreStatus extends AbstractNode
{
/**
* Shows Solr core status for given 'index_name'
*
* @access public
*
* @return array As defined in initializeResultArray() of AbstractNode
*/
public function render(): array
{
$result = $this->initializeResultArray();
// Show only when editing existing records.
if ($this->data['command'] !== 'new') {
$core = $this->data['databaseRow']['index_name'];
// Load localization file.
$GLOBALS['LANG']->includeLLFile('EXT:dlf/Resources/Private/Language/FlashMessages.xml');
// Get Solr instance.
$solr = Solr::getInstance($core);
if ($solr->ready) {
// Get core data.
$coreAdminQuery = $solr->service->createCoreAdmin();
$action = $coreAdminQuery->createStatus();
$action->setCore($core);
$coreAdminQuery->setAction($action);
$result = $solr->service->coreAdmin($coreAdminQuery)->getStatusResult();
$uptime = $result->getUptime();
$numDocuments = $result->getNumberOfDocuments();
$startTime = $result->getStartTime() ? date_format($result->getStartTime(), 'c') : 'N/A';
$lastModified = $result->getLastModified() ? date_format($result->getLastModified(), 'c') : 'N/A';
// Create flash message.
Helper::addMessage(
nl2br(htmlspecialchars(sprintf($GLOBALS['LANG']->getLL('flash.coreStatusDetails'), $startTime, $uptime, $lastModified, $numDocuments))),
htmlspecialchars(sprintf($GLOBALS['LANG']->getLL('flash.coreStatus'), $core)),
\TYPO3\CMS\Core\Messaging\FlashMessage::INFO
);
} else {
// Could not fetch core status.
Helper::addMessage(
htmlspecialchars($GLOBALS['LANG']->getLL('solr.error')),
htmlspecialchars($GLOBALS['LANG']->getLL('solr.notConnected')),
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
);
}
// Add message to result array.
$result['html'] = Helper::renderFlashMessages();
}
return $result;
}
}

10
Configuration/TCA/tx_dlf_solrcores.php

@ -44,11 +44,17 @@ return [
'index_name' => [
'label' => 'LLL:EXT:dlf/Resources/Private/Language/Labels.xml:tx_dlf_solrcores.index_name',
'config' => [
'type' => 'none',
'type' => 'input',
'size' => 30,
'max' => 255,
'eval' => 'alphanum,unique',
'eval' => 'alphanum,nospace,required,unique',
'default' => '',
'readOnly' => true,
'fieldWizard' => [
'solrCoreStatus' => [
'renderType' => 'solrCoreStatus',
],
],
],
],
],

4
Resources/Private/Language/FlashMessages.xml

@ -19,6 +19,8 @@
<label index="flash.done">Done!</label>
<label index="flash.warning">Warning!</label>
<label index="flash.error">Error!</label>
<label index="flash.coreStatus">Status of Solr Core "%s"</label>
<label index="flash.coreStatusDetails">Start Time: %s\nUptime: %s\nLast Modified: %s\nNumber of Documents: %s</label>
<label index="flash.running">Please wait...</label>
<label index="flash.newCollection">New collection "%s" [%u] added to database.</label>
<label index="flash.newLibrary">New library "%s" [%u] added to database.</label>
@ -92,6 +94,8 @@
<label index="flash.done">Fertig!</label>
<label index="flash.warning">Warnung!</label>
<label index="flash.error">Fehler!</label>
<label index="flash.coreStatus">Status des Solr-Kerns "%s"</label>
<label index="flash.coreStatusDetails">Start Time: %s\nUptime: %s\nLast Modified: %s\nNumber of Documents: %s</label>
<label index="flash.running">Indexierung läuft...</label>
<label index="flash.newCollection">Neue Sammlung "%s" [%u] zur Datenbank hinzugefügt.</label>
<label index="flash.newLibrary">Neue Bibliothek "%s" [%u] zur Datenbank hinzugefügt.</label>

5
ext_localconf.php

@ -256,3 +256,8 @@ $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][] = [
'priority' => 30,
'class' => \Kitodo\Dlf\Hooks\Form\FieldWizard\EditInProductionWarning::class
];
$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][] = [
'nodeName' => 'solrCoreStatus',
'priority' => 30,
'class' => \Kitodo\Dlf\Hooks\Form\FieldWizard\SolrCoreStatus::class
];

Loading…
Cancel
Save