Hi!
I am currently working on some new stuff for the kirby podcaster plugin, extending the statistics. The in-depth-stats use a database to store their data.
So I am wondering where the best place might be to run migrations and in the future do other stuff to keep the plugin-installation clean. I looked out for a hook like ‘plugin.after.install’ or something, but with no result.
Can you help me?
Thank you!
Maurice
1 Like
AFAIK there’s nothing baked in.
You could create something yourself though: e.g. write the plugin version to a text file somewhere and have a bootstrap function in your plugin that checks this file and does necessary migrations + afterwards update the text file with the new version.
Related to this, I think, would be a Panel plugin that tracks plugins you’ve installed. Then, if they’re on GitHub (or similar), and it could compare version numbers of your installed plugins to alert you to updates.
Perhaps even alert you to an updated version of Kirby, as well.
https://github.com/bnomei/kirby3-doctor checks at least for current Kirby version and you can add custom checks.
1 Like
Okay,
thanks for your suggestions. I’ll keep trying around a bit and see what might be the best path to go.
I made a little workaround for that. But this in your plugin:
'hooks' => [
'system.loadPlugins:after' => function () {
if (!file_exists(__DIR__ . '/migrated') ) {
//Migrate here
file_put_contents(__DIR__ . '/migrated', '');
}
}
],
If you share your plugin with the community, put this in your .gitignore
:
/migrated
So you don’t have to care about deleting that file before publishing.