Uploaded image for project: 'Blesta Core'
  1. Blesta Core
  2. CORE-4722

Remove unnecessary database transaction from Transactions::applyFromCredits()

    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

          People

          • Assignee:
            abdy Abdy Franco
            Reporter:
            jonathan Jonathan Reissmueller
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Fix Release Date:
              8/Aug/22

              Time Tracking

              Estimated:
              Original Estimate - Not Specified
              Not Specified
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 58 minutes
              58m

                Agile