Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon OnExtensionAfterUpdate usage example
    Joomla Events


OnExtensionAfterUpdate usage example


The `onExtensionAfterUpdate` plugin event in Joomla is used to perform actions after an extension has been updated. Here are a couple examples of how to use it:

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[2]:

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[2].

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[3]:

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[3].

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://github.com/joomla/joomla-cms-examples/blob/master/plugins/extension/example/example.php
[2] https://joomla.stackexchange.com/questions/27963/how-to-inject-a-custom-message-in-joomla-update-without-touching-the-core-code
[3] https://docs.joomla.org/J4.x:Improved_Override_Management
[4] https://github.com/joomla/joomla-cms/issues/31378
[5] https://docs.joomla.org/J4.x:Improved_Override_Management/fa