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

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



Revision: 6530
          http://sourceforge.net/p/ledger-smb/code/6530
Author:   ehuelsmann
Date:     2014-01-18 21:49:34 +0000 (Sat, 18 Jan 2014)
Log Message:
-----------
If a failed upgrade/migration is found, ask to restore the old version.

Modified Paths:
--------------
    trunk/LedgerSMB/Scripts/setup.pm

Added Paths:
-----------
    trunk/UI/setup/complete_migration_revert.html

Modified: trunk/LedgerSMB/Scripts/setup.pm
===================================================================
--- trunk/LedgerSMB/Scripts/setup.pm	2014-01-18 20:15:39 UTC (rev 6529)
+++ trunk/LedgerSMB/Scripts/setup.pm	2014-01-18 21:49:34 UTC (rev 6530)
@@ -162,7 +162,23 @@
 		);
 	    $request->{operation} = $request->{_locale}->text('Cancel?');
 	    $request->{next_action} = 'cancel';
-	}
+	} elsif ($request->{next_action} eq 'rebuild_modules') {
+            # we found the current version
+            # check we don't have stale migrations around
+            my $dbh = $database->dbh();
+            my $sth = $dbh->prepare(qq(
+                SELECT count(*)<>0
+                  FROM defaults
+                 WHERE setting_key = 'migration_ok' and value = 'no'
+              ));
+            $sth->execute();
+            my ($has_stale_migration) = $sth->fetchrow_array();
+            if ($has_stale_migration) {
+                $request->{operation} = 'Restore old version?';
+                $request->{message} = 'Failed migration found';
+                $request->{next_action} = 'revert_migration';
+            }
+        }
     }
     my $template = LedgerSMB::Template->new(
             path => 'UI/setup',
@@ -313,6 +329,35 @@
     }
  
 }
+
+=item revert_migration
+
+=cut
+
+sub revert_migration {
+    my ($request) = @_;
+    my $database = _get_database($request);
+    my $dbh = $database->dbh();
+    my $sth = $dbh->prepare(qq(
+         SELECT value
+           FROM defaults
+          WHERE setting_key = 'migration_src_schema'
+      ));
+    $sth->execute();
+    my ($src_schema) = $sth->fetchrow_array();
+    $dbh->rollback();
+    $dbh->do("DROP SCHEMA public CASCADE");
+    $dbh->do("ALTER SCHEMA $src_schema RENAME TO public");
+    $dbh->commit();
+
+    my $template = LedgerSMB::Template->new(
+        path => 'UI/setup',
+        template => 'complete_migration_revert',
+        format => 'HTML',
+           );
+
+    $template->render($request);
+}
    
 =item _get_template_directories
 
@@ -829,7 +874,7 @@
 =cut
 
 sub process_and_run_upgrade_script {
-    my ($request, $database, $template) = @_;
+    my ($request, $database, $src_schema, $template) = @_;
     my $dbh = $database->dbh;
     my $temp = $database->loader_log_filename();
     my $rc;
@@ -851,6 +896,10 @@
        INSERT INTO defaults (setting_key, value)
                      VALUES ('migration_ok', 'no')
      ));
+    $dbh->do(qq(
+       INSERT INTO defaults (setting_key, value)
+                     VALUES ('migration_src_schema', '$src_schema')
+     ));
     $dbh->commit;
 
     my $dbtemplate = LedgerSMB::Template->new(
@@ -881,7 +930,7 @@
            ${temp}_stdout and ${temp}_stderr))
 	if ! $success;
 
-    $dbh->do("delete from defaults where setting_key='migration_ok'");
+    $dbh->do("delete from defaults where setting_key like 'migration_%'");
     $dbh->commit;
 
 }
@@ -903,7 +952,7 @@
     $v =~ s/\.//;
     $dbh->do("ALTER SCHEMA public RENAME TO lsmb$v");
 
-    process_and_run_upgrade_script($request, $database,
+    process_and_run_upgrade_script($request, $database, "lsmb$v",
 				   "$dbinfo->{version}-1.4");
 
     if ($v eq '1.2'){
@@ -927,7 +976,7 @@
     $dbh->do('ALTER SCHEMA public RENAME TO sl28');
     # process_and_run_upgrade_script commits the transaction
 
-    process_and_run_upgrade_script($request, $database,
+    process_and_run_upgrade_script($request, $database, "sl28",
 				   'sl2.8-1.3');
 
     create_initial_user($request);

Added: trunk/UI/setup/complete_migration_revert.html
===================================================================
--- trunk/UI/setup/complete_migration_revert.html	                        (rev 0)
+++ trunk/UI/setup/complete_migration_revert.html	2014-01-18 21:49:34 UTC (rev 6530)
@@ -0,0 +1,15 @@
+<?lsmb INCLUDE "ui-header.html" 
+stylesheet="ledgersmb.css"
+include_stylesheet=["UI/setup/stylesheet.css"]
+include_script = ['UI/setup/login.js', 'UI/util.js', 'UI/logout/epiphany.js',   
+                  'UI/setup/iexplore.js',   'UI/setup/opera.js',
+                  'UI/setup/firefox.js',    'UI/setup/konqueror.js',  
+                  'UI/setup/safari.js' ] ?>
+<?lsmb PROCESS elements.html ?>
+<body class="<?lsmb dojo_theme ?>">
+<h2><?lsmb text('Database Management Console') ?></h2>
+<div class="listtop"><?lsmb text('Database Operation Complete') ?></div>
+<p><?lsmb text('This database operation has completed successfully.'); ?></p>
+<p><a href="setup.pl"><?lsmb text('Return to setup') ?></a></p>
+</body>
+</html>

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