commit() public method

Commits a transaction.
public commit ( )
示例#1
0
 /**
  * Commits a DB transaction if valid
  *
  * @param null|Transaction $transaction
  */
 protected static function tranCommit($transaction)
 {
     if ($transaction && $transaction instanceof Transaction) {
         $transaction->commit();
     }
 }
 protected function endTransaction($result)
 {
     if ($this->transaction) {
         if ($result) {
             $this->transaction->commit();
         } else {
             $this->transaction->rollBack();
         }
     }
 }
 public function afterTransaction()
 {
     if ($this->hasErrors()) {
         if ($this->ownerAddErrors) {
             foreach ($this->relations as $relation) {
                 if ($this->errors[$relation]) {
                     $this->owner->addErrors($this->errors[$relation]);
                 }
             }
         } else {
             $this->owner->addError('ALL', 'error');
             // что бы работал owner->hasErrors
         }
     }
     if ($this->transaction !== null) {
         if ($this->hasErrors()) {
             $this->transaction->rollBack();
         } else {
             $this->transaction->commit();
         }
     }
 }
示例#4
-1
 /**
  * @param \netis\crud\db\ActiveRecord $model
  * @param null|yii\db\Transaction $transaction
  */
 protected function afterExecute($model, $transaction)
 {
     if ($model->getBehavior('trackable') !== null) {
         $model->endChangeset();
     }
     if ($transaction !== null) {
         $transaction->commit();
     }
 }
示例#5
-1
 protected static function withdrawSuccessful(Invoice $invoice, Transaction $transaction)
 {
     $invoice->status = 'success';
     $invoice->user->account -= abs($invoice->amount);
     if ($invoice->user->save() && $invoice->save()) {
         $transaction->commit();
         Yii::$app->session->setFlash('success', Yii::t('app', 'Payment #{id} completed', ['id' => $invoice->id]));
     } else {
         Yii::$app->session->setFlash('error', json_encode(array_merge($invoice->user->errors, $invoice->errors), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
     }
 }
示例#6
-1
 /**
  * @inheritdoc
  */
 protected final function runInternal()
 {
     if ($this->beforeCrudActionRun()) {
         if ($this->multiple && !empty($this->model)) {
             $this->transaction = $this->model[0]->getDb()->beginTransaction();
         }
         try {
             if (isset($this->modelAction)) {
                 Yii::info('Model method to be executed: ' . $this->modelAction, __METHOD__);
                 $this->runCrudAction($this->model);
             }
             if ($this->multiple && !empty($this->model)) {
                 $this->transaction->commit();
             }
             $this->result = true;
         } catch (\Exception $e) {
             if ($this->multiple && !empty($this->model)) {
                 $this->transaction->rollBack();
             }
             $this->result = false;
             Yii::error(VarDumper::dumpAsString($e), __METHOD__);
         }
         $this->afterCrudActionRun();
     }
 }
示例#7
-1
 public function open(Transaction $transaction)
 {
     try {
         $sum = (int) Node::find()->where(['user_name' => $this->user_name])->count();
         $sum += (int) Income::find()->where(['user_name' => $this->user_name])->count();
         if ($this->invest()) {
             do {
                 $i = $this->rise();
             } while ($i > 0);
             if (0 == $sum && $this->user->canChargeBonus()) {
                 $referral = $this->user->referral;
                 $referral->account += $this->type->bonus;
                 $referral->update(true, ['account']);
                 if (4 == $this->type->id) {
                     $count = $referral->getSponsors()->select('user_name')->joinWith('nodes')->groupBy('user_name')->count();
                     if ($count > 0 && 0 == $count % 10) {
                         $gift = new Gift(['user_name' => $referral->name]);
                         $gift->save();
                         Yii::$app->session->setFlash('success', Yii::t('app', 'Your referral may receive a gift'));
                     }
                 }
             }
             $transaction->commit();
             Yii::$app->session->setFlash('success', Yii::t('app', 'The plan is open'));
             return true;
         } else {
             Yii::$app->session->setFlash('error', $this->dump());
         }
     } catch (\Exception $ex) {
         $transaction->rollBack();
         Yii::$app->session->setFlash('error', $ex->getMessage());
     }
     return false;
 }
示例#8
-1
 public function commit(Transaction $transaction)
 {
     $transaction->commit();
 }