|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * --------------------------------------------------------------------- |
| 5 | + * |
| 6 | + * GLPI - Gestionnaire Libre de Parc Informatique |
| 7 | + * |
| 8 | + * http://glpi-project.org |
| 9 | + * |
| 10 | + * @copyright 2015-2025 Teclib' and contributors. |
| 11 | + * @licence https://www.gnu.org/licenses/gpl-3.0.html |
| 12 | + * |
| 13 | + * --------------------------------------------------------------------- |
| 14 | + * |
| 15 | + * LICENSE |
| 16 | + * |
| 17 | + * This file is part of GLPI. |
| 18 | + * |
| 19 | + * This program is free software: you can redistribute it and/or modify |
| 20 | + * it under the terms of the GNU General Public License as published by |
| 21 | + * the Free Software Foundation, either version 3 of the License, or |
| 22 | + * (at your option) any later version. |
| 23 | + * |
| 24 | + * This program is distributed in the hope that it will be useful, |
| 25 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 27 | + * GNU General Public License for more details. |
| 28 | + * |
| 29 | + * You should have received a copy of the GNU General Public License |
| 30 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 31 | + * |
| 32 | + * --------------------------------------------------------------------- |
| 33 | + */ |
| 34 | + |
| 35 | +namespace Glpi\Kernel\Listener\PostBootListener; |
| 36 | + |
| 37 | +use DBConnection; |
| 38 | +use Glpi\Debug\Profiler; |
| 39 | +use Glpi\Kernel\ListenersPriority; |
| 40 | +use Glpi\Kernel\PostBootEvent; |
| 41 | +use Plugin; |
| 42 | +use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
| 43 | +use Update; |
| 44 | + |
| 45 | +final readonly class DisablePluginsOnVersionChange implements EventSubscriberInterface |
| 46 | +{ |
| 47 | + public static function getSubscribedEvents(): array |
| 48 | + { |
| 49 | + return [ |
| 50 | + PostBootEvent::class => ['onPostBoot', ListenersPriority::POST_BOOT_LISTENERS_PRIORITIES[self::class]], |
| 51 | + ]; |
| 52 | + } |
| 53 | + |
| 54 | + public function onPostBoot(): void |
| 55 | + { |
| 56 | + if (!DBConnection::isDbAvailable()) { |
| 57 | + return; |
| 58 | + } |
| 59 | + |
| 60 | + Profiler::getInstance()->start('DisablePluginsOnVersionChange::execute', Profiler::CATEGORY_BOOT); |
| 61 | + |
| 62 | + if (Update::isUpdateMandatory()) { |
| 63 | + // Disable all plugins once a new mandatory update is detected. |
| 64 | + // This prevents incompatible plugins to be loaded. |
| 65 | + (new Plugin())->unactivateAll(); |
| 66 | + return; |
| 67 | + } |
| 68 | + |
| 69 | + Profiler::getInstance()->stop('DisablePluginsOnVersionChange::execute'); |
| 70 | + } |
| 71 | +} |
0 commit comments