Modified checkout process to use reg_db_auto_exec() calls so we didn't need to call...
authorChuck Scott <cscott@gaslightmedia.com>
Tue, 15 Nov 2016 17:08:12 +0000 (12:08 -0500)
committerChuck Scott <cscott@gaslightmedia.com>
Tue, 15 Nov 2016 17:08:12 +0000 (12:08 -0500)
To find modification search for "BEGIN" to get to where the transaction is processed.

front-end/registrations.inc

index 9f8d462..e85766b 100644 (file)
@@ -2954,7 +2954,7 @@ if ($Action == "Step6") {
 
             }
 
-
+/* - NOT ADDING TO CONTACT TABLE 
             // Enter into Contact table
             if ($config->event_registration->save_contacts) {
 
@@ -3031,6 +3031,8 @@ if ($Action == "Step6") {
                 }
 
             }
+*/
+
         }// problems so far
 
         // If there's no problems so far, try to store all this stuff
@@ -3040,85 +3042,84 @@ if ($Action == "Step6") {
             // An SQL entry to create a transaction failure for testing.
             // $transaction[] = 'SELECT * FROM a_nonexistant_table;';
 
-            // Create database connection
-            $db = Toolkit_Database::getInstance();
+// - Use to debug transaction -     $GLOBALS['reg_config']['debug'] = 3 ;
+            $transFail = false;
+            reg_db_auto_exec( 'BEGIN;' );
 
-            try {
-
-                $db->beginTransaction();
-                foreach ($transaction as $sql) {
-                    @$db->exec($sql);
+            foreach ($transaction as $sql) {
+                if (!reg_db_auto_exec($sql, 0, CONN_STR, FALSE )) {
+                    $transFail = true;
+                    break;
                 }
-                $db->commit();
-
-            } catch (Exception $e) {
+            }
+            if (!$transFail) {
+                reg_db_auto_exec( 'COMMIT;', 0, CONN_STR, FALSE  );
+            } else {
 
-                $err = $e->getMessage();
-                $db->rollback();
 
                 $reason[]['text'] = 'There was a problem storing your request. Please try again later or call for assistance.<br>';
 
-                if ($config->event_registration->debug) {
-                    $v['debug'] .= "Transaction execution problem.<br>$err<br>Query:<br><pre>$sql</pre>";
-                }
-
-                debug_mail(
-                    'cscott@gaslightmedia.com',
-                    'Event Registration Error',
-                    "Errors displayed to User:\n".print_r($reason,1)."\n\nTransaction Error:\n$err\n\nQueries:\n".print_r($transaction,1)."\n\n",
-                    "From: ".$config->event_registration->organization." <".$config->event_registration->organization_internal_email.">\n"
-                );
-
-                // If the user's credit card has been charged, notify customer of this problem
-                if ($_SESSION['GLM_EVENT_REG']['card_processed'] == true) {
-
-                    debug_mail(
-                        $config->event_registration->organization_internal_email,
-                        $v['word_Event'].' Registration Error',
-                        $v["customer_name"].":\n\n"
-                            ."The Gaslight Media ".$v['word_Event']." registration system detected that a user had a problem\n"
-                            ."while trying to check out. It is also likely that their credit card was charged.\n\n"
-                            ."This is the information we have on the user attempting to check out.\n\n"
-                            ."First Name:       ".$v['fname']."\n"
-                            ."Last Name:        ".$v['lname']."\n"
-                            ."Address:          ".$v['addr1']."\n"
-                            ."                  ".$v['addr2']."\n"
-                            ."City:             ".$v['city']."\n"
-                            ."State/Province:   ".$v['state']."\n"
-                            ."ZIP/Postal Code:  ".$v['zip']."\n"
-                            ."Country:          ".$v['country']."\n"
-                            ."Phone:            ".$v['phone']."\n"
-                            ."FAX:              ".$v['fax']."\n"
-                            ."Total Charge:     ".money($grand_total)."\n"
-                            ."Name on Card:     ".$v['ccname']."\n"
-                            ."Credit Card:      ".$v['ccnum_trunc']."\n\n"
-                            ."Contact First Name:       ".$v['contact_fname']."\n"
-                            ."Contact Last Name:        ".$v['contact_lname']."\n"
-                            ."Contact Address:          ".$v['contact_addr1']."\n"
-                            ."                                         ".$v['contact_addr2']."\n"
-                            ."Contact City:             ".$v['contact_city']."\n"
-                            ."Contact State/Province:   ".$v['contact_state']."\n"
-                            ."Contact ZIP/Postal Code:  ".$v['contact_zip']."\n"
-                            ."Contact Country:          ".$v['contact_country']."\n"
-                            ."Contact Phone:            ".$v['contact_phone']."\n"
-                            ."Contact FAX:              ".$v['contact_fax']."\n"
-                            ."E-Mail:           ".$v['email']."\n\n"
-                            ."Please check receint registrations to determine if this user was able to properly submit\n"
-                            ."the request. You should also check your credit card transactions to determine if there was\n"
-                            ."in fact a charge that is not associated with a successful submission.\n\n"
-                            ."Gaslight Media has also received a notice regarding this problem. Please contact us at\n"
-                            ."231-487-0692 if you have additional questions.\n\nGaslight Media",
-                        "From: Gaslight Media ".$v['word_Event']." Registration System <info@gaslightmedia.com>\n"
-                    );
-                }
-
-                $reason[]['text'] = "The system was unable to store your request but it appears your credit card has already been charged.<br>
-                Please contact ".$v["customer_name"]
-                                .( $cust_phone != '' ? " at ".$v["customer_phone"] : '' )
-                                ." regarding this problem.";
-
+                 if ($config->event_registration->debug) {
+                     $v['debug'] .= "Transaction execution problem.<br>Query:<br><pre>$sql</pre>";
+                 }
+
+                 debug_mail(
+                     'cscott@gaslightmedia.com',
+                     'Event Registration Error',
+                     "Errors displayed to User:\n".print_r($reason,1)."\n\nTransaction Error:\nQueries:\n".print_r($transaction,1)."\n\n",
+                     "From: ".$config->event_registration->organization." <".$config->event_registration->organization_internal_email.">\n"
+                 );
+
+                 // If the user's credit card has been charged, notify customer of this problem
+                 if ($_SESSION['GLM_EVENT_REG']['card_processed'] == true) {
+
+                     debug_mail(
+                         $config->event_registration->organization_internal_email,
+                         $v['word_Event'].' Registration Error',
+                         $v["customer_name"].":\n\n"
+                             ."The Gaslight Media ".$v['word_Event']." registration system detected that a user had a problem\n"
+                             ."while trying to check out. It is also likely that their credit card was charged.\n\n"
+                             ."This is the information we have on the user attempting to check out.\n\n"
+                             ."First Name:       ".$v['fname']."\n"
+                             ."Last Name:        ".$v['lname']."\n"
+                             ."Address:          ".$v['addr1']."\n"
+                             ."                  ".$v['addr2']."\n"
+                             ."City:             ".$v['city']."\n"
+                             ."State/Province:   ".$v['state']."\n"
+                             ."ZIP/Postal Code:  ".$v['zip']."\n"
+                             ."Country:          ".$v['country']."\n"
+                             ."Phone:            ".$v['phone']."\n"
+                             ."FAX:              ".$v['fax']."\n"
+                             ."Total Charge:     ".money($grand_total)."\n"
+                             ."Name on Card:     ".$v['ccname']."\n"
+                             ."Credit Card:      ".$v['ccnum_trunc']."\n\n"
+                             ."Contact First Name:       ".$v['contact_fname']."\n"
+                             ."Contact Last Name:        ".$v['contact_lname']."\n"
+                             ."Contact Address:          ".$v['contact_addr1']."\n"
+                             ."                                        ".$v['contact_addr2']."\n"
+                             ."Contact City:             ".$v['contact_city']."\n"
+                             ."Contact State/Province:   ".$v['contact_state']."\n"
+                             ."Contact ZIP/Postal Code:  ".$v['contact_zip']."\n"
+                             ."Contact Country:          ".$v['contact_country']."\n"
+                             ."Contact Phone:            ".$v['contact_phone']."\n"
+                             ."Contact FAX:              ".$v['contact_fax']."\n"
+                             ."E-Mail:           ".$v['email']."\n\n"
+                             ."Please check receint registrations to determine if this user was able to properly submit\n"
+                             ."the request. You should also check your credit card transactions to determine if there was\n"
+                             ."in fact a charge that is not associated with a successful submission.\n\n"
+                             ."Gaslight Media has also received a notice regarding this problem. Please contact us at\n"
+                             ."231-487-0692 if you have additional questions.\n\nGaslight Media",
+                         "From: Gaslight Media ".$v['word_Event']." Registration System <info@gaslightmedia.com>\n"
+                     );
+                 }
+                 $reason[]['text'] = "The system was unable to store your request but it appears your credit card has already been charged.<br>
+                 Please contact ".$v["customer_name"]
+                                 .( $cust_phone != '' ? " at ".$v["customer_phone"] : '' )
+                                 ." regarding this problem.";
             }
 
+
         }
 
         if ($config->event_registration->debug) {
@@ -3149,20 +3150,15 @@ if ($Action == "Step6") {
                 $registrant_id = $existing_registrant['id'];
             } else {
                 // Newly created registrant record
-                // Note, need to use $db so same SQL session
                 $sql = "SELECT currval('registrations.registrant_id_seq');";
-                $stmt = $db->prepare($sql);
-                $stmt->execute();
-                $new_registrant = $stmt->fetch(PDO::FETCH_ASSOC);
+                $new_registrant = db_auto_get_row($query, 0, CONN_STR, FALSE);
                 $registrant_id = $new_registrant['currval'];
             }
 
             // Save the registrant ID in the current request
             $sql = "SELECT currval('registrations.reg_req_id_seq');";
-            $stmt = $db->prepare($sql);
-            $stmt->execute();
-            $this_request = $stmt->fetch(PDO::FETCH_ASSOC);
-            reg_db_auto_exec( "UPDATE registrations.reg_req SET registrant = $registrant_id WHERE id = ".$this_request['currval'].";", 0, CONN_STR, FALSE );
+            $this_request = db_auto_get_row($query, 0, CONN_STR, FALSE);
+            reg_db_auto_exec( "UPDATE registrations.reg_req SET registrant = $registrant_id WHERE id = ".$this_request['id'].";", 0, CONN_STR, FALSE );
 
             // Provide request ID to view
             $v['reg_req_id'] = $this_request['currval'];