Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
bed5bc44
Unverified
Commit
bed5bc44
authored
Oct 09, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ability to move a folder and its content back to root
parent
f5001e8d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
2 deletions
+43
-2
MoveFolderOnDisk.php
Modules/Media/Events/Handlers/MoveFolderOnDisk.php
+6
-1
EloquentFolderRepository.php
.../Media/Repositories/Eloquent/EloquentFolderRepository.php
+6
-1
EloquentFolderRepositoryTest.php
Modules/Media/Tests/EloquentFolderRepositoryTest.php
+31
-0
No files found.
Modules/Media/Events/Handlers/MoveFolderOnDisk.php
View file @
bed5bc44
...
...
@@ -51,7 +51,7 @@ class MoveFolderOnDisk
$oldPath
=
$media
->
path
->
getRelativeUrl
();
$media
->
update
([
'path'
=>
str_replace
(
$previousPath
,
$newPath
,
$oldPath
),
'path'
=>
$this
->
removeDoubleSlashes
(
str_replace
(
$previousPath
,
$newPath
,
$oldPath
)
),
]);
if
(
$media
->
isFolder
()
===
true
)
{
$this
->
replacePathReferences
(
$media
->
id
,
$previousPath
,
$newPath
);
...
...
@@ -84,4 +84,9 @@ class MoveFolderOnDisk
{
return
config
(
'asgard.media.config.filesystem'
);
}
private
function
removeDoubleSlashes
(
string
$string
)
:
string
{
return
str_replace
(
'//'
,
'/'
,
$string
);
}
}
Modules/Media/Repositories/Eloquent/EloquentFolderRepository.php
View file @
bed5bc44
...
...
@@ -109,7 +109,12 @@ class EloquentFolderRepository extends EloquentBaseRepository implements FolderR
private
function
getNewPathFor
(
string
$filename
,
File
$folder
)
{
return
$folder
->
path
->
getRelativeUrl
()
.
'/'
.
str_slug
(
$filename
);
return
$this
->
removeDoubleSlashes
(
$folder
->
path
->
getRelativeUrl
()
.
'/'
.
str_slug
(
$filename
));
}
private
function
removeDoubleSlashes
(
string
$string
)
:
string
{
return
str_replace
(
'//'
,
'/'
,
$string
);
}
/**
...
...
Modules/Media/Tests/EloquentFolderRepositoryTest.php
View file @
bed5bc44
...
...
@@ -381,6 +381,28 @@ final class EloquentFolderRepositoryTest extends MediaTestCase
$this
->
assertEquals
(
'/assets/media/my-folder/second-folder/third-folder/my-other-file.jpg'
,
$fileTwo
->
path
->
getRelativeUrl
());
}
/** @test */
public
function
it_can_move_folder_back_to_root_folder
()
{
$parentFolder
=
$this
->
folder
->
create
([
'name'
=>
'My Folder'
,
'parent_id'
=>
0
]);
$folder
=
$this
->
folder
->
create
([
'name'
=>
'Child Folder'
,
'parent_id'
=>
$parentFolder
->
id
]);
$file
=
app
(
FileService
::
class
)
->
store
(
\Illuminate\Http\UploadedFile
::
fake
()
->
image
(
'my-file.jpg'
),
$folder
->
id
);
$this
->
assertEquals
(
'/assets/media/my-folder/child-folder'
,
$folder
->
path
->
getRelativeUrl
());
$this
->
assertEquals
(
'/assets/media/my-folder/child-folder/my-file.jpg'
,
$file
->
path
->
getRelativeUrl
());
$this
->
assertTrue
(
$this
->
app
[
'files'
]
->
isDirectory
(
public_path
(
'/assets/media/my-folder/child-folder'
)));
$this
->
assertTrue
(
$this
->
app
[
'files'
]
->
exists
(
public_path
(
'/assets/media/my-folder/child-folder/my-file.jpg'
)));
$this
->
folder
->
move
(
$folder
,
$this
->
makeRootFolder
());
$this
->
assertTrue
(
$this
->
app
[
'files'
]
->
isDirectory
(
public_path
(
'/assets/media/child-folder'
)));
$this
->
assertTrue
(
$this
->
app
[
'files'
]
->
exists
(
public_path
(
'/assets/media/child-folder/my-file.jpg'
)));
$this
->
assertEquals
(
'/assets/media/child-folder'
,
$folder
->
path
->
getRelativeUrl
());
$file
->
refresh
();
$this
->
assertEquals
(
'/assets/media/child-folder/my-file.jpg'
,
$file
->
path
->
getRelativeUrl
());
}
/** @test */
public
function
it_can_move_folder_with_folders_and_files_in_it_disk
()
{
...
...
@@ -414,4 +436,13 @@ final class EloquentFolderRepositoryTest extends MediaTestCase
'folder_id'
=>
0
,
]);
}
private
function
makeRootFolder
()
:
File
{
return
new
File
([
'id'
=>
0
,
'folder_id'
=>
0
,
'path'
=>
config
(
'asgard.media.config.files-path'
),
]);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment