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
59e1fbb6
Unverified
Commit
59e1fbb6
authored
Oct 08, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ability to move media back on root
parent
8c60d825
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
0 deletions
+55
-0
File.php
Modules/Media/Entities/File.php
+1
-0
MoveMediaController.php
Modules/Media/Http/Controllers/Api/MoveMediaController.php
+12
-0
EloquentFileRepositoryTest.php
Modules/Media/Tests/EloquentFileRepositoryTest.php
+42
-0
No files found.
Modules/Media/Entities/File.php
View file @
59e1fbb6
...
@@ -28,6 +28,7 @@ class File extends Model implements TaggableInterface
...
@@ -28,6 +28,7 @@ class File extends Model implements TaggableInterface
protected
$table
=
'media__files'
;
protected
$table
=
'media__files'
;
public
$translatedAttributes
=
[
'description'
,
'alt_attribute'
,
'keywords'
];
public
$translatedAttributes
=
[
'description'
,
'alt_attribute'
,
'keywords'
];
protected
$fillable
=
[
protected
$fillable
=
[
'id'
,
'is_folder'
,
'is_folder'
,
'description'
,
'description'
,
'alt_attribute'
,
'alt_attribute'
,
...
...
Modules/Media/Http/Controllers/Api/MoveMediaController.php
View file @
59e1fbb6
...
@@ -4,6 +4,7 @@ namespace Modules\Media\Http\Controllers\Api;
...
@@ -4,6 +4,7 @@ namespace Modules\Media\Http\Controllers\Api;
use
Illuminate\Http\Request
;
use
Illuminate\Http\Request
;
use
Illuminate\Routing\Controller
;
use
Illuminate\Routing\Controller
;
use
Modules\Media\Entities\File
;
use
Modules\Media\Repositories\FileRepository
;
use
Modules\Media\Repositories\FileRepository
;
use
Modules\Media\Repositories\FolderRepository
;
use
Modules\Media\Repositories\FolderRepository
;
...
@@ -31,6 +32,9 @@ class MoveMediaController extends Controller
...
@@ -31,6 +32,9 @@ class MoveMediaController extends Controller
if
(
$file
->
is_folder
===
false
)
{
if
(
$file
->
is_folder
===
false
)
{
$destination
=
$this
->
folder
->
findFolder
(
$request
->
get
(
'destinationFolder'
));
$destination
=
$this
->
folder
->
findFolder
(
$request
->
get
(
'destinationFolder'
));
if
(
$destination
===
null
)
{
$destination
=
$this
->
makeRootFolder
();
}
$this
->
file
->
move
(
$file
,
$destination
);
$this
->
file
->
move
(
$file
,
$destination
);
}
}
...
@@ -41,4 +45,12 @@ class MoveMediaController extends Controller
...
@@ -41,4 +45,12 @@ class MoveMediaController extends Controller
'message'
=>
'Files moved successfully'
,
'message'
=>
'Files moved successfully'
,
]);
]);
}
}
private
function
makeRootFolder
()
:
File
{
return
new
File
([
'id'
=>
0
,
'folder_id'
=>
0
,
]);
}
}
}
Modules/Media/Tests/EloquentFileRepositoryTest.php
View file @
59e1fbb6
...
@@ -309,6 +309,40 @@ class EloquentFileRepositoryTest extends MediaTestCase
...
@@ -309,6 +309,40 @@ class EloquentFileRepositoryTest extends MediaTestCase
$this
->
assertTrue
(
$this
->
app
[
'files'
]
->
exists
(
public_path
(
'/assets/media/my-folder/child-folder/my-file_mediumThumb.jpg'
)));
$this
->
assertTrue
(
$this
->
app
[
'files'
]
->
exists
(
public_path
(
'/assets/media/my-folder/child-folder/my-file_mediumThumb.jpg'
)));
}
}
/** @test */
public
function
it_can_move_file_back_to_root_folder
()
{
$folderRepository
=
app
(
FolderRepository
::
class
);
$parentFolder
=
$folderRepository
->
create
([
'name'
=>
'My Folder'
,
'parent_id'
=>
0
]);
$folder
=
$folderRepository
->
create
([
'name'
=>
'Child Folder'
,
'parent_id'
=>
$parentFolder
->
id
]);
$file
=
\Illuminate\Http\UploadedFile
::
fake
()
->
create
(
'my-file.pdf'
);
$file
=
app
(
FileService
::
class
)
->
store
(
$file
,
$folder
->
id
);
$this
->
assertTrue
(
$this
->
app
[
'files'
]
->
exists
(
public_path
(
'/assets/media/my-folder/child-folder/my-file.pdf'
)));
$this
->
file
->
move
(
$file
,
$this
->
makeRootFolder
());
$this
->
assertTrue
(
$this
->
app
[
'files'
]
->
exists
(
public_path
(
'/assets/media/my-file.pdf'
)));
}
/** @test */
public
function
it_can_move_file_with_thumbnails_back_to_root_folder
()
{
$folderRepository
=
app
(
FolderRepository
::
class
);
$parentFolder
=
$folderRepository
->
create
([
'name'
=>
'My Folder'
,
'parent_id'
=>
0
]);
$folder
=
$folderRepository
->
create
([
'name'
=>
'Child Folder'
,
'parent_id'
=>
$parentFolder
->
id
]);
$file
=
\Illuminate\Http\UploadedFile
::
fake
()
->
image
(
'my-file.jpg'
);
$file
=
app
(
FileService
::
class
)
->
store
(
$file
,
$folder
->
id
);
$this
->
assertTrue
(
$this
->
app
[
'files'
]
->
exists
(
public_path
(
'/assets/media/my-folder/child-folder/my-file.jpg'
)));
$this
->
file
->
move
(
$file
,
$this
->
makeRootFolder
());
$this
->
assertTrue
(
$this
->
app
[
'files'
]
->
exists
(
public_path
(
'/assets/media/my-file.jpg'
)));
$this
->
assertTrue
(
$this
->
app
[
'files'
]
->
exists
(
public_path
(
'/assets/media/my-file_smallThumb.jpg'
)));
$this
->
assertTrue
(
$this
->
app
[
'files'
]
->
exists
(
public_path
(
'/assets/media/my-file_mediumThumb.jpg'
)));
}
private
function
createFile
(
$fileName
=
'random/name.jpg'
)
private
function
createFile
(
$fileName
=
'random/name.jpg'
)
{
{
return
File
::
create
([
return
File
::
create
([
...
@@ -320,4 +354,12 @@ class EloquentFileRepositoryTest extends MediaTestCase
...
@@ -320,4 +354,12 @@ class EloquentFileRepositoryTest extends MediaTestCase
'folder_id'
=>
0
,
'folder_id'
=>
0
,
]);
]);
}
}
private
function
makeRootFolder
()
:
File
{
return
new
File
([
'id'
=>
0
,
'folder_id'
=>
0
,
]);
}
}
}
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