Details
- 
        Type:
 Improvement
            
         - 
        Status: Closed
 - 
            Priority:
 Major
                
             - 
            Resolution: Fixed
 - 
            Affects Version/s: None
 - 
            Fix Version/s: 5.5.0
 - 
            Component/s: None
 - 
            Labels:None
 
Description
Database transactions are not nestable (mostly) and thus should be avoided when possible. We can remove one from Transactions::applyFromCredits() by using Transactions::unapply()
Change app/models/transactions.php around line 875 from
        // Begin a transaction
        $this->begin();
        // Apply all credits
        foreach ($apply_amounts as $transaction_id => $trans_amounts) {
            $this->apply($transaction_id, ['amounts' => $trans_amounts]);
            if (($errors = $this->errors())) {
                // Roll back
                $this->rollBack();
                return;
            }
        }
        // Commit transaction
        $this->commit();
To
// Apply all credits $last_transaction_id = null; $errors = null; foreach ($apply_amounts as $transaction_id => $trans_amounts) { $this->apply($transaction_id, ['amounts' => $trans_amounts]); if (($errors = $this->errors())) { break; } $last_transaction_id = $transaction_id; } if ($errors && $last_transaction_id) { foreach ($apply_amounts as $transaction_id => $trans_amounts) { $invoice_ids = array_map(function ($value) { return $value['invoice_id']; }, $trans_amounts); $this->unapply($transaction_id, $invoice_ids); if ($last_transaction_id == $transaction_id) { break; } } }
Activity
| Field | Original Value | New Value | 
|---|---|---|
| Rank | Ranked higher | 
| Description | 
                                                                Database transactions are not nestable in MinPHP and thus should be avoided when possible.  We can remove one from Transactions::applyFromCredits() by using Transactions::unapply()
 Change {code:java} // Begin a transaction $this->begin(); // Apply all credits foreach ($apply_amounts as $transaction_id => $trans_amounts) { $this->apply($transaction_id, ['amounts' => $trans_amounts]); if (($errors = $this->errors())) { // Roll back $this->rollBack(); return; } } // Commit transaction $this->commit(); {code} To {code:java} // Apply all credits $last_transaction_id = null; $errors = null; foreach ($apply_amounts as $transaction_id => $trans_amounts) { $this->apply($transaction_id, ['amounts' => $trans_amounts]); if (($errors = $this->errors())) { break; } $last_transaction_id = $transaction_id; } if ($errors && $last_transaction_id) { foreach ($apply_amounts as $transaction_id => $trans_amounts) { $invoice_ids = array_map(function ($value) { return $value['invoice_id']; }, $trans_amounts); $this->unapply($transaction_id, $invoice_ids); if ($last_transaction_id == $transaction_id) { break; } } } {code}  | 
                
                                                               Database transactions are not nestable in MinPHP and thus should be avoided when possible.  We can remove one from Transactions::applyFromCredits() by using Transactions::unapply() Change app/models/transactions.php around line {code:java} // Begin a transaction $this->begin(); // Apply all credits foreach ($apply_amounts as $transaction_id => $trans_amounts) { $this->apply($transaction_id, ['amounts' => $trans_amounts]); if (($errors = $this->errors())) { // Roll back $this->rollBack(); return; } } // Commit transaction $this->commit(); {code} To {code:java} // Apply all credits $last_transaction_id = null; $errors = null; foreach ($apply_amounts as $transaction_id => $trans_amounts) { $this->apply($transaction_id, ['amounts' => $trans_amounts]); if (($errors = $this->errors())) { break; } $last_transaction_id = $transaction_id; } if ($errors && $last_transaction_id) { foreach ($apply_amounts as $transaction_id => $trans_amounts) { $invoice_ids = array_map(function ($value) { return $value['invoice_id']; }, $trans_amounts); $this->unapply($transaction_id, $invoice_ids); if ($last_transaction_id == $transaction_id) { break; } } } {code}  | 
                
| Description | 
                                                                Database transactions are not nestable in MinPHP and thus should be avoided when possible.  We can remove one from Transactions::applyFromCredits() by using Transactions::unapply() Change app/models/transactions.php around line {code:java} // Begin a transaction $this->begin(); // Apply all credits foreach ($apply_amounts as $transaction_id => $trans_amounts) { $this->apply($transaction_id, ['amounts' => $trans_amounts]); if (($errors = $this->errors())) { // Roll back $this->rollBack(); return; } } // Commit transaction $this->commit(); {code} To {code:java} // Apply all credits $last_transaction_id = null; $errors = null; foreach ($apply_amounts as $transaction_id => $trans_amounts) { $this->apply($transaction_id, ['amounts' => $trans_amounts]); if (($errors = $this->errors())) { break; } $last_transaction_id = $transaction_id; } if ($errors && $last_transaction_id) { foreach ($apply_amounts as $transaction_id => $trans_amounts) { $invoice_ids = array_map(function ($value) { return $value['invoice_id']; }, $trans_amounts); $this->unapply($transaction_id, $invoice_ids); if ($last_transaction_id == $transaction_id) { break; } } } {code}  | 
                
                                                               Database transactions are not nestable in MinPHP and thus should be avoided when possible.  We can remove one from Transactions::applyFromCredits() by using Transactions::unapply() Change app/models/transactions.php around line 875 from {code:java} // Begin a transaction $this->begin(); // Apply all credits foreach ($apply_amounts as $transaction_id => $trans_amounts) { $this->apply($transaction_id, ['amounts' => $trans_amounts]); if (($errors = $this->errors())) { // Roll back $this->rollBack(); return; } } // Commit transaction $this->commit(); {code} To {code:java} // Apply all credits $last_transaction_id = null; $errors = null; foreach ($apply_amounts as $transaction_id => $trans_amounts) { $this->apply($transaction_id, ['amounts' => $trans_amounts]); if (($errors = $this->errors())) { break; } $last_transaction_id = $transaction_id; } if ($errors && $last_transaction_id) { foreach ($apply_amounts as $transaction_id => $trans_amounts) { $invoice_ids = array_map(function ($value) { return $value['invoice_id']; }, $trans_amounts); $this->unapply($transaction_id, $invoice_ids); if ($last_transaction_id == $transaction_id) { break; } } } {code}  | 
                
| Story Points | 2 | 
| Sprint | 5.5.0-b2 Sprint 1 [ 163 ] | 
| Rank | Ranked higher | 
| Fix Version/s | 5.5.0-b2 [ 11733 ] | |
| Fix Version/s | 5.6.0-b1 [ 11730 ] | 
| Description | 
                                                                Database transactions are not nestable in MinPHP and thus should be avoided when possible.  We can remove one from Transactions::applyFromCredits() by using Transactions::unapply() Change app/models/transactions.php around line 875 from {code:java} // Begin a transaction $this->begin(); // Apply all credits foreach ($apply_amounts as $transaction_id => $trans_amounts) { $this->apply($transaction_id, ['amounts' => $trans_amounts]); if (($errors = $this->errors())) { // Roll back $this->rollBack(); return; } } // Commit transaction $this->commit(); {code} To {code:java} // Apply all credits $last_transaction_id = null; $errors = null; foreach ($apply_amounts as $transaction_id => $trans_amounts) { $this->apply($transaction_id, ['amounts' => $trans_amounts]); if (($errors = $this->errors())) { break; } $last_transaction_id = $transaction_id; } if ($errors && $last_transaction_id) { foreach ($apply_amounts as $transaction_id => $trans_amounts) { $invoice_ids = array_map(function ($value) { return $value['invoice_id']; }, $trans_amounts); $this->unapply($transaction_id, $invoice_ids); if ($last_transaction_id == $transaction_id) { break; } } } {code}  | 
                
                                                               Database transactions are not nestable and thus should be avoided when possible.  We can remove one from Transactions::applyFromCredits() by using Transactions::unapply() Change app/models/transactions.php around line 875 from {code:java} // Begin a transaction $this->begin(); // Apply all credits foreach ($apply_amounts as $transaction_id => $trans_amounts) { $this->apply($transaction_id, ['amounts' => $trans_amounts]); if (($errors = $this->errors())) { // Roll back $this->rollBack(); return; } } // Commit transaction $this->commit(); {code} To {code:java} // Apply all credits $last_transaction_id = null; $errors = null; foreach ($apply_amounts as $transaction_id => $trans_amounts) { $this->apply($transaction_id, ['amounts' => $trans_amounts]); if (($errors = $this->errors())) { break; } $last_transaction_id = $transaction_id; } if ($errors && $last_transaction_id) { foreach ($apply_amounts as $transaction_id => $trans_amounts) { $invoice_ids = array_map(function ($value) { return $value['invoice_id']; }, $trans_amounts); $this->unapply($transaction_id, $invoice_ids); if ($last_transaction_id == $transaction_id) { break; } } } {code}  | 
                
| Description | 
                                                                Database transactions are not nestable and thus should be avoided when possible.  We can remove one from Transactions::applyFromCredits() by using Transactions::unapply() Change app/models/transactions.php around line 875 from {code:java} // Begin a transaction $this->begin(); // Apply all credits foreach ($apply_amounts as $transaction_id => $trans_amounts) { $this->apply($transaction_id, ['amounts' => $trans_amounts]); if (($errors = $this->errors())) { // Roll back $this->rollBack(); return; } } // Commit transaction $this->commit(); {code} To {code:java} // Apply all credits $last_transaction_id = null; $errors = null; foreach ($apply_amounts as $transaction_id => $trans_amounts) { $this->apply($transaction_id, ['amounts' => $trans_amounts]); if (($errors = $this->errors())) { break; } $last_transaction_id = $transaction_id; } if ($errors && $last_transaction_id) { foreach ($apply_amounts as $transaction_id => $trans_amounts) { $invoice_ids = array_map(function ($value) { return $value['invoice_id']; }, $trans_amounts); $this->unapply($transaction_id, $invoice_ids); if ($last_transaction_id == $transaction_id) { break; } } } {code}  | 
                
                                                               Database transactions are not nestable (mostly) and thus should be avoided when possible.  We can remove one from Transactions::applyFromCredits() by using Transactions::unapply() Change app/models/transactions.php around line 875 from {code:java} // Begin a transaction $this->begin(); // Apply all credits foreach ($apply_amounts as $transaction_id => $trans_amounts) { $this->apply($transaction_id, ['amounts' => $trans_amounts]); if (($errors = $this->errors())) { // Roll back $this->rollBack(); return; } } // Commit transaction $this->commit(); {code} To {code:java} // Apply all credits $last_transaction_id = null; $errors = null; foreach ($apply_amounts as $transaction_id => $trans_amounts) { $this->apply($transaction_id, ['amounts' => $trans_amounts]); if (($errors = $this->errors())) { break; } $last_transaction_id = $transaction_id; } if ($errors && $last_transaction_id) { foreach ($apply_amounts as $transaction_id => $trans_amounts) { $invoice_ids = array_map(function ($value) { return $value['invoice_id']; }, $trans_amounts); $this->unapply($transaction_id, $invoice_ids); if ($last_transaction_id == $transaction_id) { break; } } } {code}  | 
                
| Assignee | Abdy Franco [ abdy ] | 
| Status | Open [ 1 ] | In Progress [ 3 ] | 
| Sprint | 5.5.0-b2 Sprint 1 [ 163 ] | 5.5.0 Sprint 1 [ 164 ] | 
| Rank | Ranked higher | 
| Fix Version/s | 5.5.0 [ 11734 ] | |
| Fix Version/s | 5.5.0-b2 [ 11733 ] | 
| Remaining Estimate | 0 minutes [ 0 ] | |
| Time Spent | 58 minutes [ 3480 ] | |
| Worklog Id | 15862 [ 15862 ] | 
| Status | In Progress [ 3 ] | In Review [ 5 ] | 
| Resolution | Fixed [ 1 ] | 
| Status | In Review [ 5 ] | Closed [ 6 ] |