Skip to content

Do not disable plugins during bugfixes updates #19199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cedric-anne
Copy link
Member

Checklist before requesting a review

  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.
  • I have added tests that prove my fix is effective or that my feature works.
  • This change requires a documentation update.

Description

It make sense to disable all plugins when GLPI is upgraded to a new intermediate version (e.g. 9.4 -> 9.5) or a new major version (9.5 -> 10.0), because we can introduce BC breaks in the code that would result in a complete GLPI crash when an incompatible plugin is loaded. But it does not seems required to do it when the update does not contains more than bugfixes. Indeed, in bugfixes version, we are not suppose to introduce BC-breaks (see https://glpi-developer-documentation.readthedocs.io/en/develop/sourcecode.html#backward-compatibility).

I therefore propose to disable the plugins only when an update is made to a new intermediate or major version.

Please note that it will also prevent the tester plugin to be disabled on the test database everytime an update is made to update the DB to the latest dev version.

@cedric-anne cedric-anne added this to the 11.0.0 milestone Mar 13, 2025
@cedric-anne cedric-anne self-assigned this Mar 13, 2025
@AdrienClairembault
Copy link
Contributor

Plugins can define that they only support specific minors versions.
Couldn't this lead to a plugin being active on a version that it does not support ?

@cedric-anne
Copy link
Member Author

Plugins can define that they only support specific minors versions. Couldn't this lead to a plugin being active on a version that it does not support ?

No, the plugin loading logic will anyway check the compatibility of the plugin everytime GLPI is booted, and the plugin will be disabled in this case. See

glpi/src/Plugin.php

Lines 790 to 812 in a71aa6f

// Check prerequisites
if ($usage_ok) {
$function = 'plugin_' . $plugin_key . '_check_prerequisites';
if (function_exists($function)) {
ob_start();
if (!$function()) {
$usage_ok = false;
}
ob_end_clean();
}
}
if (!$usage_ok) {
// Deactivate if not usable
trigger_error(
sprintf(
'Plugin "%s" prerequisites are not matched. It has been deactivated.',
$plugin_key
),
E_USER_WARNING
);
$this->unactivate($plugin->fields['id']);
}

@cconard96
Copy link
Contributor

Plugin loading in general should be more resilient now. Any exception thrown from an init function should disable that plugin now. I wonder if it's needed to limit this just to bugfix versions or if it is OK globally.

@cedric-anne
Copy link
Member Author

Plugin loading in general should be more resilient now. Any exception thrown from an init function should disable that plugin now. I wonder if it's needed to limit this just to bugfix versions or if it is OK globally.

If there is compile error, the error will not be caught (see #18695), so we cannot remove this for now for all updates. Something was started to handle this, see #18765, but we did not had time yet to finish it.

@orthagh
Copy link
Contributor

orthagh commented Mar 13, 2025

I agree with this proposal only if you can assure me the plugins are not called (no hooks) during updates.
So, it is like they are temporarily disabled.

@cedric-anne
Copy link
Member Author

I agree with this proposal only if you can assure me the plugins are not called (no hooks) during updates. So, it is like they are temporarily disabled.

Our migrations are not suppose to use something else than hardoded values, and are supposed to only do direct DB queries that cannot be hooked by plugins.
Maybe there are some old migrations that contains some calls to CommonDBTM::add()/CommonDBTM::update()/.... If it cause issues, I guess we will be able to detect and fix them quickly. As long as this change is targetting an major version, I consider it as an acceptable risk.

@trasher
Copy link
Contributor

trasher commented Mar 14, 2025

I would say the same as @orthagh: I'm OK if plugins are not loaded during the installation phase - "hooks" are probably not only the only possible issue.

@cedric-anne
Copy link
Member Author

Unless on specific circumstances, the plugins are not loaded during the update process, see

if (!DBConnection::isDbAvailable() || (!defined('SKIP_UPDATES') && !Update::isDbUpToDate())) {
// Requires the database to be available.
return;
}

The are loaded only in CLI context, if the update is "replayed", or if the SKIP_UPDATES constant is defined. This is true for either the exiting code and the proposed patch.

Disabling the plugins will anyway only disable the hooks execution in the current update context. We could add a unloadAllPlugins that would have the same effect for the update process, and would permit to not have them disabled after the update process.

@cedric-anne cedric-anne marked this pull request as draft March 17, 2025 13:12
@cedric-anne cedric-anne force-pushed the 11.0/plugins-update-no-disable branch from 096dc3f to 76a3155 Compare March 25, 2025 14:13
@orthagh
Copy link
Contributor

orthagh commented Mar 25, 2025

Like I said IRL, I'm not strongly against the proposed changes.
I'm nervous about plugins interfering with GLPI during the update process.
They shouldn't, regarding the piece of code mentioned above, but the question I asked, Is there any possibility a plugin page can be called externally by a user or script and so interfere with the database.

We quickly mention the public router may disable its legacy routes when a plugin is disabled (update or not)
But can this be a solution for the current concern also?

@cedric-anne
Copy link
Member Author

cedric-anne commented Mar 26, 2025

We quickly mention the public router may disable its legacy routes when a plugin is disabled (update or not)
But can this be a solution for the current concern also?

It is a partial solution to this, and has been done in #19271.

I'm nervous about plugins interfering with GLPI during the update process.

With the current state of the code, it is not possible, but unrelated changes may change this behaviour. The best solution would be to implement the following behaviour:

  • suspend all plugins;
  • do the GLPI update;
  • optionally unsuspend all plugins if the update corresponds to a bugfixes update only.

It is probably easy to implement, and I would like to do it prior to the GLPI 11.0 RC1 release, but I have to focus on most important topics for the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants