[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[4069] branches/1.3



Revision: 4069
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4069&view=rev
Author:   einhverfr
Date:     2011-11-25 10:08:28 +0000 (Fri, 25 Nov 2011)
Log Message:
-----------
initial rewrite of backup logic done on new framework.  Needs a little testing before we freeze

Modified Paths:
--------------
    branches/1.3/Changelog
    branches/1.3/LedgerSMB/Database.pm
    branches/1.3/UI/setup/confirm_operation.html
    branches/1.3/UI/setup/new_user.html
    branches/1.3/UI/setup/select_coa.html
    branches/1.3/UI/setup/upgrade_info.html
    branches/1.3/scripts/setup.pl

Added Paths:
-----------
    branches/1.3/UI/setup/begin_backup.html

Modified: branches/1.3/Changelog
===================================================================
--- branches/1.3/Changelog	2011-11-25 07:49:44 UTC (rev 4068)
+++ branches/1.3/Changelog	2011-11-25 10:08:28 UTC (rev 4069)
@@ -16,8 +16,9 @@
 * Correcting parse errors in pos_template.txt (Chris T)
 * Corrected Action not defined error on asset import (Chris T)
 * Corrected permissions issue for editing assembly (Chris T)
+* Database administration interface more consistent (Chris T)
+* Backup functionality moved to database administration interface (Chris T)
 
-
 Changelog for LedgerSMB 1.3.6
 * Including xelatex templates under directory templates/xedemo (Chris T)
 * Fix for company name in order entry (David B)

Modified: branches/1.3/LedgerSMB/Database.pm
===================================================================
--- branches/1.3/LedgerSMB/Database.pm	2011-11-25 07:49:44 UTC (rev 4068)
+++ branches/1.3/LedgerSMB/Database.pm	2011-11-25 10:08:28 UTC (rev 4069)
@@ -71,7 +71,7 @@
     return $self;
 }
 
-=item base_backuo()
+=item base_backup
 
 This routine connects to the database using pg_dumpall and returns a plain text,
 roles-only dump of the current database cluster.  This is left uncompressed for

Added: branches/1.3/UI/setup/begin_backup.html
===================================================================
--- branches/1.3/UI/setup/begin_backup.html	                        (rev 0)
+++ branches/1.3/UI/setup/begin_backup.html	2011-11-25 10:08:28 UTC (rev 4069)
@@ -0,0 +1,54 @@
+<?lsmb INCLUDE "ui-header.html" 
+stylesheet="ledgersmb.css"
+include_stylesheet=["UI/setup/stylesheet.css"] ?>
+<?lsmb PROCESS elements.html ?>
+<body>
+<h2><?lsmb text('Database Management Console') ?></h2>
+<div class="listtop"><?lsmb text('Where shall we send the backup?') ?></div>
+<?lsmb # notice, message, and operation are all localized. ?>
+<div id="notice"><?lsmb notice ?></div>
+<form action="setup.pl" method="POST" name="confirm_operation">
+<?lsmb INCLUDE input element_data = {
+    name = 'database'
+    type = 'hidden'
+   value = database
+} ?>
+<?lsmb INCLUDE input element_data = {
+    name = 'backup'
+    type = 'hidden'
+   value = backup
+} ?>
+<div class="inputrow" id="emailopt">
+<?lsmb INCLUDE input element_data = {
+    type = 'radio'
+    name = 'backup_type'
+   label = text('To email') #'
+   value = 'email'
+}, label_pos = 1 ?>
+<?lsmb INCLUDE inout element_data = {
+    type = "text"
+    name = "email"
+   value = email
+   class = "email"
+?>
+</div>
+<div class="inputrow" id="browseropt">
+<?lsmb INCLUDE input element_data = {
+    type = 'radio'
+    name = 'backup_type'
+   label = text('To my browser') #'
+   value = 'browser'
+}, label_pos = 1 ?>
+</div>
+<div class="inputrow">
+<?lsmb INCLUDE button element_data = {
+    name = 'action'
+   value = 'run_backup'
+    type = 'submit'
+   class = 'submit'
+    text = text('Run Backup') #'
+} ?>
+</div>
+</form>
+</body>
+</html>

Modified: branches/1.3/UI/setup/confirm_operation.html
===================================================================
--- branches/1.3/UI/setup/confirm_operation.html	2011-11-25 07:49:44 UTC (rev 4068)
+++ branches/1.3/UI/setup/confirm_operation.html	2011-11-25 10:08:28 UTC (rev 4069)
@@ -3,6 +3,7 @@
 include_stylesheet=["UI/setup/stylesheet.css"] ?>
 <?lsmb PROCESS elements.html ?>
 <body>
+<h2><?lsmb text('Database Management Console') ?></h2>
 <div class="listtop"><?lsmb text('Confirm Operation') ?></div>
 <?lsmb # notice, message, and operation are all localized. ?>
 <div id="notice"><?lsmb notice ?></div>
@@ -14,30 +15,30 @@
     type = 'hidden'
    value = database
 } ?>
-<div class="inputrow" id="yesno">
-<?lsmb 
-INCLUDE input element_data = {
-    name = 'confirm'
-   value = '1'
-    type = 'radio'
-   class = 'confirm'
-   label = text('Yes')
-} ;
-INCLUDE input element_data = {
-    name = 'confirm'
-   value = '0'
-    type = 'radio'
-   class = 'confirm'
-   label = text('No')
+<div class="inputrow">
+<?lsmb INCLUDE button element_data = {
+    name = 'action'
+   value = next_action
+    type = 'submit'
+   class = 'submit'
+    text = text('Yes') 
 } ?>
 </div>
+<div id="others"><?lsmb text('Backup') ?></div>
 <div class="inputrow">
 <?lsmb INCLUDE button element_data = {
     name = 'action'
-   value = next_action
+   value = 'backup_db'
     type = 'submit'
+   class = 'submit'
+    text = text('Backup DB') #'
+} ?>
+<?lsmb INCLUDE button element_data = {
+    name = 'action'
+   value = 'backup_roles'
+    type = 'submit'
    class = 'next'
-    text = text('Next') 
+    text = text('Backup Roles') #' 
 } ?>
 </div>
 </form>

Modified: branches/1.3/UI/setup/new_user.html
===================================================================
--- branches/1.3/UI/setup/new_user.html	2011-11-25 07:49:44 UTC (rev 4068)
+++ branches/1.3/UI/setup/new_user.html	2011-11-25 10:08:28 UTC (rev 4069)
@@ -3,6 +3,7 @@
 include_stylesheet=["UI/setup/stylesheet.css"] ?>
 <?lsmb PROCESS elements.html ?>
 <body>
+<h2><?lsmb text('Database Management Console') ?></h2>
 <div class="listtop"><?lsmb text('Enter User') ?></div>
 <form action="setup.pl" method="POST" name="new_user">
 <?lsmb INCLUDE input element_data = {

Modified: branches/1.3/UI/setup/select_coa.html
===================================================================
--- branches/1.3/UI/setup/select_coa.html	2011-11-25 07:49:44 UTC (rev 4068)
+++ branches/1.3/UI/setup/select_coa.html	2011-11-25 10:08:28 UTC (rev 4069)
@@ -3,7 +3,7 @@
 include_stylesheet=["UI/setup/stylesheet.css"] ?>
 <?lsmb PROCESS elements.html ?>
 <body>
-<h2>Database Management Console</h2>
+<h2><?lsmb text('Database Management Console') ?></h2>
 <div class="listtop"><?lsmb title ?></div>
 <form action="setup.pl" method="POST" name="credentials">
 <?lsmb IF coa_lc;

Modified: branches/1.3/UI/setup/upgrade_info.html
===================================================================
--- branches/1.3/UI/setup/upgrade_info.html	2011-11-25 07:49:44 UTC (rev 4068)
+++ branches/1.3/UI/setup/upgrade_info.html	2011-11-25 10:08:28 UTC (rev 4069)
@@ -3,6 +3,7 @@
 include_stylesheet=["UI/setup/stylesheet.css"] ?>
 <?lsmb PROCESS elements.html ?>
 <body>
+<h2><?lsmb text('Database Management Console') ?></h2>
 <div class="listtop"><?lsmb text('Enter User') ?></div>
 <form action="setup.pl" method="POST" name="new_user">
 <?lsmb INCLUDE input element_data = {

Modified: branches/1.3/scripts/setup.pl
===================================================================
--- branches/1.3/scripts/setup.pl	2011-11-25 07:49:44 UTC (rev 4068)
+++ branches/1.3/scripts/setup.pl	2011-11-25 10:08:28 UTC (rev 4069)
@@ -126,6 +126,107 @@
 
 }
 
+=item backup_db
+
+Backs up a full db
+
+=cut
+
+sub backup_db {
+    my $request = shift @_;
+    $request->{backup} = 'db';
+    _begin_backup($request);
+}
+
+=item backup_roles
+
+Backs up roles only (for all db's)
+
+=cut
+
+sub backup_roles {
+    my $request = shift @_;
+    $request->{backup} = 'roles';
+    _begin_backup($request);
+}
+
+# Private method, basically just passes the inputs on to the next screen.
+sub _begin_backup {
+    my $request = shift @_;
+    my $template = LedgerSMB::Template->new(
+            path => 'UI/setup',
+            template => 'begin_backup',
+            format => 'HTML',
+    );
+    $template->render($request);
+};
+
+
+=item run_backup
+
+Runs the backup.  If backup_type is set to email, emails the 
+
+=cut
+
+sub run_backup {
+    use LedgerSMB::Company_Config;
+
+    my $request = shift @_;
+    my $database = LedgerSMB::Database->new(
+               {username => $creds->{username},
+            company_name => $request->{database},
+                password => $creds->{password}}
+    );
+
+    my $backupfile;
+    my $mimetype;
+
+    if ($request->{backup} eq 'roles'){
+       $backupfile = $database->base_backup; 
+       $mimetype   = 'text/x-sql';
+    } elsif ($request->{backup} eq 'db'){
+       $backupfile = $database->db_backup;
+       $mimetype   = 'application/octet-stream';
+    } else {
+        $request->error($request->{_locale}->text('Invalid backup request'));
+    }
+
+    if ($request->{backup_type} eq 'email'){
+        my $csettings = $LedgerSMB::Company_Config::settings;
+	my $mail = new LedgerSMB::Mailer(
+		from          => $csettings->{default_email_from},
+		to            => $request->{email},
+		subject       => "Email of Backup",
+		message       => 'The Backup is Attached',
+	);
+	$mail->attach(
+            mimetype => $mimetype,
+            filename => $backupfile,
+            file     => $backupfile,
+	);
+        $mail->send;
+    } elsif ($request->{backup_type} eq 'browser'){
+        open BAK, '<', $backupfile;
+        my $cgi = CGI::Simple->new();
+        print $cgi->header(
+          -type       => $mimetype,
+          -status     => '200',
+          -charset    => 'utf-8',
+          -attachment => $backupfile,
+        );
+    } else {
+        $request->error($request->{_locale}->text("Don't know what to do with backup");
+    }
+    my $template = LedgerSMB::Template->new(
+            path => 'UI/setup',
+            template => 'complete',
+            format => 'HTML',
+    );
+    $template->render($request);
+ 
+}
+   
+
 =item migrate_sl
 
 Beginning of an SQL-Ledger 2.7/2.8 migration.

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.