mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-05 18:23:48 +00:00
fixed moving issue when user move folder with files into team folder
This commit is contained in:
@@ -1,24 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Domain\Items\Actions;
|
||||
|
||||
use Gate;
|
||||
use Domain\Teams\Actions\SetTeamFolderPropertyForAllChildrenAction;
|
||||
use Domain\Folders\Models\Folder;
|
||||
use Domain\Sharing\Models\Share;
|
||||
use Gate;
|
||||
|
||||
class MoveFileOrFolderAction
|
||||
{
|
||||
public function __construct(
|
||||
public SetTeamFolderPropertyForAllChildrenAction $setTeamFolderPropertyForAllChildren,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Move folder or file to new location
|
||||
*/
|
||||
public function __invoke($request, ?Share $share = null): void
|
||||
{
|
||||
foreach ($request->input('items') as $item) {
|
||||
$item = get_item($item['type'], $item['id']);
|
||||
|
||||
Gate::authorize('can-edit', [$item, $share]);
|
||||
$entry = get_item($item['type'], $item['id']);
|
||||
|
||||
$item->update([
|
||||
'parent_id' => $request->input('to_id'),
|
||||
]);
|
||||
// Check permission
|
||||
Gate::authorize('can-edit', [$entry, $share]);
|
||||
|
||||
// Process folder
|
||||
if ($item['type'] === 'folder') {
|
||||
|
||||
// Determine, if we are moving folder into the team folder or not
|
||||
$isTeamFolder = is_null($request->input('to_id'))
|
||||
? false
|
||||
: Folder::find($request->input('to_id'))->getLatestParent()->team_folder;
|
||||
|
||||
// Change team_folder mark for all children folders
|
||||
($this->setTeamFolderPropertyForAllChildren)($entry, $isTeamFolder);
|
||||
|
||||
// Update folder
|
||||
$entry->update([
|
||||
'parent_id' => $request->input('to_id'),
|
||||
'team_folder' => $isTeamFolder,
|
||||
]);
|
||||
}
|
||||
|
||||
// Process file
|
||||
if ($item['type'] !== 'folder') {
|
||||
// Update file
|
||||
$entry->update([
|
||||
'parent_id' => $request->input('to_id'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user