meilisearch/Classes/Report/SchemaStatus.php

102 lines
4.0 KiB
PHP
Raw Permalink 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;
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;
/**
* Provides an status report about which schema version is used and checks
* 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 SchemaStatus extends AbstractMeilisearchStatus
2021-04-17 00:26:33 +02:00
{
/**
* The schema name property is constructed as follows:
*
* tx_meilisearch - The extension key
* x-y-z - The extension version this schema is meant to work with
* YYYYMMDD - The date the schema file was changed the last time
*
* Must be updated when changing the schema.
*
* @var string
*/
const RECOMMENDED_SCHEMA_VERSION = 'tx_meilisearch-11-0-0--20200415';
/**
* Compiles a collection of schema version checks against each configured
2021-04-17 21:20:54 +02:00
* Meilisearch server. Only adds an entry if a schema other than the
2021-04-17 00:26:33 +02:00
* recommended one was found.
*
*/
public function getStatus()
{
$reports = [];
/** @var $connectionManager ConnectionManager */
$connectionManager = GeneralUtility::makeInstance(ConnectionManager::class);
2021-04-17 21:20:54 +02:00
$meilisearchConnections = $connectionManager->getAllConnections();
2021-04-17 00:26:33 +02:00
2021-04-17 21:20:54 +02:00
foreach ($meilisearchConnections as $meilisearchConnection) {
2021-04-29 18:33:05 +02:00
$adminService = $meilisearchConnection->getService();
2021-04-17 21:20:54 +02:00
/** @var $meilisearchConnection MeilisearchConnection */
2021-04-17 00:26:33 +02:00
if (!$adminService->ping()) {
$url = $adminService->__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;
}
$isWrongSchema = $adminService->getSchema()->getName() != self::RECOMMENDED_SCHEMA_VERSION;
if ($isWrongSchema) {
2021-04-17 21:20:54 +02:00
$variables = ['meilisearch' => $adminService, 'recommendedVersion' => self::RECOMMENDED_SCHEMA_VERSION];
2021-04-17 00:26:33 +02:00
$report = $this->getRenderedReport('SchemaStatus.html', $variables);
$status = GeneralUtility::makeInstance(
Status::class,
/** @scrutinizer ignore-type */ 'Schema Version',
/** @scrutinizer ignore-type */ 'Unsupported Schema',
/** @scrutinizer ignore-type */ $report,
/** @scrutinizer ignore-type */ Status::WARNING
);
$reports[] = $status;
}
}
return $reports;
}
}