Here are a couple practical examples of using the `onExtensionAfterUpdate` plugin event in Joomla:
Injecting a custom message on extension update failure
You can use `onExtensionAfterUpdate` to inject a custom message when an extension update fails, without modifying core Joomla code:
1. Create a plugin that listens for the `onExtensionAfterUpdate` event.
2. In the plugin's `onExtensionAfterUpdate` method, check if the update failed by inspecting the `$result` parameter.
3. If the update failed, you can unset the default error message and set your own custom message instead.[1]
This allows you to provide a more helpful error message to users when your extension fails to update.
Comparing override file hashes before and after update
The Joomla Improved Override Management project uses `onExtensionAfterUpdate` to detect if template override files have changed during an extension update:
1. Before the update, it collects the md5 hashes of all override files.
2. After the update completes, it compares the hashes to find any override files that were changed or updated.
3. The changed override information is then stored in the `#__templates_overrides` database table.[1]
This allows the project to notify users if any of their template overrides were impacted by an extension update, so they can review and adjust the overrides if needed.
In summary, `onExtensionAfterUpdate` provides a hook to run custom logic after an extension has been updated, such as injecting messages or analyzing changes to override files. The key is to listen for the event, check the update result, and perform your desired actions.
Citations:[1] https://docs.joomla.org/J4.x:Improved_Override_Management
[2] https://github.com/joomla/joomla-cms/issues/31378
[3] https://github.com/joomla/joomla-cms-examples/blob/master/plugins/extension/example/example.php
[4] https://www.reddit.com/r/Kotlin/comments/18drvtr/what_are_the_real_use_cases_that_led_you_to_use/
[5] https://docs.joomla.org/J4.x:Improved_Override_Management/fa