diff --git a/controllers/CollectionController.php b/controllers/CollectionController.php index 08efee3..af22c19 100644 --- a/controllers/CollectionController.php +++ b/controllers/CollectionController.php @@ -46,7 +46,7 @@ class CollectionController extends Controller { $searchModel = new CollectionSearch(); $dataProvider = $searchModel->search($this->request->queryParams); - + $dataProvider->query->andWhere(['!=', 'status', 0]); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, @@ -101,7 +101,18 @@ class CollectionController extends Controller */ public function actionDelete($id) { - $this->findModel($id)->delete(); + // 获取模型 + $model = $this->findModel($id); + + // 设置状态为禁用 + $model->status = 0; + + // 保存模型 + if ($model->save()) { + Yii::$app->session->setFlash('success', 'Task delete successfully.'); + } else { + Yii::$app->session->setFlash('error', 'Failed to delete task.'); + } return $this->redirect(['index']); } @@ -137,8 +148,8 @@ class CollectionController extends Controller $secret = $receive_secret; } $model = CollectionTasks::findOne(['id' => $id]); - if ($model === null) { - throw new NotFoundHttpException('请求的文件收集任务不存在'); + if ($model === null | $model->status === 0) { + throw new NotFoundHttpException('请求的文件收集任务已失效或不存在'); } elseif (!is_dir(Yii::getAlias(Yii::$app->params['dataDirectory']) . '/' . $model->user_id . '/' . $model->folder_path)) { throw new NotFoundHttpException('收集任务的目标路径不存在'); } elseif ($secret === null) { diff --git a/controllers/ShareController.php b/controllers/ShareController.php index 028494e..d696eb1 100644 --- a/controllers/ShareController.php +++ b/controllers/ShareController.php @@ -43,6 +43,7 @@ class ShareController extends Controller { $searchModel = new ShareSearch(); $dataProvider = $searchModel->search($this->request->queryParams); + $dataProvider->query->andWhere(['!=', 'status', 0]); return $this->render('index', [ 'searchModel' => $searchModel, @@ -138,7 +139,18 @@ class ShareController extends Controller */ public function actionDelete($share_id) { - $this->findModel($share_id)->delete(); + // 获取模型 + $model = $this->findModel($share_id); + + // 设置状态为禁用 + $model->status = 0; + + // 保存模型 + if ($model->save()) { + Yii::$app->session->setFlash('success', 'Share delete successfully.'); + } else { + Yii::$app->session->setFlash('error', 'Failed to delete share.'); + } return $this->redirect(['index']); } @@ -164,7 +176,7 @@ class ShareController extends Controller $model = $this->findModel($share_id); //检查文件/文件夹是否存在 $abp = Yii::getAlias(Yii::$app->params['dataDirectory']) . '/' . $model->sharer_id . '/' . $model->file_relative_path; - if (!file_exists($abp)) { + if (!file_exists($abp) || $model->status == 0) { throw new NotFoundHttpException('分享失效,文件或文件夹不存在'); } if ($this->request->isPost) { diff --git a/models/CollectionTasks.php b/models/CollectionTasks.php index bed7b5e..30afdcd 100644 --- a/models/CollectionTasks.php +++ b/models/CollectionTasks.php @@ -14,6 +14,7 @@ use yii\db\ActiveRecord; * @property string $folder_path 收集目标文件夹(相对路径) * @property string $created_at 收集任务创建时间 * @property string $secret 访问密钥 + * @property int|null $status 收集任务是否启用 * * @property CollectionUploaded[] $collectionUploadeds * @property User $user @@ -38,7 +39,7 @@ class CollectionTasks extends ActiveRecord return [ [['user_id', 'folder_path', 'secret'], 'required'], [['folder_path', 'secret'], 'required', 'on' => self::SCENARIO_CREATE], - [['user_id'], 'integer'], + [['user_id', 'status'], 'integer'], [['created_at'], 'safe'], [['folder_path', 'secret'], 'string', 'max' => 255], [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['user_id' => 'id']], @@ -56,6 +57,7 @@ class CollectionTasks extends ActiveRecord 'folder_path' => '收集目标文件夹(相对路径)', 'created_at' => '任务创建时间', 'secret' => '访问密钥', + 'status' => 'Status', ]; } diff --git a/models/Share.php b/models/Share.php index 4ef6efe..917a474 100644 --- a/models/Share.php +++ b/models/Share.php @@ -14,6 +14,7 @@ use yii\db\ActiveRecord; * @property string $file_relative_path 文件的相对路径 * @property string $access_code 分享密钥 * @property string $creation_date 分享创建日期 + * @property int|null $status 分享是否启用 * * @property User $sharer */ @@ -35,7 +36,7 @@ class Share extends ActiveRecord { return [ [['file_relative_path', 'access_code'], 'required'], - [['sharer_id'], 'integer'], + [['sharer_id', 'status'], 'integer'], [['creation_date'], 'safe'], [['file_relative_path'], 'string', 'max' => 255], [['access_code'], 'string', 'max' => 4], @@ -55,6 +56,7 @@ class Share extends ActiveRecord 'file_relative_path' => '文件位置', 'access_code' => '访问密码', 'creation_date' => '分享创建日期', + 'status' => 'Status', ]; }