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

fix(api): allow api platform updates from installed 22.04.0 (#11495) #11533

Merged
merged 2 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 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,15 @@ msgstr "Criticité d'hôte"

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

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));
}
}
}
}