how to delete data when plugin is disabled
-
I need to delete some data when plugin is disabled so I put an hook in plugin.json:
"hook": "action:plugin.deactivate", "method": "methodPlugin" }]~~~~ so in the library.js plugin.methodPlugin=function(id){ console.log("PR "+id); meta.settings.set('string',{}, function(err) { }); } I want delete the value in the meta.settings.set('string'.....).Anyone can help me?
-
As of https://github.com/NodeBB/NodeBB/blob/master/src/meta/settings.js it's not implemented within
meta.settings
(@administrators might want to add this).
You can require the src/database.js instead and use its exports directly.db.delete("settings:string", function (err) { ... });
should work for you.Btw you might be missing a
if (id === "some-plugin")
around this command, otherwise it will trigger on any plugin disable (if that is what you intend to do, it's fine). -
@Doppy if you want an example.... check this out
https://github.com/barisusakli/nodebb-plugin-rss/blob/master/index.js#L392
-
Make sure you have a good reason for doing this. Someone may remove a plugin and reinstall it at a later date, and still want their old settings. Right now this is how it works by default.