When you delete/remove a plugin all the database tables related to it will be deleted and I would like to know if there is a way to keep them or store them into a file and force the user to download it.

I made some kind of forum and saved many relevant information in a custom table but if someone deletes/removes the plugin accidentally or to include another row nothing will work anymore.

Is there I function I can use in public function onBeforeUninstall() to save my table?

I know you can go to phpmyadmin/adminer an use the export function by hand but we are all people and we can forget that.

Thank you very much


If your plugin overrides onBeforeUninstall(), then you could call craft()->db->backup();

But that will backup the whole database via PHP code, which might not be what you want.

Since you're in a plugin, I'd probably make sure mysqldump is available to PHP via the command line and use that to execute it and that way you can also specify the exact tables you'd like to dump.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.