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

Clarify precautions around hooks which dispatch on install/upgrade #1306

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

Conversation

cameron1729
Copy link
Collaborator

No description provided.

Copy link

netlify bot commented Mar 24, 2025

Deploy Preview for moodledevdocs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 7c34d75
🔍 Latest deploy log https://app.netlify.com/sites/moodledevdocs/deploys/67e4ddaa6e251d0008e16f75
😎 Deploy Preview https://deploy-preview-1306--moodledevdocs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines 299 to 302
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.
Copy link
Member

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.

@cameron1729 cameron1729 force-pushed the hooks-during-install branch from fa165fc to 7c34d75 Compare March 27, 2025 05:10
@cameron1729
Copy link
Collaborator Author

Thanks @andrewnicols - I've updated the wording, removed line breaks, and added backticks.

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 this pull request may close these issues.

2 participants