Skip to content

Commit 51394fd

Browse files
cedric-annetrasher
authored andcommitted
Unactivate all plugins once a mandatory update is detected
1 parent b16c9a6 commit 51394fd

File tree

3 files changed

+72
-4
lines changed

3 files changed

+72
-4
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
}

src/Glpi/Kernel/ListenersPriority.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ final class ListenersPriority
4747
PostBootListener\LoadLegacyConfiguration::class => 160,
4848
PostBootListener\LoadLanguage::class => 150,
4949
PostBootListener\CustomObjectsAutoloaderRegistration::class => 140,
50+
PostBootListener\DisablePluginsOnVersionChange::class => 135,
5051
PostBootListener\InitializePlugins::class => 130,
5152
PostBootListener\CustomObjectsBootstrap::class => 120,
5253
];

src/Update.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,6 @@ function (string $flag) {
227227
$DB->doQuery(sprintf('SET SESSION sql_mode = %s', $DB->quote(implode(',', $sql_mode_flags))));
228228
}
229229

230-
// Update process desactivate all plugins
231-
$plugin = new Plugin();
232-
$plugin->unactivateAll();
233-
234230
$migrations = $this->getMigrationsToDo($current_version, $force_latest);
235231

236232
$number_of_steps = count($migrations);

0 commit comments

Comments
 (0)