2021-04-17 00:26:33 +02:00
|
|
|
<?php
|
|
|
|
namespace WapplerSystems\Meilisearch\Report;
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
* Copyright notice
|
|
|
|
*
|
|
|
|
* (c) 2011-2015 Stefan Sprenger <stefan.sprenger@dkd.de>
|
|
|
|
* (c) 2012-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;
|
2021-04-17 21:20:54 +02:00
|
|
|
use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchConnection;
|
2021-04-17 00:26:33 +02:00
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
|
|
|
use TYPO3\CMS\Reports\Status;
|
|
|
|
|
|
|
|
/**
|
2021-04-17 21:20:54 +02:00
|
|
|
* Provides a status report about whether the installed Meilisearch version matches
|
2021-04-17 00:26:33 +02:00
|
|
|
* the required version.
|
|
|
|
*
|
|
|
|
* @author Stefan Sprenger <stefan.sprenger@dkd.de>
|
|
|
|
*/
|
2021-04-17 21:20:54 +02:00
|
|
|
class MeilisearchVersionStatus extends AbstractMeilisearchStatus
|
2021-04-17 00:26:33 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2021-04-17 21:20:54 +02:00
|
|
|
* Required Meilisearch version. The version that gets installed when using the
|
|
|
|
* provided install script EXT:meilisearch/Resources/Private/Install/install-meilisearch.sh
|
2021-04-17 00:26:33 +02:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
const REQUIRED_SOLR_VERSION = '8.8.1';
|
|
|
|
|
|
|
|
/**
|
2021-04-17 21:20:54 +02:00
|
|
|
* Compiles a version check against each configured Meilisearch server.
|
2021-04-17 00:26:33 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
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) {
|
|
|
|
$coreAdmin = $meilisearchConnection->getAdminService();
|
|
|
|
/** @var $meilisearchConnection MeilisearchConnection */
|
2021-04-17 00:26:33 +02:00
|
|
|
if (!$coreAdmin->ping()) {
|
|
|
|
$url = $coreAdmin->__toString();
|
2021-04-17 21:20:54 +02:00
|
|
|
$pingFailedMsg = 'Could not ping meilisearch server, can not check version ' . (string)$url;
|
2021-04-17 00:26:33 +02:00
|
|
|
$status = GeneralUtility::makeInstance(
|
|
|
|
Status::class,
|
2021-04-17 21:20:54 +02:00
|
|
|
/** @scrutinizer ignore-type */ 'Meilisearch Version',
|
2021-04-17 00:26:33 +02:00
|
|
|
/** @scrutinizer ignore-type */ 'Not accessible',
|
|
|
|
/** @scrutinizer ignore-type */ $pingFailedMsg,
|
|
|
|
/** @scrutinizer ignore-type */ Status::ERROR
|
|
|
|
);
|
|
|
|
$reports[] = $status;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-04-17 21:20:54 +02:00
|
|
|
$meilisearchVersion = $coreAdmin->getMeilisearchServerVersion();
|
|
|
|
$isOutdatedVersion = version_compare($this->getCleanMeilisearchVersion($meilisearchVersion), self::REQUIRED_SOLR_VERSION, '<');
|
2021-04-17 00:26:33 +02:00
|
|
|
|
|
|
|
if (!$isOutdatedVersion) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-04-17 21:20:54 +02:00
|
|
|
$formattedVersion = $this->formatMeilisearchVersion($meilisearchVersion);
|
|
|
|
$variables = ['requiredVersion' => self::REQUIRED_SOLR_VERSION, 'currentVersion' => $formattedVersion, 'meilisearch' => $coreAdmin];
|
|
|
|
$report = $this->getRenderedReport('MeilisearchVersionStatus.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 */ 'Meilisearch Version',
|
2021-04-17 00:26:33 +02:00
|
|
|
/** @scrutinizer ignore-type */ 'Outdated, Unsupported',
|
|
|
|
/** @scrutinizer ignore-type */ $report,
|
|
|
|
/** @scrutinizer ignore-type */ Status::ERROR
|
|
|
|
);
|
|
|
|
|
|
|
|
$reports[] = $status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $reports;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-04-17 21:20:54 +02:00
|
|
|
* Gets the clean Meilisearch version in case of a custom build which may have
|
2021-04-17 00:26:33 +02:00
|
|
|
* additional information in the version string.
|
|
|
|
*
|
2021-04-17 21:20:54 +02:00
|
|
|
* @param string $meilisearchVersion Unformatted Meilisearch version number as provided by Meilisearch.
|
|
|
|
* @return string Clean Meilisearch version number: mayor.minor.patchlevel
|
2021-04-17 00:26:33 +02:00
|
|
|
*/
|
2021-04-17 21:20:54 +02:00
|
|
|
protected function getCleanMeilisearchVersion($meilisearchVersion)
|
2021-04-17 00:26:33 +02:00
|
|
|
{
|
2021-04-17 21:20:54 +02:00
|
|
|
$explodedMeilisearchVersion = explode('.', $meilisearchVersion);
|
2021-04-17 00:26:33 +02:00
|
|
|
|
2021-04-17 21:20:54 +02:00
|
|
|
$shortMeilisearchVersion = $explodedMeilisearchVersion[0]
|
|
|
|
. '.' . $explodedMeilisearchVersion[1]
|
|
|
|
. '.' . $explodedMeilisearchVersion[2];
|
2021-04-17 00:26:33 +02:00
|
|
|
|
2021-04-17 21:20:54 +02:00
|
|
|
return $shortMeilisearchVersion;
|
2021-04-17 00:26:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-04-17 21:20:54 +02:00
|
|
|
* Formats the Meilisearch server version number. By default this is going
|
2021-04-17 00:26:33 +02:00
|
|
|
* to be the simple major.minor.patch-level version. Custom Builds provide
|
|
|
|
* more information though, in case of custom builds, their complete
|
|
|
|
* version will be added, too.
|
|
|
|
*
|
2021-04-17 21:20:54 +02:00
|
|
|
* @param string $meilisearchVersion Unformatted Meilisearch version number as provided by Meilisearch.
|
2021-04-17 00:26:33 +02:00
|
|
|
* @return string formatted short version number, in case of custom builds followed by the complete version number
|
|
|
|
*/
|
2021-04-17 21:20:54 +02:00
|
|
|
protected function formatMeilisearchVersion($meilisearchVersion)
|
2021-04-17 00:26:33 +02:00
|
|
|
{
|
2021-04-17 21:20:54 +02:00
|
|
|
$shortMeilisearchVersion = $this->getCleanMeilisearchVersion($meilisearchVersion);
|
|
|
|
$formattedMeilisearchVersion = $shortMeilisearchVersion;
|
2021-04-17 00:26:33 +02:00
|
|
|
|
2021-04-17 21:20:54 +02:00
|
|
|
if ($meilisearchVersion != $shortMeilisearchVersion) {
|
|
|
|
$formattedMeilisearchVersion .= ' (' . $meilisearchVersion . ')';
|
2021-04-17 00:26:33 +02:00
|
|
|
}
|
|
|
|
|
2021-04-17 21:20:54 +02:00
|
|
|
return $formattedMeilisearchVersion;
|
2021-04-17 00:26:33 +02:00
|
|
|
}
|
|
|
|
}
|