/** * Finds the SourceRatio model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return SourceRatio the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = SourceRatio::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Deletes an existing Source model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { #$this->findModel($id)->delete(); $model = $this->findModel($id); $model->status = $model::STATUS_DELETED; #$ret = $model->delete(); $ret = $model->save(); if ($ret) { #update basic $basicModel = Basic::findOne($model->basic_id); if (!$basicModel) { throw new NotFoundHttpException('The requested page does not exist.'); } $basicModel->source_num = $basicModel->source_num - 1; $basicRet = $basicModel->save(); #update sourceTemp $sourceTempModel = SourceTemp::findOne($model->source_temp_id); if ($sourceTempModel) { $sourceTempModel->basic_id = 0; $tempRet = $sourceTempModel->save(); #update source ratio $sourceRatioModel = SourceRatio::findOne(['source_id' => $model->source_temp_id]); if ($sourceRatioModel) { $sourceRatioModel->status = SourceRatio::STATUS_NO_MATCHED; $sourceRatioModel->save(); } } return $this->redirect(['source/index', 'basic_id' => $model->basic_id]); } else { throw new ServerErrorHttpException('Delete Error'); } }