Page 1 of 1

Button to export a dump of the entire database

PostPosted: Sun Jan 25, 2009 12:16 pm
by s_nalepa
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:

PostPosted: Sun Jan 25, 2009 7:10 pm
by shannah
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

PostPosted: Mon Jan 26, 2009 8:54 am
by s_nalepa
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]

PostPosted: Mon Jan 26, 2009 12:30 pm
by shannah
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.

PostPosted: Tue Jan 27, 2009 7:14 am
by s_nalepa
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.

PostPosted: Tue Jan 27, 2009 11:43 am
by shannah
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.