diff --git a/src/octoprint/plugin/types.py b/src/octoprint/plugin/types.py index d285173c..578e117a 100644 --- a/src/octoprint/plugin/types.py +++ b/src/octoprint/plugin/types.py @@ -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): """ diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index d94ba4a4..811baaf6 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -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