-
Notifications
You must be signed in to change notification settings - Fork 363
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
Clarify precautions around hooks which dispatch on install/upgrade #1306
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for moodledevdocs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
docs/apis/core/hooks/index.md
Outdated
Unlike lib.php based plugin callbacks, certain hooks _are dispatched during system installation and upgrade_ (for example `before_http_headers`). Callback | ||
methods for such hooks must take extra care to ensure the plugin is properly initialised, as (among other things) on install _the site's database is not initialised_. | ||
The function during_initial_install() or version string from the plugin configuration may be used to conditionally make DB queries or use API functions in such cases. | ||
Failure to do so may render the web install/upgrade page unusable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to linebreak - it makes diffs shit and has no impact.
Can you please put the methods, filepaths, etc. in backticks while you're at it.
I'd also suggest you don't need to say that "certain hooks" - all hooks may be. There is no definitive list. It just depends whether the hook is triggered during the process.
Perhaps something like:
Hooks may be dispatched at any time, including during installation and upgrade, therefore the callback methods for hooks which may be triggered during installation and upgrade must take care to ensure that the plugin is properly initialised and that the database is available if database calls are made.
The during_initial_install()
function can be used to check whether the Moodle site is installed, and fetching the plugin's version using get_config('your_pluginname', 'version')
are two ways that this can be achieved. Failure to do this may render the web installation and upgrade system unusable.
Please note that the legacy component callback system where callbacks were created as global functions in lib.php
could not be called during installation or upgrade.
80fdff9
to
fa165fc
Compare
fa165fc
to
7c34d75
Compare
Thanks @andrewnicols - I've updated the wording, removed line breaks, and added backticks. |
No description provided.