diff --git a/Classes/Hooks/Form/FieldWizard/SolrCoreStatus.php b/Classes/Hooks/Form/FieldWizard/SolrCoreStatus.php new file mode 100644 index 00000000..42e14a9a --- /dev/null +++ b/Classes/Hooks/Form/FieldWizard/SolrCoreStatus.php @@ -0,0 +1,76 @@ + + * + * 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 + * @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; + } +} diff --git a/Configuration/TCA/tx_dlf_solrcores.php b/Configuration/TCA/tx_dlf_solrcores.php index e5f21cc3..6b1a897f 100644 --- a/Configuration/TCA/tx_dlf_solrcores.php +++ b/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', + ], + ], ], ], ], diff --git a/Resources/Private/Language/FlashMessages.xml b/Resources/Private/Language/FlashMessages.xml index 9ccb20ef..fdb10738 100644 --- a/Resources/Private/Language/FlashMessages.xml +++ b/Resources/Private/Language/FlashMessages.xml @@ -19,6 +19,8 @@ + + @@ -92,6 +94,8 @@ + + diff --git a/ext_localconf.php b/ext_localconf.php index c2b91efa..474f9f6d 100644 --- a/ext_localconf.php +++ b/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 +];