Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
fix(api): allow api platform updates from installed 22.04.0 (#11495)
Browse files Browse the repository at this point in the history
Refs: MON-12296
  • Loading branch information
kduret committed Aug 8, 2022
1 parent 5d0c218 commit c350361
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lang/fr_FR.UTF-8/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -16964,3 +16964,24 @@ msgstr "Criticité d'hôte"

msgid "Host severity level"
msgstr "Niveau de criticité d'hôte"

msgid "Following modules need to be removed first: %s"
msgstr "Les modules suivants doivent être supprimés : %s"

msgid "Module \"%s\" is missing"
msgstr "Le module \"%s\" est manquant"

msgid "An error occured while retrieving details of module \"%s\""
msgstr "Une erreur s'est produite lors de la récupération des informations détaillées du module \"%s\""

msgid "Centreon database schema does not seem to be installed."
msgstr "Le schema de base de données de Centreon ne semble pas installé."

msgid "Centreon database schema version is \"%s\" (\"%s\" required)."
msgstr "La version du schema de base de données de Centreon est \"%s\" (\"%s\" requise)."

msgid "Please use Web UI to install Centreon."
msgstr "Veuillez utiliser l'interface Web pour installer Centreon."

msgid "Please use Web UI to update Centreon."
msgstr "Veuillez utiliser l'interface Web pour mettre à jour Centreon."
105 changes: 105 additions & 0 deletions src/EventSubscriber/UpdateEventSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

/*
* Copyright 2005 - 2022 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/

namespace EventSubscriber;

use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Centreon\Domain\Log\LoggerTrait;
use Core\Platform\Application\Repository\ReadVersionRepositoryInterface;

class UpdateEventSubscriber implements EventSubscriberInterface
{
use LoggerTrait;

private const MINIMAL_INSTALLED_VERSION = '22.04.0';

/**
* @param ReadVersionRepositoryInterface $readVersionRepository
*/
public function __construct(
private ReadVersionRepositoryInterface $readVersionRepository,
) {
}

/**
* @inheritDoc
*/
public static function getSubscribedEvents(): array
{
return [
KernelEvents::REQUEST => [
['validateCentreonWebVersionOrFail', 35],
],
];
}

/**
* validation centreon web installed version
*
* @param RequestEvent $event
* @throws \Exception
*/
public function validateCentreonWebVersionOrFail(RequestEvent $event): void
{
$this->debug('Checking if route matches updates endpoint');
if (
$event->getRequest()->getMethod() === Request::METHOD_PATCH
&& preg_match(
'#^.*/api/(?:latest|beta|v[0-9]+|v[0-9]+\.[0-9]+)/platform/updates$#',
$event->getRequest()->getPathInfo(),
)
) {
$this->debug('Getting Centreon web current version');
$currentVersion = $this->readVersionRepository->findCurrentVersion();

if ($currentVersion === null) {
$errorMessage =
_('Centreon database schema does not seem to be installed.')
. ' '
. _('Please use Web UI to install Centreon.');
$this->error($errorMessage);
throw new \Exception(_($errorMessage));
}

$this->debug(
sprintf(
'Comparing installed version %s to required version %s',
$currentVersion,
self::MINIMAL_INSTALLED_VERSION,
),
);
if (version_compare($currentVersion, self::MINIMAL_INSTALLED_VERSION, '<')) {
$errorMessage = sprintf(
_('Centreon database schema version is "%s" ("%s" required).')
. ' '
. _('Please use Web UI to update Centreon.'),
$currentVersion,
self::MINIMAL_INSTALLED_VERSION,
);
$this->debug($errorMessage);
throw new \Exception(_($errorMessage));
}
}
}
}

0 comments on commit c350361

Please sign in to comment.