rollBack() public method

Rolls back a transaction.
public rollBack ( )
 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();
         }
     }
 }
Esempio n. 3
-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();
     }
 }
Esempio n. 4
-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;
 }