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

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



Revision: 5458
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=5458&view=rev
Author:   einhverfr
Date:     2013-01-02 03:51:08 +0000 (Wed, 02 Jan 2013)
Log Message:
-----------
Merging setup.pl enhancements to 1.3

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

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

Property Changed:
----------------
    branches/1.3/
    branches/1.3/scripts/setup.pl


Property changes on: branches/1.3
___________________________________________________________________
Modified: svn:mergeinfo
   - /trunk:3711-3712,5424
   + /trunk:3711-3712,5424,5446-5448,5457

Modified: branches/1.3/Changelog
===================================================================
--- branches/1.3/Changelog	2013-01-02 03:48:47 UTC (rev 5457)
+++ branches/1.3/Changelog	2013-01-02 03:51:08 UTC (rev 5458)
@@ -2,6 +2,11 @@
 Initial Release:  Monday, Oct 12 2011
 Supported Presently
 
+Changelog for 1.3.28
+* Added db list to setup.pl when no db is entered and credentials allow login
+  to "postgres" db. (Chris T)
+* Added copy db utility to setup.pl for testing dbs (Chris T)
+
 Changelog for 1.3.27
 * Detect whether ledgersmb.conf exists during Makefile.PL run and create if
   not (Chris T)

Modified: branches/1.3/LedgerSMB/Database.pm
===================================================================
--- branches/1.3/LedgerSMB/Database.pm	2013-01-02 03:48:47 UTC (rev 5457)
+++ branches/1.3/LedgerSMB/Database.pm	2013-01-02 03:51:08 UTC (rev 5458)
@@ -22,6 +22,7 @@
 # Methods are documented inline.  
 
 package LedgerSMB::Database;
+use DBI;
 
 our $VERSION = '1';
 
@@ -273,7 +274,6 @@
 =cut 
 
 sub get_info {
-    use DBI;
     use LedgerSMB::Auth;
     my $self = shift @_;
     my $retval = { # defaults
@@ -393,6 +393,39 @@
     return $retval;
 }
 
+=item $db->list()
+
+Lists available databases except for those named "postgres" or starting with
+"template"
+
+Returns a list of strings of db names.
+
+=cut
+
+sub list {
+    my ($self) = @_;
+    my $creds = LedgerSMB::Auth->get_credentials();
+    my $dbh = DBI->connect(
+        "dbi:Pg:dbname=postgres", 
+         "$creds->{login}", "$creds->{password}", { AutoCommit => 0 }
+    );
+    my $resultref = $dbh->selectall_arrayref(
+        "SELECT datname FROM pg_database 
+          WHERE datname <> 'postgres' AND datname NOT LIKE 'template%'
+       ORDER BY datname"
+    );
+    my @results;
+    for my $r (@$resultref){
+        push @results, values @$r;
+    }
+
+    $dbh->disconnect;
+    use Data::Dumper;
+    return @results;
+}
+
+
+    
 =item $db->create();
 
 Creates a database and loads the contrib files.  This is done from template0, 
@@ -420,7 +453,6 @@
     # 
     # Hat tip:  irc user nwnw -- CT
 
-    use DBI;
     my $dbh = DBI->connect('dbi:Pg:dbname=template1');
 
     $dbh->{RaiseError} = 1;
@@ -454,6 +486,25 @@
      return $rc;
 }
 
+=item $db->copy('new_name')
+
+Copies the existing database to a new name.
+
+=cut
+
+sub copy {
+    my ($self, $new_name) = @_;
+    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)
 
 Loads or reloads sql modules from $loadorder

Modified: branches/1.3/UI/setup/confirm_operation.html
===================================================================
--- branches/1.3/UI/setup/confirm_operation.html	2013-01-02 03:48:47 UTC (rev 5457)
+++ branches/1.3/UI/setup/confirm_operation.html	2013-01-02 03:51:08 UTC (rev 5458)
@@ -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'

Copied: branches/1.3/UI/setup/list_databases.html (from rev 5448, trunk/UI/setup/list_databases.html)
===================================================================
--- branches/1.3/UI/setup/list_databases.html	                        (rev 0)
+++ branches/1.3/UI/setup/list_databases.html	2013-01-02 03:51:08 UTC (rev 5458)
@@ -0,0 +1,17 @@
+<?lsmb INCLUDE "ui-header.html"
+stylesheet="ledgersmb.css"
+include_stylesheet=["UI/setup/stylesheet.css"];
+       PROCESS "elements.html";
+       PROCESS "dynatable.html"; ?>
+<body>
+<div class="listtop"><?lsmb text('Available Databases') ?></div>
+<?lsmb 
+    INCLUDE dynatable
+            columns = [{col_id = 'db', 
+                       name = text('Database'), 
+                       type = 'href'
+                  href_base = 'setup.pl?action=login&database='}]
+            tbody = {rows = dbs}
+              id = 'db_list' ?>
+</body>
+</html>

Modified: branches/1.3/scripts/setup.pl
===================================================================
--- branches/1.3/scripts/setup.pl	2013-01-02 03:48:47 UTC (rev 5457)
+++ branches/1.3/scripts/setup.pl	2013-01-02 03:51:08 UTC (rev 5458)
@@ -50,7 +50,8 @@
     #$request->{_locale}->new('en'); why not continue to use already set $request->{_locale}
     my $creds = LedgerSMB::Auth::get_credentials();
     if (!$request->{database}){
-        $request->error($request->{_locale}->text('No database specified'));
+        list_databases($request);
+        return;
     }
     my $database = LedgerSMB::Database->new(
                {username => $creds->{login},
@@ -157,6 +158,57 @@
 
 }
 
+=item list_databases
+Lists all databases as hyperlinks to continue operations.
+
+=cut
+
+sub list_databases {
+    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 @results = $database->list;
+    $request->{dbs} = [];
+    for my $r (@results){
+       push @{$request->{dbs}}, {row_id => $r, db => $r };
+    }
+    my $template = LedgerSMB::Template->new(
+            path => 'UI/setup',
+            template => 'list_databases',
+	    format => 'HTML',
+    );
+    $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


Property changes on: branches/1.3/scripts/setup.pl
___________________________________________________________________
Added: svn:mergeinfo
   + /trunk/LedgerSMB/Scripts/setup.pm:5446-5448
/trunk/scripts/setup.pl:3711-3712,5424,5446-5448

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