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

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



Revision: 6550
          http://sourceforge.net/p/ledger-smb/code/6550
Author:   ehuelsmann
Date:     2014-01-19 13:01:11 +0000 (Sun, 19 Jan 2014)
Log Message:
-----------
Add sl2.8 migration to setup.pl.

Modified Paths:
--------------
    branches/1.3/scripts/setup.pl

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

Copied: branches/1.3/UI/setup/migrate_sl_info.html (from rev 6548, branches/1.3/UI/setup/upgrade_info.html)
===================================================================
--- branches/1.3/UI/setup/migrate_sl_info.html	                        (rev 0)
+++ branches/1.3/UI/setup/migrate_sl_info.html	2014-01-19 13:01:11 UTC (rev 6550)
@@ -0,0 +1,84 @@
+<?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('Upgrade Info') ?></div>
+<form action="setup.pl" method="POST" name="upgrade_info">
+<?lsmb INCLUDE input element_data = {
+    name = 'database'
+    type = 'hidden'
+   value = database
+} ?>
+<div class="form">
+<p>
+  LedgerSMB has introduced three new system wide default values which
+  you will need to set as part of the upgrade process.
+</p>
+<p>
+  In addition to these new defaults LedgerSMB 1.3 adds stricter
+  checks on data validity in the database. Because of these stricter checks
+  it's no longer valid to leave companies without a country or customers
+  without accounts receivable reference. The defaults you choose below will
+  be used to add values where these are currently missing but required.
+</p>
+<div class="input_row">
+<?lsmb INCLUDE select element_data = {
+                          options = countries
+                       value_attr = 'code'
+                        text_attr = 'country'
+                            name  = 'default_country'
+                           label  = text('Default Country') #'
+                            class = 'country'
+} ?>
+</div>
+<div class="input_row">
+<p>
+  LedgerSMB supports multiple <em>Accounts receivable (AR)</em> accounts
+per company. One of those must be the system default. Please select
+your default below in case of multiple. If the list below is empty,
+your database is in an inconsistent state and needs to be fixed first.
+</p>
+<?lsmb INCLUDE select element_data = {
+                            name  = 'default_ar'
+                           label  = text('Default AR') #'
+                            class = 'accno'
+                            options = ar_accounts
+                            value_attr = 'accno'
+                            text_attr = 'desc'
+} ?>
+</div>
+<div class="input_row">
+<p>
+  LedgerSMB supports multiple <em>Accounts payable (AP)</em> accounts
+per company. One of those must be the system default. Please select
+your default below in case of multiple. If the list below is empty,
+your database is in an inconsistent state and needs to be fixed first.
+</p>
+<?lsmb INCLUDE select element_data = {
+                            name  = 'default_ap'
+                           label  = text('Default AP') #'
+                            class = 'accno'
+                            options = ap_accounts
+                            value_attr = 'accno'
+                            text_attr = 'desc'
+} ?>
+</div>
+<div class="input_row">
+<p>
+  Note that the process invoked by hitting the button below might
+  take long to complete as it will run the upgrade process and will
+  copy all data from the 1.2 tables into the 1.3 tables.
+</p>
+<?lsmb INCLUDE button element_data = {
+    text = text('Upgrade') 
+    name = 'action'
+   value = 'run_migrate_sl'
+    type = 'submit'
+   class = 'submit'
+} ?>
+</div>
+</form>
+</body>
+</html>

Modified: branches/1.3/scripts/setup.pl
===================================================================
--- branches/1.3/scripts/setup.pl	2014-01-19 12:57:04 UTC (rev 6549)
+++ branches/1.3/scripts/setup.pl	2014-01-19 13:01:11 UTC (rev 6550)
@@ -329,7 +329,7 @@
 
 =cut
 
-sub migrate_sl{
+sub migrate_sl {
     my ($request) = @_;
     my $creds = LedgerSMB::Auth::get_credentials();
     my $database = LedgerSMB::Database->new(
@@ -345,6 +345,137 @@
 
     # Credentials set above via environment variables --CT
     $request->{dbh} = DBI->connect(qq|dbi:Pg:dbname="$request->{database}"|);
+    my $locale = $request->{_locale};
+
+    my @pre_upgrade_checks = (
+        { query => "select *
+                    from customer
+                   where customernumber in (select customernumber
+                                              from customer
+                                             group by customernumber
+                                             having count(*) > 1)",
+          name => $locale->text('Double customernumbers'), 
+          cols => ['id', 'customernumber', 'name'],
+          edit => 'customernumber',
+          table => 'customer'},
+        { query => "select *
+                    from vendor
+                   where vendornumber in (select vendornumber
+                                              from vendor
+                                             group by vendornumber
+                                             having count(*) > 1)",
+          name => $locale->text('Double vendornumbers'), 
+          cols => ['id', 'vendornumber', 'name'],
+          edit => 'vendornumber',
+          table => 'vendor'},
+        { query => "select *
+                     from employee
+                    where employeenumber is null",
+          name => $locale->text('Null employee numbers'),
+          cols => ['id', 'login', 'name', 'employeenumber'],
+          edit => 'employeenumber',
+          table => 'employee'},
+        { query => "select *
+                     from employee
+                    where employeenumber in (select employeenumber
+                                               from employee
+                                              group by employeenumber
+                                              having count(*) > 1)",
+          name => $locale->text('Null employee numbers'),
+          cols => ['id', 'login', 'name', 'employeenumber'],
+          edit => 'employeenumber',
+          table => 'employee'},
+        { query => "select *
+                     from ar
+                    where invnumber in (select invnumber
+                                          from ar
+                                         group by invnumber
+                                         having count(*) > 1)
+                   order by invnumber",
+          name => $locale->text('Non-unique invoice numbers'),
+          cols => ['id', 'invnumber', 'transdate', 'duedate', 'datepaid',
+                     'ordnumber', 'quonumber', 'approved'],
+          edit => 'invnumber',
+          table => 'ar'},
+        { query => "select *
+                     from makemodel
+                    where model is null",
+          name => $locale->text('Null model numbers'),
+          cols => ['parts_id', 'make', 'model'],
+          edit => 'model',
+          table => 'makemodel'},
+        { query => "select *
+                     from makemodel
+                    where make is null",
+          name => $locale->text('Null make numbers'),
+          cols => ['parts_id', 'make', 'model'],
+          edit => 'make',
+          table => 'makemodel'},
+        { query => "select *
+                     from partscustomer
+                    where not exists (select 1
+                                        from pricegroup
+                                       where id = pricegroup_id)",
+          name => $locale->text("Non-existing customer pricegroups in partscustomer (can't be edited through the web interface)"),
+          # No 'edit =>' section: this is an informational query
+          cols => ['parts_id', 'credit_id', 'pricegroup_id'],
+          table => 'partscustomer'}
+        );
+    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, 'fix_sl_tests');
+        }
+    }
+
+    @{$request->{ar_accounts}} = _get_linked_accounts($request, "AR");
+    @{$request->{ap_accounts}} = _get_linked_accounts($request, "AP");
+    unshift @{$request->{ar_accounts}}, {}
+       unless scalar(@{$request->{ar_accounts}}) == 1;
+    unshift @{$request->{ap_accounts}}, {}
+       unless scalar(@{$request->{ap_accounts}}) == 1;
+
+    @{$request->{countries}} = ();
+    foreach my $iso2 (all_country_codes()) {
+        push @{$request->{countries}}, { code    => uc($iso2),
+                                         country => code2country($iso2) };
+    }
+    @{$request->{countries}} =
+        sort { $a->{country} cmp $b->{country} } @{$request->{countries}};
+    unshift @{$request->{countries}}, {};
+
+
+    my $template = LedgerSMB::Template->new(
+            path => 'UI/setup',
+            template => 'migrate_sl_info',
+            format => 'HTML',
+    );
+    $template->render($request);
+}
+
+
+=item run_migrate_sl
+
+
+=cut
+
+sub run_migrate_sl{
+    my ($request) = @_;
+    my $creds = LedgerSMB::Auth::get_credentials();
+    my $database = LedgerSMB::Database->new(
+               {username => $creds->{login},
+            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(qq|dbi:Pg:dbname="$request->{database}"|);
     my $dbh = $request->{dbh};
     $dbh->do('ALTER SCHEMA public RENAME TO sl28');
     $dbh->do('CREATE SCHEMA PUBLIC');
@@ -358,12 +489,14 @@
          $rc2=system("psql -f $ENV{PG_CONTRIB_DIR}/$contrib.sql >> $temp/dblog_stdout 2>>$temp/dblog_stderr");
          $rc ||= $rc2
      }
+    $logger->info("loaded extensions");
      my $rc2 = system("psql -f sql/Pg-database.sql >> $temp/dblog_stdout 2>>$temp/dblog_stderr");
      
      $rc ||= $rc2;
 
     $database->load_modules('LOADORDER');
     $database->process_roles('Roles.sql');
+    $logger->info("loaded LOADORDER and Roles");
     my $dbtemplate = LedgerSMB::Template->new(
         user => {}, 
         path => 'sql/upgrade',
@@ -509,7 +642,7 @@
         my $sth = $request->{dbh}->prepare($check->{query});
         $sth->execute();
         if ($sth->rows > 0){ # Check failed --CT
-             _failed_check($request, $check, $sth);
+             _failed_check($request, $check, $sth, 'fix_tests');
         }
     }
 
@@ -539,7 +672,7 @@
 }
 
 sub _failed_check{
-    my ($request, $check, $sth) = @_;
+    my ($request, $check, $sth, $next_action) = @_;
     my $template = LedgerSMB::Template->new(
             path => 'UI',
             template => 'form-dynatable',
@@ -571,7 +704,7 @@
     my $buttons = [
            { type => 'submit',
              name => 'action',
-            value => 'fix_tests',
+            value => $next_action,
              text => $request->{_locale}->text('Save and Retry'),
             class => 'submit' },
     ];
@@ -585,14 +718,14 @@
     });
 }
 
-=item fix_tests
 
-Handles input from the failed test function and then re-runs the migrate db 
-script.
+=item _fix_tests
 
+
+
 =cut
 
-sub fix_tests{
+sub _fix_tests {
     my ($request) = @_;
     my $creds = LedgerSMB::Auth::get_credentials();
     # ENVIRONMENT NECESSARY
@@ -616,9 +749,34 @@
             $request->error($sth->errstr);
     }
     $request->{dbh}->commit;
+}
+
+=item fix_tests
+
+Handles input from the failed test function and then re-runs the migrate db 
+script.
+
+=cut
+
+sub fix_tests{
+    my ($request) = @_;
+    _fix_tests($request);
     upgrade($request);
 }
 
+=item fix_sl_tests
+
+Handles input from the failed test function and then re-runs the migrate db 
+script.
+
+=cut
+
+sub fix_sl_tests{
+    my ($request) = @_;
+    _fix_tests($request);    
+    migrate_sl($request);
+}
+
 =item create_db
 
  Beginning of the new database workflow

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


------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Ledger-smb-commits mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-commits