Button to export a dump of the entire database

A place for users and developers of the Xataface to discuss and receive support.

Button to export a dump of the entire database

Postby s_nalepa » Sun Jan 25, 2009 12:16 pm

Hello Steve.

Beautiful piece of work, but not very easy to get a grip of all possibilities. I would like to have a button, like the export to csv or xml, which would trigger the backup function in mysql and let you save a compressed backup copy of the database locally. I guess it shouldn't be difficult to write an sql command for this, in php, but how do I attach it to a button, and how can I place this button somewhere in the main view? :roll:
s_nalepa
 
Posts: 16
Joined: Sat Dec 29, 2007 8:43 am
Location: Lund, Sweden

Postby shannah » Sun Jan 25, 2009 7:10 pm

What you need to do is create a custom action that exports your database.

Check out
http://xataface.com/documentation/tutor ... ce_actions
http://xataface.com/wiki/actions.ini_file

These explain how to create a custom action to do something. It doesn't explain how to actually generate the database dump. There should be plenty of info on the net on this.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby s_nalepa » Mon Jan 26, 2009 8:54 am

Thanks. Actually I made it without an action. As I wanted this button to always be available I made my own copy of global_header.html in my app's templates folder, it looks like this:
Code: Select all
{if $ENV.prefs.show_logo}
      <div>
            {define_slot name="site_logo"}{include file="Dataface_Logo.html"}{/define_slot}
      </div>
      {if $ENV.user}
      <div>
            {define_slot name="backup_butn"}{include file="Backup_butn.html"}{/define_slot}
      </div>
      {/if}
{/if}


The file Backup_butn.html looks like this:
Code: Select all
<a href="http://#.#.#.#/qserver/phpmysqlautobackup/run.php"><img src="{$ENV.DATAFACE_SITE_URL}/images/backup.jpg" title="G&ouml;r en backup av databasen" alt="G&ouml;r en backup av databasen"/></a>


This one points to a script I found in a user comment in the MySql5.1 online manual. It really works, the script writes gzipped backup file named with date and time into a 777 chmod'ed folder. The script is from
http://www.dwalker.co.uk/phpmysqlautobackup/. Now I wonder how to end up back in my xataface site after running the script. Maybe through a header (location:##) tag? But I would like to pass the file_name variable and display it as a download link inside my site...[quote][/quote]
Last edited by s_nalepa on Tue Jan 27, 2009 7:37 am, edited 1 time in total.
s_nalepa
 
Posts: 16
Joined: Sat Dec 29, 2007 8:43 am
Location: Lund, Sweden

Postby shannah » Mon Jan 26, 2009 12:30 pm

It is quite a bit easier if you work within the framework (i.e. do this via a custom action). Although using your strategy of linking to an outside script is an entirely valid strategy. The easiest method would be to open the export script in a new window. That way, when the user is finished, they just close the window and they return to your application.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby s_nalepa » Tue Jan 27, 2009 7:14 am

Yes, of course.
Well, using a target attribute to the link for backup is a solution, as long as I won't understand how to put things inside the framework. How would I eg. put the results of the action:
Code: Select all
<?php
class actions_statistik {
    function handle(&$params){
       $res = mysql_query("select sum(est_low) from objekt", $app->db());
      // return $res;
       df_display(array('my_result'=>&$res),"Dataface_Main_Template.html'');

    }
}
?>

inside the original template, in "before_user_status_logged_in"? I don't seem to really understand the interaction between templates and actions, and how you can override only parts of a template.
s_nalepa
 
Posts: 16
Joined: Sat Dec 29, 2007 8:43 am
Location: Lund, Sweden

Postby shannah » Tue Jan 27, 2009 11:43 am

There are a few decisions you'll need to make before implementing this to help you to be clear on how the system should work.

1. Do you want the link to appear all the time or only if the user has previously generated a backup?
2. Do you want the link to generate the backup on the spot or to just link to cached file that was previously generated.


A custom action is used when you want to create a new page or specified action - not when you just want to embed a little snippet into the template for the entire application.

So if you just want to add a link, you can do so by just implementing a block in the application delegate class. Check out some of the documentation in the wiki on customizing the user interface for details on this. In this case you'd probably want to implement the 'after_personal_tools' block:

Code: Select all
function block__after_personal_tools(){
    echo "Put your link here";
}



You could also use actions to insert links in various places in the application. Best to just work your way step by step through the tutorials for actions and ask questions as you get stuck on that front.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 28 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved