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
beea73de
Commit
beea73de
authored
Nov 02, 2014
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move the delete files to the correct class
parent
538347f1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
9 deletions
+53
-9
MediaController.php
Http/Controllers/Admin/MediaController.php
+8
-1
Imagy.php
Image/Imagy.php
+34
-5
EloquentFileRepository.php
Repositories/Eloquent/EloquentFileRepository.php
+0
-2
FileService.php
Services/FileService.php
+11
-1
No files found.
Http/Controllers/Admin/MediaController.php
View file @
beea73de
...
...
@@ -7,6 +7,7 @@ use Laracasts\Flash\Flash;
use
Modules\Core\Http\Controllers\Admin\AdminBaseController
;
use
Modules\Media\Entities\File
;
use
Modules\Media\Http\Requests\UpdateMediaRequest
;
use
Modules\Media\Image\Imagy
;
use
Modules\Media\Repositories\FileRepository
;
class
MediaController
extends
AdminBaseController
...
...
@@ -19,11 +20,16 @@ class MediaController extends AdminBaseController
* @var Repository
*/
private
$config
;
/**
* @var Imagy
*/
private
$imagy
;
public
function
__construct
(
FileRepository
$file
,
Repository
$config
)
public
function
__construct
(
FileRepository
$file
,
Repository
$config
,
Imagy
$imagy
)
{
$this
->
file
=
$file
;
$this
->
config
=
$config
;
$this
->
imagy
=
$imagy
;
}
/**
...
...
@@ -102,6 +108,7 @@ class MediaController extends AdminBaseController
*/
public
function
destroy
(
File
$file
)
{
$this
->
imagy
->
deleteAllFor
(
$file
);
$this
->
file
->
destroy
(
$file
);
Flash
::
success
(
'File deleted'
);
...
...
Image/Imagy.php
View file @
beea73de
...
...
@@ -26,7 +26,7 @@ class Imagy
* All the different images types where thumbnails should be created
* @var array
*/
private
$imageExtensions
=
[
'jpg'
,
'png'
,
'jpeg'
,
'gif'
];
private
$imageExtensions
=
[
'jpg'
,
'png'
,
'jpeg'
,
'gif'
];
/**
* @var Repository
*/
...
...
@@ -55,7 +55,9 @@ class Imagy
*/
public
function
get
(
$path
,
$thumbnail
,
$forceCreate
=
false
)
{
if
(
!
$this
->
isImage
(
$path
))
return
;
if
(
!
$this
->
isImage
(
$path
))
{
return
;
}
$filename
=
$this
->
config
->
get
(
'media::config.files-path'
)
.
$this
->
newFilename
(
$path
,
$thumbnail
);
...
...
@@ -76,7 +78,9 @@ class Imagy
*/
public
function
getThumbnail
(
$originalImage
,
$thumbnail
)
{
if
(
!
$this
->
isImage
(
$originalImage
))
return
$originalImage
;
if
(
!
$this
->
isImage
(
$originalImage
))
{
return
$originalImage
;
}
return
$this
->
config
->
get
(
'media::config.files-path'
)
.
$this
->
newFilename
(
$originalImage
,
$thumbnail
);
}
...
...
@@ -87,7 +91,9 @@ class Imagy
*/
public
function
createAll
(
$path
)
{
if
(
!
$this
->
isImage
(
$path
))
return
;
if
(
!
$this
->
isImage
(
$path
))
{
return
;
}
foreach
(
$this
->
manager
->
all
()
as
$thumbName
=>
$filters
)
{
$image
=
$this
->
image
->
make
(
public_path
()
.
$path
);
...
...
@@ -157,9 +163,32 @@ class Imagy
* @param string $path
* @return bool
*/
p
rivate
function
isImage
(
$path
)
p
ublic
function
isImage
(
$path
)
{
return
in_array
(
pathinfo
(
$path
,
PATHINFO_EXTENSION
),
$this
->
imageExtensions
);
}
/**
* Delete all files on disk for the given file in storage
* This means the original and the thumbnails
* @param $file
* @return bool
*/
public
function
deleteAllFor
(
$file
)
{
if
(
!
$this
->
isImage
(
$file
->
path
))
{
return
$this
->
finder
->
delete
(
$file
->
path
);
}
$paths
[]
=
public_path
()
.
$file
->
path
;
$fileName
=
pathinfo
(
$file
->
path
,
PATHINFO_FILENAME
);
$extension
=
pathinfo
(
$file
->
path
,
PATHINFO_EXTENSION
);
foreach
(
$this
->
manager
->
all
()
as
$thumbnail
=>
$filters
)
{
$paths
[]
=
public_path
()
.
$this
->
config
->
get
(
'media::config.files-path'
)
.
"
{
$fileName
}
_
{
$thumbnail
}
.
{
$extension
}
"
;
}
return
$this
->
finder
->
delete
(
$paths
);
}
}
Repositories/Eloquent/EloquentFileRepository.php
View file @
beea73de
...
...
@@ -57,8 +57,6 @@ class EloquentFileRepository extends EloquentBaseRepository implements FileRepos
public
function
destroy
(
$file
)
{
$this
->
finder
->
delete
(
'public/'
.
$file
->
path
);
$file
->
delete
();
}
}
Services/FileService.php
View file @
beea73de
...
...
@@ -3,6 +3,7 @@
use
Illuminate\Contracts\Config\Repository
;
use
Illuminate\Contracts\Queue\Queue
;
use
Illuminate\Support\Facades\App
;
use
Modules\Media\Image\Imagy
;
use
Modules\Media\Repositories\FileRepository
;
use
Symfony\Component\HttpFoundation\File\UploadedFile
;
...
...
@@ -20,12 +21,21 @@ class FileService
* @var Queue
*/
private
$queue
;
/**
* @var Imagy
*/
private
$imagy
;
public
function
__construct
(
FileRepository
$file
,
Repository
$config
,
Queue
$queue
)
public
function
__construct
(
FileRepository
$file
,
Repository
$config
,
Queue
$queue
,
Imagy
$imagy
)
{
$this
->
file
=
$file
;
$this
->
config
=
$config
;
$this
->
queue
=
$queue
;
$this
->
imagy
=
$imagy
;
}
/**
...
...
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