Config migration must happen after all plugin implementations are initialized

Introduced new callback for settings plugin to hook into the point after the settings have been migrated since the initialize method is not suitable for that as it might be called before other plugin implementations reachable through hooks are initialized.
This commit is contained in:
Gina Häußge 2015-06-19 22:31:05 +02:00
parent 269f18a22f
commit 0e60b26048
2 changed files with 21 additions and 5 deletions

View file

@ -853,9 +853,9 @@ class SettingsPlugin(OctoPrintPlugin):
Your plugin's implementation should take care of migrating any data by utilizing self._settings. OctoPrint
will take care of saving any changes to disk by calling `self._settings.save()` after returning from this method.
This method will be called before your plugin's :func:`initialize` method, but with all injections already
having taken place. You can therefore depend on the configuration having been migrated by the time :func:`initialize`
is called.
This method will be called before your plugin's :func:`on_settings_initialized` method, with all injections already
having taken place. You can therefore depend on the configuration having been migrated by the time
:func:`on_settings_initialized` is called.
Arguments:
target (int): The settings format version the plugin requires, this should always be the same value as
@ -865,6 +865,15 @@ class SettingsPlugin(OctoPrintPlugin):
"""
pass
def on_settings_initialized(self):
"""
Called after the settings have been initialized and - if necessary - also been migrated through a call to
func:`on_settings_migrate`.
This method will always be called after the `initialize` method.
"""
pass
class EventHandlerPlugin(OctoPrintPlugin):
"""

View file

@ -210,7 +210,7 @@ class Server():
set_preprocessors=set_preprocessors)
return dict(settings=plugin_settings)
def settings_plugin_pre_init(name, implementation):
def settings_plugin_config_migration(name, implementation):
if not isinstance(implementation, octoprint.plugin.SettingsPlugin):
return
@ -224,10 +224,17 @@ class Server():
implementation._settings.set_int(["_config_version"], settings_version)
implementation._settings.save()
implementation.on_settings_initialized()
pluginManager.implementation_inject_factories=[octoprint_plugin_inject_factory, settings_plugin_inject_factory]
pluginManager.implementation_pre_inits=[settings_plugin_pre_init]
pluginManager.initialize_implementations()
settingsPlugins = pluginManager.get_implementations(octoprint.plugin.SettingsPlugin)
for implementation in settingsPlugins:
settings_plugin_config_migration(implementation._identifier, implementation)
pluginManager.implementation_post_inits=[settings_plugin_config_migration]
pluginManager.log_all_plugins()
# initialize file manager and register it for changes in the registered plugins