From 806501fbd638447245e42c97ce3da6041cc4ab43 Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Wed, 22 Apr 2020 22:13:36 +0200 Subject: [PATCH] update card after activate --- backend/models/CustomerActivateForm.php | 31 +++++++++---------- .../models/SingleCustomerActivateForm.php | 10 ++++-- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/backend/models/CustomerActivateForm.php b/backend/models/CustomerActivateForm.php index b7a915a..c888315 100644 --- a/backend/models/CustomerActivateForm.php +++ b/backend/models/CustomerActivateForm.php @@ -33,32 +33,29 @@ class CustomerActivateForm extends Model{ * @throws \Exception */ public function activate(){ - if ( !$this->validate()){ + if (!$this->validate()) { return false; } $tx = \Yii::$app->db->beginTransaction(); assert(isset($tx)); - try{ - Yii::$app->db->createCommand(Ticket::$SQL_UPDATE_TICKETS_END_DATE_ON_CARD_ACTIVATION )->execute(); - Card::updateAll( - [ - 'status' => Card::STATUS_ACTIVE, - ], - [ - 'status' => Card::STATUS_INACTIVE - ] - ); + try { + // update ticket end dates + Yii::$app->db->createCommand(Ticket::$SQL_UPDATE_TICKETS_END_DATE_ON_CARD_ACTIVATION)->execute(); + // update card.status + Card::updateAll([ 'status' => Card::STATUS_ACTIVE, ], [ 'status' => Card::STATUS_INACTIVE ] ); + // update card.flag + Card::updateFlagStatus(); + // update ticket + \Yii::$app->db->createCommand(Ticket::$SQL_UPDATE)->execute(); - - Card::updateFlagStatus(); - $tx->commit(); - }catch (\Exception $exception){ + $tx->commit(); + } catch (\Exception $exception) { $tx->rollBack(); throw $exception; } - $this->message = $this->inactiveCardCount ." kártya aktiválva" ; - return true; + $this->message = $this->inactiveCardCount . " kártya aktiválva"; + return true; } } diff --git a/frontend/models/SingleCustomerActivateForm.php b/frontend/models/SingleCustomerActivateForm.php index e2fea27..0b623f2 100644 --- a/frontend/models/SingleCustomerActivateForm.php +++ b/frontend/models/SingleCustomerActivateForm.php @@ -6,6 +6,7 @@ namespace frontend\models; use common\models\Card; use common\models\Ticket; +use Exception; use Yii; use yii\base\Model; use yii\data\ArrayDataProvider; @@ -98,7 +99,7 @@ class SingleCustomerActivateForm extends Model{ /** * @return bool - * @throws \Exception + * @throws Exception */ public function activate() { @@ -106,7 +107,7 @@ class SingleCustomerActivateForm extends Model{ return false; } - $tx = \Yii::$app->db->beginTransaction(); + $tx = Yii::$app->db->beginTransaction(); assert(isset($tx)); try { @@ -122,8 +123,11 @@ class SingleCustomerActivateForm extends Model{ ] ); Card::updateFlagStatus(); + + Card::updateCardFlagTicket( $this->card->id_card); + $tx->commit(); - } catch (\Exception $exception) { + } catch (Exception $exception) { $tx->rollBack(); throw $exception; }