Upgrading template programmatically only if needed

Hi,

I have a couple of plugins that have a custom model. I made some improvements and I need to upgrade the template model. I undestand that this operation can wipe out possible customization from the user, but I don’t see any posssibility to avoid this.

I’d like to know if I have any way to understand if the version of the template is the same as my previous version other than looking if it’s identical. Can I add a version to the template? In that case I would only apply my new template if my template changes.

Second question: is there a hook I can use when installing to be used to change the template?

sandro
*:slight_smile:

Versioning wouldn’t help you, because the user could modify the note type, so you’ll need to compare the actual structure. There is no hook for this, and it’s better done when you actually need to use the note type.

Thanks Damien for answering,

you pointed out what I stated at the beginning and that’s very clear. So the point is how to reduce to the minimum the possibility I need to go over hist/her possible changes.

If there was a hook on install, that seems to me pretty reasonable, the old version could be a precious hep in decision taking. But you say there’s no hook at install time. Did you ever consider
to add one?

So I check the model any time I use it (on import time). Is there any way to write down information that I can retrieve the next time I run the import?. I could at least write down information on a file in the plugin, but you may have devised a smarter and more elegant solution…

There is no install hook, and I don’t want code running until a restart, so that users can vet it if they wish. You’ll need to store your add-on data somewhere, and you can check for the presence of a key to know if it is the first startup. I can not really provide help with add-on writing I’m afraid, so I recommend you explore similar add-ons to see how they’ve handled things.