db->beginTransaction(); $device = MobileDevice::findOne(['id' => $this->id_device]); if ($device === null) { throw new NotFoundHttpException(); } $card = Card::findOne(['id_card' => $device->id_card]); if ($card === null) { throw new NotFoundHttpException(); } \Yii::info("MobileStatusForm: changing status from $device->status to $this->status"); $origStatus = $device->status; $device->status = $this->status; if ( $this->status === MobileDevice::STATUS_ACTIVE ){ // only one card can be active at the same time MobileDevice::updateAll([ 'activated_at' => null, 'status' => MobileDevice::STATUS_DELETED_SYSTEM ], [ 'id_card' => $device->id_card ] ); } if ($this->status === MobileDevice::STATUS_ACTIVE) { if (!isset($device->activated_at)) { $device->activated_at = Helper::getDateTimeString(); } } else { $device->activated_at = null; } $device->save(false); $customer = Customer::find()->andWhere(['id_customer_card' => $device->id_card])->one(); Log::log([ 'type' => Log::$TYPE_MOBILE_DEVICE_STATUS, 'message' => "Eszkösz $device->id; Kártya: $card->number; előző státusz: $origStatus; új státusz: $this->status", 'id_customer' => $customer->id_customer ]); $tx->commit(); }catch ( \Exception $e){ \Yii::error("Failed to save status for device $this->id_device :".$e->getMessage()); if ( $tx != null ){ $tx->rollBack(); } throw $e; } } }