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

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



Revision: 3665
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3665&view=rev
Author:   einhverfr
Date:     2011-08-17 23:14:29 +0000 (Wed, 17 Aug 2011)

Log Message:
-----------
Setup.pl fixes, beginnings of the database migration wizard

Modified Paths:
--------------
    trunk/LedgerSMB/Database.pm
    trunk/dists/source/build.sh
    trunk/scripts/setup.pl

Modified: trunk/LedgerSMB/Database.pm
===================================================================
--- trunk/LedgerSMB/Database.pm	2011-08-17 03:29:34 UTC (rev 3664)
+++ trunk/LedgerSMB/Database.pm	2011-08-17 23:14:29 UTC (rev 3665)
@@ -207,11 +207,14 @@
        $sth = $dbh->prepare('SELECT version FROM defaults');
        $sth->execute();
        if (my ($ref) = $sth->fetchrow_hashref('NAME_lc')){
-           $retval->{appname} = 'ledgersmb';
-           $retval->{version} = 'legacy';
-           $retval->{full_version} = $ref->{version};
-           return $retval;
+           if ($ref->{version}){
+               $retval->{appname} = 'ledgersmb';
+               $retval->{version} = 'legacy';
+               $retval->{full_version} = $ref->{version};
+               return $retval;
+           }
        }
+       $dbh->rollback;
        # LedgerSMB 1.2 and above
        $sth = $dbh->prepare('SELECT value FROM defaults WHERE setting_key = ?');
        $sth->execute('version');
@@ -225,8 +228,11 @@
            } elsif ($ref->{value} =~ /^1.3/){
                 $retval->{version} = '1.3';
            }
-           return $retval;
+           if ($retval->{version}){
+              return $retval;
+           }
        }
+       $dbh->rollback;
        # SQL-Ledger 2.7-2.8 (fldname, fldvalue)
        $sth = $dbh->prepare('SELECT fldvalue FROM defaults WHERE fldname = ?');
        $sth->execute('version');
@@ -236,6 +242,7 @@
             $retval->{version} = $ref->{fldname};
             $retval->{version} =~ s/(\d+\.\d+).*/$1/g;
        }
+       $dbh->rollback;
    }
    return $retval;
 }

Modified: trunk/dists/source/build.sh
===================================================================
--- trunk/dists/source/build.sh	2011-08-17 03:29:34 UTC (rev 3664)
+++ trunk/dists/source/build.sh	2011-08-17 23:14:29 UTC (rev 3665)
@@ -2,7 +2,7 @@
 
 # Simple script to prepare for release
 
-version="1.3.0_snapshot20110803";
+version="1.3.0_snapshot20110816";
 build_d="../release";
 
 if test -d $build_d/ledgersmb; then

Modified: trunk/scripts/setup.pl
===================================================================
--- trunk/scripts/setup.pl	2011-08-17 03:29:34 UTC (rev 3664)
+++ trunk/scripts/setup.pl	2011-08-17 23:14:29 UTC (rev 3665)
@@ -21,11 +21,12 @@
 
 use LedgerSMB::Auth;
 use LedgerSMB::Database;
+use strict;
 
 sub __default {
 
     my ($request) = @_;
-    $template = LedgerSMB::Template->new(
+    my $template = LedgerSMB::Template->new(
             path => 'UI/setup',
             template => 'credentials',
 	    format => 'HTML',
@@ -105,7 +106,7 @@
         $request->{operation} = $request->{_locale}->text('Cancel?');
         $request->{next_action} = 'cancel';
     }
-    $template = LedgerSMB::Template->new(
+    my $template = LedgerSMB::Template->new(
             path => 'UI/setup',
             template => 'confirm_operation',
 	    format => 'HTML',
@@ -144,8 +145,75 @@
             company_name => $request->{database},
                 password => $creds->{password}}
     );
+
+    # ENVIRONMENT NECESSARY
+    $ENV{PGUSER} = $creds->{login};
+    $ENV{PGPASSWORD} = $creds->{password};
+    $ENV{PGDATABASE} = $request->{database};
+
+    # Credentials set above via environment variables --CT
+    $request->{dbh} = DBI->connect("dbi:Pg:dbname=$request->{database}");
+    my $locale = $request->{_locale};
+
+    my @pre_upgrade_checks = (
+       {query => "SELECT count(*), customernumber from customer
+                   GROUP BY customernumber
+                   HAVING count(*) > 1",
+         name => $locale->text('Unique Customernumber'),
+         cols => ['customernumber', 'name', 'address1', 'city', 'state', 'zip'],
+         edit => 'customernumber'},
+
+       {query => "SELECT count(*), vendornumber from vendor
+                   GROUP BY vendornumber
+                   HAVING count(*) > 1",
+         name => $locale->text('Unique Vendornumber'),
+         cols => ['vendornumber', 'name', 'address1', 'city', 'state', 'zip'],
+         edit => 'vendornumber'},
+
+       {query => 'SELECT * FROM employee where employeenumber IS NULL',
+         name => $locale->text('No null employeenumber'),
+         cols => ['login', 'name', 'employeenumber'],
+         edit => 'employeenumber'},
+
+       {query => "select partnumber, count(*) from parts 
+                  WHERE obsolete is not true
+                  group by partnumber having count(*) > 1",
+         name => $locale->text('Unique nonobsolete partnumbers'),
+         cols => ['partnumber', 'description', 'sellprice'],
+         edit => 'partnumber'},
+
+       {query => 'SELECT invnumber, count(*) from ar
+                   group by invnumber having count(*) > 1',
+         name => $locale->text('Unique AR Invoice numbers'),
+         cols =>  ['invnumber', 'transdate', 'amount', 'netamount', 'paid'],
+         edit =>  'invnumber'},
+    );
+    for my $check (@pre_upgrade_checks){
+        my $sth = $request->{dbh}->prepare($check->{query});
+        $sth->execute();
+        if ($sth->rows > 0){ # Check failed --CT
+             _failed_check($request, $check, $sth);
+        }
+    }
+    my $template = LedgerSMB::Template->new(
+            path => 'UI/setup',
+            template => 'upgrade_info',
+            format => 'HTML',
+    );
+    $template->render($request);
+    
+
 }
 
+sub _failed_check{
+    my ($request, $check, $sth) = @_;
+    my $template = LedgerSMB::Template->new(
+            path => 'UI',
+            template => 'form_dynatable',
+            format => 'HTML',
+    );
+}
+
 =item create_db
 
  Beginning of the new database workflow
@@ -181,7 +249,7 @@
          push @{$request->{coa_lcs}}, {code => $lcs};
     } 
 
-    $template = LedgerSMB::Template->new(
+    my $template = LedgerSMB::Template->new(
             path => 'UI/setup',
             template => 'select_coa',
 	    format => 'HTML',
@@ -258,14 +326,14 @@
            @{$request->{countries}} 
             = $request->call_procedure(procname => 'location_list_country' ); 
 
-           $locale = $request->{_locale};
+           my $locale = $request->{_locale};
 
            @{$request->{perm_sets}} = (
                {id => '0', label => $locale->text('Manage Users')},
                {id => '1', label => $locale->text('Full Permissions')},
            );
 
-           $template = LedgerSMB::Template->new(
+           my $template = LedgerSMB::Template->new(
                    path => 'UI/setup',
                    template => 'new_user',
 	           format => 'HTML',
@@ -290,7 +358,7 @@
              push @{$request->{coa_lcs}}, {code => $lcs};
         } 
     }
-    $template = LedgerSMB::Template->new(
+    my $template = LedgerSMB::Template->new(
             path => 'UI/setup',
             template => 'select_coa',
 	    format => 'HTML',
@@ -334,7 +402,7 @@
    }
    $request->{dbh}->commit;
    
-    $template = LedgerSMB::Template->new(
+    my $template = LedgerSMB::Template->new(
             path => 'UI/setup',
             template => 'complete',
 	    format => 'HTML',


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