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

SF.net SVN: ledger-smb:[5448] trunk



Revision: 5448
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=5448&view=rev
Author:   einhverfr
Date:     2012-12-31 12:43:09 +0000 (Mon, 31 Dec 2012)
Log Message:
-----------
Database copying for test purposes now supported

Modified Paths:
--------------
    trunk/LedgerSMB/Database.pm
    trunk/LedgerSMB/Scripts/setup.pm
    trunk/UI/setup/confirm_operation.html

Modified: trunk/LedgerSMB/Database.pm
===================================================================
--- trunk/LedgerSMB/Database.pm	2012-12-31 12:10:10 UTC (rev 5447)
+++ trunk/LedgerSMB/Database.pm	2012-12-31 12:43:09 UTC (rev 5448)
@@ -415,7 +415,8 @@
     );
     my $resultref = $dbh->selectall_arrayref(
         "SELECT datname FROM pg_database 
-          WHERE datname <> 'postgres' AND datname NOT LIKE 'template%'"
+          WHERE datname <> 'postgres' AND datname NOT LIKE 'template%'
+       ORDER BY datname"
     );
     my @results;
     for my $r (@$resultref){
@@ -498,11 +499,15 @@
 
 sub copy {
     my ($self, $new_name) = @_;
-    my $dbh = DBI->connect('dbi:Pg:dbname=postgres');
-    my $dbname = $dbh->quote_ident($self->{dbname});
-    $new_name = $dbh->quote_ident($new_name);
-    $dbh->do("CREATE DATABASE $new_name WITH TEMPLATE $dbname");
+    my $dbh = DBI->connect('dbi:Pg:dbname=postgres', 
+         $self->{username}, $self->{password},
+         { AutoCommit => 1, PrintError => 1, }
+    );
+    my $dbname = $dbh->quote_identifier($self->{company_name});
+    $new_name = $dbh->quote_identifier($new_name);
+    my $rc = $dbh->do("CREATE DATABASE $new_name WITH TEMPLATE $dbname");
     $dbh->disconnect;
+    return $rc;
 }        
 
 =item $db->load_modules($loadorder)

Modified: trunk/LedgerSMB/Scripts/setup.pm
===================================================================
--- trunk/LedgerSMB/Scripts/setup.pm	2012-12-31 12:10:10 UTC (rev 5447)
+++ trunk/LedgerSMB/Scripts/setup.pm	2012-12-31 12:43:09 UTC (rev 5448)
@@ -177,6 +177,31 @@
     $template->render($request);
 }
 
+=item copy_db
+
+Copies db to the name of $request->{new_name}
+
+=cut
+
+sub copy_db {
+    my ($request) = @_;
+    my $creds = LedgerSMB::Auth::get_credentials('setup');
+    my $database = LedgerSMB::Database->new(
+               {username => $creds->{login},
+            company_name => $request->{database},
+                password => $creds->{password}}
+    );
+    my $rc = $database->copy($request->{new_name}) 
+           || die 'An error occurred. Please check your database logs.' ;
+    my $template = LedgerSMB::Template->new(
+            path => 'UI/setup',
+            template => 'complete',
+            format => 'HTML',
+    );
+    $template->render($request);
+}
+
+
 =item backup_db
 
 Backs up a full db

Modified: trunk/UI/setup/confirm_operation.html
===================================================================
--- trunk/UI/setup/confirm_operation.html	2012-12-31 12:10:10 UTC (rev 5447)
+++ trunk/UI/setup/confirm_operation.html	2012-12-31 12:43:09 UTC (rev 5448)
@@ -27,7 +27,23 @@
 </div>
 <div id="sep" class="listheading"><?lsmb text('Other Actions') ?></div>
 <?lsmb IF next_action == 'rebuild_modules' ?>
+<div id="copy database">
+<?lsmb INCLUDE input element_data = {
+    name = 'new_name'
+    type = 'text'
+   class = 'dbname'
+   label = text('Copy to New Name') #'
+}; ?>
+<?lsmb INCLUDE button element_data = {
+    name = 'action'
+   value = 'copy_db'
+    type = 'submit'
+   class = 'submit'
+    text = text('Copy') #'
+}; ?>
+
 <div id="user">
+<div><?lsmb text('Users') ?></div>
 <?lsmb INCLUDE button element_data = {
     name = 'action'
    value = 'skip_coa'

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