文件收集任务 日志记录 后端

This commit is contained in:
Chenx221 2024-04-06 13:53:17 +08:00
parent 6d72678b34
commit 96d718624e
Signed by: chenx221
GPG Key ID: D7A9EC07024C3021
2 changed files with 20 additions and 2 deletions

View File

@ -239,10 +239,12 @@ class CollectionController extends Controller
// 创建一个新的CollectionUploaded模型实例并设置其属性值 // 创建一个新的CollectionUploaded模型实例并设置其属性值
$model = new CollectionUploaded(); $model = new CollectionUploaded();
$model->user_id = Yii::$app->user->id;
$model->task_id = $taskId; $model->task_id = $taskId;
$model->uploader_ip = $uploaderIp; $model->uploader_ip = $uploaderIp;
$model->uploaded_at = date('Y-m-d H:i:s'); // 设置上传时间为当前时间 $model->uploaded_at = date('Y-m-d H:i:s'); // 设置上传时间为当前时间
$model->subfolder_name = $subfolderName; $model->subfolder_name = $subfolderName;
$model->user_agent = $request->userAgent;
if ($model->validate()) { if ($model->validate()) {
// 进行文件上传 // 进行文件上传
$targetDirectory = Yii::getAlias(Yii::$app->params['dataDirectory']) . '/' . $userId . '/' . $folderPath . '/' . $subfolderName; $targetDirectory = Yii::getAlias(Yii::$app->params['dataDirectory']) . '/' . $userId . '/' . $folderPath . '/' . $subfolderName;

View File

@ -9,12 +9,15 @@ use yii\db\ActiveRecord;
* This is the model class for table "collection_uploaded". * This is the model class for table "collection_uploaded".
* *
* @property int $id 文件收集的上传记录id * @property int $id 文件收集的上传记录id
* @property int|null $user_id 用户ID
* @property int $task_id 对应的文件收集id * @property int $task_id 对应的文件收集id
* @property string $uploader_ip 上传者ip * @property string $uploader_ip 上传者ip
* @property string $uploaded_at 上传时间 * @property string $uploaded_at 上传时间
* @property string $subfolder_name 对应的子文件夹名 * @property string $subfolder_name 对应的子文件夹名
* @property string $user_agent 浏览器UA信息
* *
* @property CollectionTasks $task * @property CollectionTasks $task
* @property User $user
*/ */
class CollectionUploaded extends ActiveRecord class CollectionUploaded extends ActiveRecord
{ {
@ -32,12 +35,13 @@ class CollectionUploaded extends ActiveRecord
public function rules(): array public function rules(): array
{ {
return [ return [
[['task_id', 'uploader_ip', 'subfolder_name'], 'required'], [['task_id', 'uploader_ip', 'subfolder_name', 'user_agent'], 'required'],
[['task_id'], 'integer'], [['user_id', 'task_id'], 'integer'],
[['uploaded_at'], 'safe'], [['uploaded_at'], 'safe'],
[['uploader_ip'], 'string', 'max' => 45], [['uploader_ip'], 'string', 'max' => 45],
[['subfolder_name'], 'string', 'max' => 255], [['subfolder_name'], 'string', 'max' => 255],
[['task_id'], 'exist', 'skipOnError' => true, 'targetClass' => CollectionTasks::class, 'targetAttribute' => ['task_id' => 'id']], [['task_id'], 'exist', 'skipOnError' => true, 'targetClass' => CollectionTasks::class, 'targetAttribute' => ['task_id' => 'id']],
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['user_id' => 'id']],
]; ];
} }
@ -48,10 +52,12 @@ class CollectionUploaded extends ActiveRecord
{ {
return [ return [
'id' => '上传记录id', 'id' => '上传记录id',
'user_id' => '用户ID',
'task_id' => '收集任务id', 'task_id' => '收集任务id',
'uploader_ip' => '上传者ip', 'uploader_ip' => '上传者ip',
'uploaded_at' => '上传时间', 'uploaded_at' => '上传时间',
'subfolder_name' => '所在位置', 'subfolder_name' => '所在位置',
'user_agent' => '浏览器UA信息',
]; ];
} }
@ -64,4 +70,14 @@ class CollectionUploaded extends ActiveRecord
{ {
return $this->hasOne(CollectionTasks::class, ['id' => 'task_id']); return $this->hasOne(CollectionTasks::class, ['id' => 'task_id']);
} }
/**
* Gets query for [[User]].
*
* @return \yii\db\ActiveQuery
*/
public function getUser()
{
return $this->hasOne(User::class, ['id' => 'user_id']);
}
} }