Alfresco create patch
When extending Alfresco having to write a patch is rather a common use case. Either you’ve changed your content model so you have to update a certain volume of documents. Or you want to apply new permissions, create new authorities, and so on. There might be a multitude of reasons for creating a patch. But in fact, what exactly is a patch?
Well, it’s pretty simple. It’s a piece of work you want to run once. Usually after a deploy (version/fix). The idea is to update the existing persistent items (Database, Solr, files system).
And really, that’s all. It can be done by a simple web script, however, web scripts can be run multiple times, and you still have to run it manually. In fact, Alfresco provides a component for that specific case. And it does more than running a piece of work once during start up. I find it really handy. so let’s see how it works.
Use Case
Let’s create a simple patch that will create a new authority zone.
Java class
createCustomZonePatch.java
Simply extends AbstractPath and overrides the method applyInternal.
Spring context and properties
custom-context.xml
i18n properties
The patch can be allowed only for a specific version this is why there are properties from/to/target. The values in my example are the defaults when you don’t want to specify a version. Thus, the patch will run next time Alfresco repository will start.
Additional information
The code will be ran in a transaction as System user. The result will be saved in the database in the table ALF_APPLIED_PATCHES.
SQL
Result