|
@@ -2,8 +2,10 @@
|
|
|
|
|
|
namespace App\Services\Folder;
|
|
|
|
|
|
+use App\Models\File;
|
|
|
use App\Models\Folder;
|
|
|
use App\Models\NamingRule;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
class FoldersService
|
|
|
{
|
|
@@ -11,9 +13,16 @@ class FoldersService
|
|
|
{
|
|
|
$folder = Folder::query()->findOrFail($id);
|
|
|
$namingRule = NamingRule::query()->findOrFail($namingRuleId);
|
|
|
- // 子孙文件夹均需更新
|
|
|
- Folder::query()
|
|
|
- ->where('path', 'like', $folder->path . '%')
|
|
|
- ->update(['naming_rule_id' => $namingRule->id]);
|
|
|
+ // 子孙均需更新
|
|
|
+ DB::transaction(function () use ($folder, $namingRule) {
|
|
|
+ Folder::query()
|
|
|
+ ->where('path', 'like', $folder->path . '%')
|
|
|
+ ->update(['naming_rule_id' => $namingRule->id]);
|
|
|
+
|
|
|
+ File::query()
|
|
|
+ ->join('folders', 'files.folder_id', '=', 'folders.id')
|
|
|
+ ->where('folders.path', 'like', $folder->path . '%')
|
|
|
+ ->update(['files.naming_rule_id' => $namingRule->id]);
|
|
|
+ });
|
|
|
}
|
|
|
}
|