Skip to content

Commit 0f0ad69

Browse files
authored
Merge pull request #1306 from cameron1729/hooks-during-install
Clarify precautions around hooks which dispatch on install/upgrade
2 parents 2a22895 + 7c34d75 commit 0f0ad69

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

docs/apis/core/hooks/index.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,11 @@ Any guidelines for callback priority should be described in hook descriptions if
296296

297297
:::caution
298298

299-
Callbacks _are executed during system installation and all upgrades_, the callback
300-
methods must verify the plugin is in correct state. Often the easiest way is to
301-
use function during_initial_install() or version string from the plugin configuration.
299+
Hooks may be dispatched at any time, _including 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 and that the database is available if database calls are made (as the database does not exist during site installation).
300+
301+
The `during_initial_install()` function can be used to check whether the the site is currently being installed, and `get_config('your_pluginname', 'version')` are two ways to conditionally make database queries or use API functions. `isset($CFG->upgraderunning)` can also be used to test if an upgrade is running. Failing to implement these checks may render the web install/upgrade page unusable.
302+
303+
Please note that the legacy component callback system did _not_ call the `lib.php` callbacks during installation or upgrade. As such, when porting these callbacks to hooks, you may need to implement additional checks as described above.
302304

303305
:::
304306

0 commit comments

Comments
 (0)