public static function setStatusCompleted(UploadEvent $event) { $transaction = Yii::$app->getDb()->beginTransaction(); try { $record = self::getRecord($event->record->id); if ($record->status_id == Status::COMPLETE) { throw new \Exception('Record has same status'); } $record->setAttributes(['status_id' => Status::COMPLETE]); if (!$record->save(true, ['status_id'])) { throw new \Exception('Record status do not updated'); } $history = new StatusHistory(); $history->setAttributes(['record_id' => $record->id, 'author_id' => $event->user_id, 'status_code' => Status::COMPLETE, 'created_at' => time()]); if (!$history->save()) { throw new \Exception('StatusHistory do not created'); } $transaction->commit(); return true; } catch (\Exception $e) { $transaction->rollBack(); return false; } }