[interchange-cvs] interchange - heins modified 4 files

interchange-core@icdevgroup.org interchange-core@icdevgroup.org
Wed Apr 23 12:06:00 2003


User:      heins
Date:      2003-04-23 16:01:02 GMT
Modified:  dist/foundation catalog.cfg
Modified:  dist/foundation/etc log_transaction
Modified:  lib/Vend Order.pm
Modified:  lib/Vend/Table Common.pm
Log:
* Fix mv_form_profile to work with &and/&or checks. (Last fix did not work.)

* While vetting MySQL and transactions, I discovered that we weren't doing
  them right on several levels anyway.

  -- Added no-commit flag to [import ..] tag so that we don't automatically
     commit after the order import.

  -- If the Route "transactions" entry is specified in the main route,
     the commit or rollback is done based on success/failure of all
	 of the routes (that don't have error_ok set).

* Added MYSQL_TRANSACTIONS variable to allow creation/use of MySQL
  InnoDB type for order transactions. Will add additional_fields
  support in separate commit.

Revision  Changes    Path
2.19      +4 -5      interchange/dist/foundation/catalog.cfg


rev 2.19, prev_rev 2.18
Index: catalog.cfg
===================================================================
RCS file: /var/cvs/interchange/dist/foundation/catalog.cfg,v
retrieving revision 2.18
retrieving revision 2.19
diff -u -r2.18 -r2.19
--- catalog.cfg	12 Apr 2003 00:21:24 -0000	2.18
+++ catalog.cfg	23 Apr 2003 16:01:02 -0000	2.19
@@ -287,11 +287,6 @@
 	track        logs/log
 EOF
 
-ifdef TRANSACTION_TABLES
-Route log       transactions '__TRANSACTION_TABLES__'
-Route log_entry transactions '__TRANSACTION_TABLES__'
-endif
-
 ## This route copies the user if they requested that. We don't
 ## care (much) if it fails, so error_ok is set and failure will
 ## not cause the order to fail
@@ -352,6 +347,8 @@
 Route   entry   empty           1
 Route   entry   supplant        1
 Route   entry   no_receipt      1
+Route   entry   write_tables    "inventory userdb transactions orderline"
+Route   entry   transactions    '__TRANSACTION_TABLES__'
 Route   entry   email           '__ORDERS_TO__'
 
 # Default route is run if no routes set, this should be last Route
@@ -360,6 +357,8 @@
 Route   default   cascade         "log main copy_user"
 Route   default   empty           1
 Route   default   supplant        1
+Route   default   write_tables    "inventory userdb transactions orderline"
+Route   default   transactions    '__TRANSACTION_TABLES__'
 Route   default   email           '__ORDERS_TO__'
 
 ## Uncomment this if you want Routes read dynamically from DB



2.8       +2 -2      interchange/dist/foundation/etc/log_transaction


rev 2.8, prev_rev 2.7
Index: log_transaction
===================================================================
RCS file: /var/cvs/interchange/dist/foundation/etc/log_transaction,v
retrieving revision 2.7
retrieving revision 2.8
diff -u -r2.7 -r2.8
--- log_transaction	12 Apr 2003 00:21:24 -0000	2.7
+++ log_transaction	23 Apr 2003 16:01:02 -0000	2.8
@@ -183,7 +183,7 @@
 [/if]
 [seti total_cost][total-cost noformat=1][/seti]
 Add main order [value mv_order_number] to transactions:
-[import table=transactions type=LINE continue=NOTES]
+[import table=transactions type=LINE continue=NOTES no-commit=1]
 code: [value mv_order_number]
 store_id: __STORE_ID__
 order_number: [value mv_order_number]
@@ -258,7 +258,7 @@
 [set download_present][/set]
 
 [item-list]Added [item-code] to orderline:
-[import table=orderline type=LINE continue=NOTES]
+[import table=orderline type=LINE continue=NOTES no-commit=1]
 code: [value mv_order_number]-[item-increment]
 store_id: __STORE_ID__
 order_number: [value mv_order_number]



2.55      +56 -15    interchange/lib/Vend/Order.pm


rev 2.55, prev_rev 2.54
Index: Order.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Order.pm,v
retrieving revision 2.54
retrieving revision 2.55
diff -u -r2.54 -r2.55
--- Order.pm	20 Apr 2003 16:26:16 -0000	2.54
+++ Order.pm	23 Apr 2003 16:01:02 -0000	2.55
@@ -1,6 +1,6 @@
 # Vend::Order - Interchange order routing routines
 #
-# $Id: Order.pm,v 2.54 2003/04/20 16:26:16 mheins Exp $
+# $Id: Order.pm,v 2.55 2003/04/23 16:01:02 mheins Exp $
 #
 # Copyright (C) 1996-2001 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -28,7 +28,7 @@
 package Vend::Order;
 require Exporter;
 
-$VERSION = substr(q$Revision: 2.54 $, 10);
+$VERSION = substr(q$Revision: 2.55 $, 10);
 
 @ISA = qw(Exporter);
 
@@ -345,13 +345,13 @@
 }
 
 sub chain_checks {
-	my ($or, $ref, $checks, $err) = @_;
+	my ($or, $ref, $checks, $err, $vref) = @_;
 	my ($var, $val, $mess, $message);
 	my $result = 1;
 	$mess = "$checks $err";
 	while($mess =~ s/(\S+=\w+)[\s,]*//) {
 		my $check = $1;
-		($val, $var, $message) = do_check($check);
+		($val, $var, $message) = do_check($check, $vref);
 		return undef if ! defined $var;
 		if($val and $or) {
 			1 while $mess =~ s/(\S+=\w+)[\s,]*//;
@@ -963,7 +963,8 @@
 		$val =~ s/&#(\d+);/chr($1)/ge;
 
 		if ($Parse{$var}) {
-			($val, $var, $message) = $Parse{$var}->($ref, $val, $m);
+			## $vref added for chained checks only
+			($val, $var, $message) = $Parse{$var}->($ref, $val, $m, $vref);
 		}
 		else {
 			logError( "Unknown order check parameter in profile %s: %s=%s",
@@ -1623,6 +1624,11 @@
 	# Settable by user to indicate failure
 	delete $::Scratch->{mv_route_failed};
 
+	## Allow setting of a master transaction route. This allows 
+	## setting tables in transaction mode, then only committing
+	## once all routes have completed.
+	my $master_transactions;
+
 	ROUTES: {
 		BUILD:
 	foreach $c (@routes) {
@@ -1963,7 +1969,14 @@
 
 	for(@route_failed) {
 		my $route = $Vend::Cfg->{Route_repository}{$_};
+
+#::logDebug("checking route $_ for transactions");
+		## We only want to roll back the master at the end
+		next if $route->{master};
+
+
 		if($route->{transactions}) {
+#::logDebug("rolling back route $_");
 			Vend::Interpolate::flag( 'rollback', {}, $route->{transactions})
 		}
 		next unless $route->{rollback};
@@ -1976,7 +1989,12 @@
 
 	for(@route_complete) {
 		my $route = $Vend::Cfg->{Route_repository}{$_};
+#::logDebug("checking route $_ for transactions");
+		## We only want to commit the master if nothing failed
+		next if $route->{master};
+
 		if($route->{transactions}) {
+#::logDebug("committing route $_");
 			Vend::Interpolate::flag( 'commit', {}, $route->{transactions})
 		}
 		next unless $route->{commit};
@@ -1989,19 +2007,42 @@
 
 	if(! $errors) {
 		delete $Vend::Session->{order_error};
-	}
-	elsif ($main->{errors_to}) {
-		$Vend::Session->{order_error} = $errors;
-#### change this to use Vend::Mail::send
-		send_mail(
-			$main->{errors_to},
-			errmsg("ERRORS on ORDER %s", $::Values->{mv_order_number}),
-			$errors
+#::logDebug("no errors, commiting main route");
+		if($main->{transactions}) {
+			Vend::Interpolate::flag( 'commit', {}, $main->{transactions})
+		}
+		if($main->{commit}) {
+			Vend::Interpolate::tag_perl(
+						$main->{commit_tables},
+						{},
+						$main->{commit}
 			);
+		}
 	}
 	else {
-		$Vend::Session->{order_error} = $errors;
-		::logError("ERRORS on ORDER %s:\n%s", $::Values->{mv_order_number}, $errors);
+		if($main->{transactions}) {
+#::logDebug("errors, rolling back main route");
+			Vend::Interpolate::flag( 'rollback', {}, $main->{transactions})
+		}
+		if($main->{rollback}) {
+			Vend::Interpolate::tag_perl(
+						$main->{rollback_tables},
+						{},
+						$main->{rollback}
+			);
+		}
+		if ($main->{errors_to}) {
+			$Vend::Session->{order_error} = $errors;
+			send_mail(
+				$main->{errors_to},
+				errmsg("ERRORS on ORDER %s", $::Values->{mv_order_number}),
+				$errors
+				);
+		}
+		else {
+			$Vend::Session->{order_error} = $errors;
+			::logError("ERRORS on ORDER %s:\n%s", $::Values->{mv_order_number}, $errors);
+		}
 	}
 
 	# Get rid of this puppy



2.27      +6 -3      interchange/lib/Vend/Table/Common.pm


rev 2.27, prev_rev 2.26
Index: Common.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Table/Common.pm,v
retrieving revision 2.26
retrieving revision 2.27
diff -u -r2.26 -r2.27
--- Common.pm	16 Feb 2003 11:48:02 -0000	2.26
+++ Common.pm	23 Apr 2003 16:01:02 -0000	2.27
@@ -1,6 +1,6 @@
 # Vend::Table::Common - Common access methods for Interchange databases
 #
-# $Id: Common.pm,v 2.26 2003/02/16 11:48:02 racke Exp $
+# $Id: Common.pm,v 2.27 2003/04/23 16:01:02 mheins Exp $
 #
 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
 # Copyright (C) 2003 ICDEVGROUP <interchange@icdevgroup.org>
@@ -23,7 +23,7 @@
 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 # MA  02111-1307  USA.
 
-$VERSION = substr(q$Revision: 2.26 $, 10);
+$VERSION = substr(q$Revision: 2.27 $, 10);
 use strict;
 
 package Vend::Table::Common;
@@ -1325,7 +1325,10 @@
 			File::Copy::copy(@{$_});
 		}
 	}
-	$out->commit() if $out->config('HAS_TRANSACTIONS');
+
+	unless($options->{no_commit}) {
+		$out->commit() if $out->config('HAS_TRANSACTIONS');
+	}
 	delete $out->[$CONFIG]{Clean_start};
 	delete $out->[$CONFIG]{_Dirty};
 	unlockfile(\*IN) or die "unlock\n";