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
62625d47
Unverified
Commit
62625d47
authored
Sep 22, 2017
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding logic to create files and thumbnails inside sub folder
parent
33e68a1c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
3 deletions
+47
-3
Imagy.php
Modules/Media/Image/Imagy.php
+17
-1
FileService.php
Modules/Media/Services/FileService.php
+3
-2
FileServiceTest.php
Modules/Media/Tests/FileServiceTest.php
+27
-0
No files found.
Modules/Media/Image/Imagy.php
View file @
62625d47
...
...
@@ -110,10 +110,13 @@ class Imagy
foreach
(
$this
->
manager
->
all
()
as
$thumbnail
)
{
$image
=
$this
->
image
->
make
(
$this
->
filesystem
->
disk
(
$this
->
getConfiguredFilesystem
())
->
get
(
$this
->
getDestinationPath
(
$path
->
getRelativeUrl
())));
$filename
=
config
(
'asgard.media.config.files-path'
)
.
$this
->
newFilename
(
$path
,
$thumbnail
->
name
());
$filename
=
$this
->
getFilenameFor
(
$path
,
$thumbnail
);
foreach
(
$thumbnail
->
filters
()
as
$manipulation
=>
$options
)
{
$image
=
$this
->
imageFactory
->
make
(
$manipulation
)
->
handle
(
$image
,
$options
);
}
$image
=
$image
->
stream
(
pathinfo
(
$path
,
PATHINFO_EXTENSION
),
array_get
(
$thumbnail
->
filters
(),
'quality'
,
90
));
$this
->
writeImage
(
$filename
,
$image
);
}
...
...
@@ -241,4 +244,17 @@ class Imagy
return
$path
;
}
private
function
getFilenameFor
(
MediaPath
$path
,
Thumbnail
$thumbnail
)
{
$filenameWithoutPrefix
=
str_replace
(
config
(
'asgard.media.config.files-path'
),
''
,
$path
->
getRelativeUrl
());
$filename
=
substr
(
strrchr
(
$filenameWithoutPrefix
,
'/'
),
1
);
$folders
=
str_replace
(
$filename
,
''
,
$filenameWithoutPrefix
);
if
(
$filename
===
false
)
{
return
config
(
'asgard.media.config.files-path'
)
.
$this
->
newFilename
(
$path
,
$thumbnail
->
name
());
}
return
config
(
'asgard.media.config.files-path'
)
.
$folders
.
$this
->
newFilename
(
$path
,
$thumbnail
->
name
());
}
}
Modules/Media/Services/FileService.php
View file @
62625d47
...
...
@@ -30,11 +30,12 @@ class FileService
/**
* @param UploadedFile $file
* @param int $parentId
* @return mixed
*/
public
function
store
(
UploadedFile
$file
)
public
function
store
(
UploadedFile
$file
,
int
$parentId
=
0
)
{
$savedFile
=
$this
->
file
->
createFromFile
(
$file
);
$savedFile
=
$this
->
file
->
createFromFile
(
$file
,
$parentId
);
$path
=
$this
->
getDestinationPath
(
$savedFile
->
getOriginal
(
'path'
));
$stream
=
fopen
(
$file
->
getRealPath
(),
'r+'
);
...
...
Modules/Media/Tests/FileServiceTest.php
View file @
62625d47
...
...
@@ -2,6 +2,7 @@
namespace
Modules\Media\Tests
;
use
Modules\Media\Repositories\FolderRepository
;
use
Modules\Media\Services\FileService
;
final
class
FileServiceTest
extends
MediaTestCase
...
...
@@ -60,4 +61,30 @@ final class FileServiceTest extends MediaTestCase
$this
->
assertFalse
(
$this
->
app
[
'files'
]
->
exists
(
public_path
(
'assets/media/records_smallThumb.pdf'
)));
$this
->
assertFalse
(
$this
->
app
[
'files'
]
->
exists
(
public_path
(
'assets/media/records_mediumThumb.pdf'
)));
}
/** @test */
public
function
it_can_store_a_file_in_sub_folder
()
{
$folderRepository
=
app
(
FolderRepository
::
class
);
$folderRepository
->
create
([
'name'
=>
'My Folder'
,
'parent_id'
=>
0
]);
$file
=
\Illuminate\Http\UploadedFile
::
fake
()
->
create
(
'records.pdf'
);
$this
->
fileService
->
store
(
$file
,
1
);
$this
->
assertTrue
(
$this
->
app
[
'files'
]
->
exists
(
public_path
(
'assets/media/my-folder/records.pdf'
)));
}
/** @test */
public
function
it_can_store_an_image_with_thumbnails_in_sub_folder
()
{
$folderRepository
=
app
(
FolderRepository
::
class
);
$folderRepository
->
create
([
'name'
=>
'My Folder'
,
'parent_id'
=>
0
]);
$file
=
\Illuminate\Http\UploadedFile
::
fake
()
->
image
(
'my-file.jpg'
);
$this
->
fileService
->
store
(
$file
,
1
);
$this
->
assertTrue
(
$this
->
app
[
'files'
]
->
exists
(
public_path
(
'assets/media/my-folder/my-file.jpg'
)));
$this
->
assertTrue
(
$this
->
app
[
'files'
]
->
exists
(
public_path
(
'assets/media/my-folder/my-file_smallThumb.jpg'
)));
$this
->
assertTrue
(
$this
->
app
[
'files'
]
->
exists
(
public_path
(
'assets/media/my-folder/my-file_mediumThumb.jpg'
)));
}
}
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