no message

This commit is contained in:
kuaifan 2022-06-12 20:41:45 +08:00
parent 324d7ea487
commit 6759e2b30c
5 changed files with 18 additions and 22 deletions

View File

@ -257,7 +257,7 @@ class FileController extends AbstractController
'userid' => $userid,
'created_id' => $user->userid,
]);
$file->checkName();
$file->handleDuplicateName();
$file->saveBeforePids();
//
$data = File::find($file->id);
@ -308,7 +308,7 @@ class FileController extends AbstractController
'userid' => $userid,
'created_id' => $user->userid,
]);
$file->checkName();
$file->handleDuplicateName();
$data = AbstractModel::transaction(function() use ($file) {
$content = FileContent::select(['content', 'text', 'size'])->whereFid($file->cid)->orderByDesc('id')->first();
$file->size = $content?->size ?: 0;
@ -385,7 +385,7 @@ class FileController extends AbstractController
}
//
$file->pid = $pid;
$file->checkName();
$file->handleDuplicateName();
$file->saveBeforePids();
$files[] = $file;
}
@ -695,7 +695,7 @@ class FileController extends AbstractController
'userid' => $userid,
'created_id' => $user->userid,
]);
$dirRow->checkName();
$dirRow->handleDuplicateName();
if ($dirRow->saveBeforePids()) {
$addItem[] = File::find($dirRow->id);
}
@ -762,7 +762,7 @@ class FileController extends AbstractController
'userid' => $userid,
'created_id' => $user->userid,
]);
$file->checkName();
$file->handleDuplicateName();
// 开始创建
return AbstractModel::transaction(function () use ($addItem, $webkitRelativePath, $type, $user, $data, $file) {
$file->size = $data['size'] * 1024;

View File

@ -198,32 +198,28 @@ class File extends AbstractModel
}
/**
* 检查文件名
* @param boolean $rename 重复是否自动重命名
* @return bool
* 处理重名
* @return void
*/
public function checkName($rename = true)
public function handleDuplicateName()
{
$exist = self::wherePid($this->pid)->whereUserid($this->userid)->whereName($this->name)->exists();
$builder = self::wherePid($this->pid)->whereUserid($this->userid)->whereExt($this->ext);
$exist = $builder->clone()->whereName($this->name)->exists();
if (!$exist) {
return true; // 未重名
return; // 未重名,不需要处理
}
if (!$rename) {
return false; // 重名不需要自动重命名
}
// 自动重命名
// 发现重名,自动重命名
$nextNum = 2;
if (preg_match("/(.*?)(\s+\(\d+\))*$/", $this->name)) {
$preName = preg_replace("/(.*?)(\s+\(\d+\))*$/", "$1", $this->name);
$nextNum = self::wherePid($this->pid)->whereUserid($this->userid)->where("name", "LIKE", "{$preName}%")->count() + 1;
$nextNum = $builder->clone()->where("name", "LIKE", "{$preName}%")->count() + 1;
}
$newName = "{$this->name} ({$nextNum})";
if (self::wherePid($this->pid)->whereUserid($this->userid)->whereName($newName)->exists()) {
if ($builder->clone()->whereName($newName)->exists()) {
$nextNum = rand(100, 9999);
$newName = "{$this->name} ({$nextNum})";
}
$this->name = $newName;
return true;
}
/**
@ -504,7 +500,7 @@ class File extends AbstractModel
'userid' => $newUserid,
'created_id' => 0,
]);
$file->checkName();
$file->handleDuplicateName();
$file->saveBeforePids();
// 移交文件

View File

@ -1,6 +1,6 @@
{
"name": "DooTask",
"version": "0.17.5",
"version": "0.17.7",
"description": "DooTask is task management system.",
"scripts": {
"start": "./cmd dev",

View File

@ -1 +1 @@
70305cdb15a321af
c07ad9fe85dfaae9

@ -1 +1 @@
Subproject commit 7af75419e19bc0f96923896326ffa05f9deff282
Subproject commit 72acf02c1d4cca30fae4d736d7f7bb3db1c515b8