Jump to content

First module assistance: saving database


muzzer
 Share

Recommended Posts

OK, I'm finally writing my first PW module. I've grabbed Ryans Hello Process Module and mangled it to do roughly what I want. I've got a new item in the admin>setup menu called Backup Database. Clicking this runs my module which creates a backup of the PW database and saves it to the /site/assets/backups folder. Works sweet.

At present when I do an update to a PW site I make the changes locally, then go into phpMyAdmin, select the database, select options, export the database, and then import the sql to the live database. This module is meant to make the exporting process much quicker, plus since everything else in PW is so cool I just wanted to learn a bit about modules development  :)

Anyways, next I've created a link to download the file after which it is to be deleted from the /site/assets/backup folder.

However, clicking the download link gives me:

Forbidden: You don't have permission to access /site/assets/backups/db-backup.sql.gz on this server.
 
Is there a location where I can save this file but only a logged in admin user can access it? Obviously I need to be able to download this file but cannot have joe public having access to the database sql.
 
 
Link to comment
Share on other sites

Thanks Macrura,

Profile exporter is exactly what I was trying to achieve for the sql dump so it was good to see how that was wrapped up in a module. I've used a readfile() function with html headers to do a direct download of the dump, which works well. Now to tackle the import section, I'm thinking this will need to be a bit selective as overwriting session info in the database will log the user out.

Hmm, have not looked into yet but at a glance just now it looks like session info is not stored in the database.

Anyways,thanks for the pointers, helpful. I'm now beginning to see what the fuss is with module development, great stuff.

Link to comment
Share on other sites

  • 2 weeks later...

For the file download, you can also look at the wireSendFile function. It sounds like you found the DB export functions from the profile exporter. For the importer, have a look at ProcessWire's install.php file that can do an import via mysqli or an import via PDO but note that it doesn't work with just any SQL file, as it requires the simple SQL dump produced by the profile exporter (i.e. single line statements and single record INSERTs). 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...