meilisearch/Classes/Report/MeilisearchConfigStatus.php

85 lines
3.2 KiB
PHP
Raw Normal View History

2021-04-17 00:26:33 +02:00
<?php
namespace WapplerSystems\Meilisearch\Report;
/***************************************************************
* Copyright notice
*
* (c) 2010-2015 Ingo Renner <ingo@typo3.org>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use WapplerSystems\Meilisearch\ConnectionManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Reports\Status;
/**
2021-04-17 21:20:54 +02:00
* Provides a status report about which meilisearchconfig version is used and checks
2021-04-17 00:26:33 +02:00
* whether it fits the recommended version shipping with the extension.
*
* @author Ingo Renner <ingo@typo3.org>
*/
2021-04-17 21:20:54 +02:00
class MeilisearchConfigStatus extends AbstractMeilisearchStatus
2021-04-17 00:26:33 +02:00
{
/**
* The config name property is constructed as follows:
*
* tx_meilisearch - The extension key
* x-y-z - The extension version this config is meant to work with
* YYYYMMDD - The date the config file was changed the last time
*
2021-04-17 21:20:54 +02:00
* Must be updated when changing the meilisearchconfig.
2021-04-17 00:26:33 +02:00
*
* @var string
*/
const RECOMMENDED_SOLRCONFIG_VERSION = 'tx_meilisearch-11-0-0--20200415';
/**
2021-04-17 21:20:54 +02:00
* Compiles a collection of meilisearchconfig version checks against each configured
* Meilisearch server. Only adds an entry if a meilisearchconfig other than the
2021-04-17 00:26:33 +02:00
* recommended one was found.
*
*/
public function getStatus()
{
$reports = [];
2021-04-17 21:20:54 +02:00
$meilisearchConnections = GeneralUtility::makeInstance(ConnectionManager::class)->getAllConnections();
2021-04-17 00:26:33 +02:00
2021-04-17 21:20:54 +02:00
foreach ($meilisearchConnections as $meilisearchConnection) {
$adminService = $meilisearchConnection->getAdminService();
2021-04-17 00:26:33 +02:00
2021-04-17 21:20:54 +02:00
if ($adminService->ping() && $adminService->getMeilisearchconfigName() != self::RECOMMENDED_SOLRCONFIG_VERSION) {
$variables = ['meilisearch' => $adminService, 'recommendedVersion' => self::RECOMMENDED_SOLRCONFIG_VERSION];
$report = $this->getRenderedReport('MeilisearchConfigStatus.html', $variables);
2021-04-17 00:26:33 +02:00
$status = GeneralUtility::makeInstance(
Status::class,
2021-04-17 21:20:54 +02:00
/** @scrutinizer ignore-type */ 'Meilisearchconfig Version',
/** @scrutinizer ignore-type */ 'Unsupported meilisearchconfig.xml',
2021-04-17 00:26:33 +02:00
/** @scrutinizer ignore-type */ $report,
/** @scrutinizer ignore-type */ Status::WARNING
);
$reports[] = $status;
}
}
return $reports;
}
}