Skip to content

Commit b0ad199

Browse files
committed
rename directory in s3
1 parent 95fee23 commit b0ad199

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/Controllers/FileManagerController.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ public function rename(RequestValidator $request)
184184
$this->fm->rename(
185185
$request->input('disk'),
186186
$request->input('newName'),
187-
$request->input('oldName')
187+
$request->input('oldName'),
188+
$request->input('type'),
188189
)
189190
);
190191
}

src/Events/Renamed.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function oldName()
6363
*/
6464
public function type()
6565
{
66-
$info = Storage::disk($this->disk)->getMetadata($this->oldName);
66+
$info = Storage::disk($this->disk)->getMetadata($this->newName);
6767

6868
return $info['type'];
6969
}

src/FileManager.php

+16-2
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,23 @@ public function paste($disk, $path, $clipboard)
271271
*
272272
* @return array
273273
*/
274-
public function rename($disk, $newName, $oldName)
274+
public function rename($disk, $newName, $oldName, $type)
275275
{
276-
Storage::disk($disk)->move($oldName, $newName);
276+
if ($type == "dir") {
277+
if (Storage::disk($disk)->has($oldName)) {
278+
$folderContents = Storage::disk($disk)->listContents($oldName, true);
279+
foreach ($folderContents as $content) {
280+
if ($content['type'] === 'file') {
281+
$src = $content['path'];
282+
$dest = str_replace($oldName, $newName, $src);
283+
Storage::disk($disk)->move($src, $dest);
284+
}
285+
}
286+
Storage::disk($disk)->deleteDirectory($oldName);
287+
}
288+
} else {
289+
Storage::disk($disk)->move($oldName, $newName);
290+
}
277291

278292
event(new Renamed($disk, $newName, $oldName));
279293

0 commit comments

Comments
 (0)