Skip to content
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

Add hook callback for deprecated after_config callback #71

Open
djarran opened this issue Oct 17, 2024 · 2 comments · May be fixed by #72
Open

Add hook callback for deprecated after_config callback #71

djarran opened this issue Oct 17, 2024 · 2 comments · May be fixed by #72
Assignees

Comments

@djarran
Copy link
Contributor

djarran commented Oct 17, 2024

When installing the plugin on Moodle 4.5, the following error occurs:

Callback after_config in tool_abconfig component should be migrated to new hook callback for core\hook\after_config

    line 7213 of /lib/moodlelib.php: call to debugging()
    line 7280 of /lib/moodlelib.php: call to {closure}()
    line 34 of /lib/classes/hook/after_config.php: call to get_plugins_with_function()
    line 1198 of /lib/setup.php: call to core\hook\after_config->process_legacy_callbacks()
    line 235 of /config.php: call to require_once()
    line 30 of /index.php: call to require_once()
@djarran djarran self-assigned this Oct 17, 2024
@djarran
Copy link
Contributor Author

djarran commented Oct 17, 2024

Now that the callback is implemented, it is failing within the hook when creating a new cache when the cache is disabled, such as in the upgrade and install scripts when these two constants are defined:

define('CLI_SCRIPT', true);
define('CACHE_DISABLE_ALL', true);

Error:

root@4ad3d9ae8b15:/var/www/mdl405# XDEBUG_TRIGGER=1 php admin/cli/upgrade.php
!!! Coding error detected, it must be fixed by a programmer: You can only set identifiers on initial definition creation. Define a new cache to set different identifiers. !!!

Debug info:
Error code: codingerror
Stack trace: * line 774 of /cache/classes/definition.php: core\exception\coding_exception thrown
* line 111 of /cache/classes/disabled_factory.php: call to core_cache\definition->set_identifiers()
* line 190 of /cache/classes/cache.php: call to core_cache\disabled_factory->create_cache_from_definition()
* line 263 of /admin/tool/abconfig/classes/experiment_manager.php: call to core_cache\cache::make()
* line 274 of /admin/tool/abconfig/classes/experiment_manager.php: call to tool_abconfig_experiment_manager->get_experiments()
* line 102 of /admin/tool/abconfig/classes/hook_callbacks.php: call to tool_abconfig_experiment_manager->get_active_request()
* line ? of unknownfile: call to tool_abconfig\hook_callbacks::after_config()
* line 318 of /lib/classes/hook/manager.php: call to call_user_func()
* line 1199 of /lib/setup.php: call to core\hook\manager->dispatch()
* line 235 of /config.php: call to require_once()
* line 41 of /admin/cli/upgrade.php: call to require()

This should be caught in the try/catch block in the hook like in Moodle 4.1 but it is getting caught instead the default_exception_handler

    public static function after_config(\core\hook\after_config $hook) {
        try {
            global $SESSION, $USER;

            // Setup experiment manager.
            $manager = new \tool_abconfig_experiment_manager();

            ...
           
        } catch (Exception $e) {        // @codingStandardsIgnoreStart
            // Catch exceptions from stuff not existing during installation process, fail silently
        }                               // @codingStandardsIgnoreEnd
    }

@djarran
Copy link
Contributor Author

djarran commented Oct 18, 2024

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

Successfully merging a pull request may close this issue.

1 participant