Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Castopod
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ad Aures
Castopod
Commits
e65e236b
Commit
e65e236b
authored
3 years ago
by
Yassine Doghri
Browse files
Options
Downloads
Patches
Plain Diff
refactor: replace hardcoded media root with media_path helper method in settings controller
parent
89dee41d
No related branches found
Branches containing commit
Tags
v1.0.0-alpha.57
Tags containing commit
2 merge requests
!160
WIP:Feat/social interact
,
!150
fix(ux): enhance user experience
Pipeline
#1200
passed
3 years ago
Stage: prepare
Stage: quality
Stage: bundle
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/Admin/Controllers/SettingsController.php
+19
-29
19 additions, 29 deletions
modules/Admin/Controllers/SettingsController.php
with
19 additions
and
29 deletions
modules/Admin/Controllers/SettingsController.php
+
19
−
29
View file @
e65e236b
...
...
@@ -56,16 +56,16 @@ class SettingsController extends BaseController
helper
([
'filesystem'
,
'media'
]);
// delete site folder in media before repopulating it
delete_files
(
ROOTPATH
.
'public/media
/site
/
'
);
delete_files
(
media_path
(
'
/site'
)
);
// save original in disk
$originalFilename
=
save_media
(
$siteIconFile
,
'site'
,
'icon'
);
// convert jpeg image to png if not
if
(
$siteIconFile
->
getClientMimeType
()
!==
'image/png'
)
{
service
(
'image'
)
->
withFile
(
ROOTPATH
.
'public/media/'
.
$originalFilename
)
service
(
'image'
)
->
withFile
(
media_path
(
$originalFilename
)
)
->
convert
(
IMAGETYPE_JPEG
)
->
save
(
ROOTPATH
.
'public/media
/site/icon.png'
);
->
save
(
media_path
(
'
/site/icon.png'
)
)
;
}
// generate random hash to use as a suffix to renew browser cache
...
...
@@ -73,24 +73,24 @@ class SettingsController extends BaseController
// generate ico
$ico_lib
=
new
PHP_ICO
();
$ico_lib
->
add_image
(
ROOTPATH
.
'public/media
/site/icon.png'
,
[[
32
,
32
],
[
64
,
64
]]);
$ico_lib
->
save_ico
(
ROOTPATH
.
"public/media
/site/favicon.
{
$randomHash
}
.ico"
);
$ico_lib
->
add_image
(
media_path
(
'
/site/icon.png'
)
,
[[
32
,
32
],
[
64
,
64
]]);
$ico_lib
->
save_ico
(
media_path
(
"
/site/favicon.
{
$randomHash
}
.ico"
)
)
;
// resize original to needed sizes
foreach
([
64
,
180
,
192
,
512
]
as
$size
)
{
service
(
'image'
)
->
withFile
(
ROOTPATH
.
'public/media
/site/icon.png'
)
->
withFile
(
media_path
(
'
/site/icon.png'
)
)
->
resize
(
$size
,
$size
)
->
save
(
media_path
(
"/site/icon-
{
$size
}
.
{
$randomHash
}
.png"
));
}
service
(
'settings'
)
->
set
(
'App.siteIcon'
,
[
'ico'
=>
media_path
(
"/site/favicon.
{
$randomHash
}
.ico"
),
'64'
=>
media_path
(
"/site/icon-64.
{
$randomHash
}
.png"
),
'180'
=>
media_path
(
"/site/icon-180.
{
$randomHash
}
.png"
),
'192'
=>
media_path
(
"/site/icon-192.
{
$randomHash
}
.png"
),
'512'
=>
media_path
(
"/site/icon-512.
{
$randomHash
}
.png"
),
'ico'
=>
'/'
.
media_path
(
"/site/favicon.
{
$randomHash
}
.ico"
),
'64'
=>
'/'
.
media_path
(
"/site/icon-64.
{
$randomHash
}
.png"
),
'180'
=>
'/'
.
media_path
(
"/site/icon-180.
{
$randomHash
}
.png"
),
'192'
=>
'/'
.
media_path
(
"/site/icon-192.
{
$randomHash
}
.png"
),
'512'
=>
'/'
.
media_path
(
"/site/icon-512.
{
$randomHash
}
.png"
),
]);
}
...
...
@@ -99,9 +99,9 @@ class SettingsController extends BaseController
public
function
deleteIcon
():
RedirectResponse
{
helper
(
'filesystem'
);
helper
(
[
'filesystem'
,
'media'
]
);
// delete site folder in media
delete_files
(
ROOTPATH
.
'public/media
/site
/
'
);
delete_files
(
media_path
(
'
/site'
)
);
service
(
'settings'
)
->
forget
(
'App.siteIcon'
);
...
...
@@ -111,13 +111,12 @@ class SettingsController extends BaseController
public
function
regenerateImages
():
RedirectResponse
{
helper
(
'media'
);
$allPodcasts
=
(
new
PodcastModel
())
->
findAll
();
foreach
(
$allPodcasts
as
$podcast
)
{
$podcastImages
=
glob
(
ROOTPATH
.
'public/'
.
config
(
'App'
)
->
mediaRoot
.
"/podcasts/
{
$podcast
->
handle
}
/*_*
{
jpg,png,webp
}
"
,
GLOB_BRACE
);
$podcastImages
=
glob
(
media_path
(
"/podcasts/
{
$podcast
->
handle
}
/*_*
{
jpg,png,webp
}
"
),
GLOB_BRACE
);
if
(
$podcastImages
)
{
foreach
(
$podcastImages
as
$podcastImage
)
{
...
...
@@ -138,10 +137,7 @@ class SettingsController extends BaseController
}
}
$personsImages
=
glob
(
ROOTPATH
.
'public/'
.
config
(
'App'
)
->
mediaRoot
.
'/persons/*_*{jpg,png,webp}'
,
GLOB_BRACE
);
$personsImages
=
glob
(
media_path
(
'/persons/*_*{jpg,png,webp}'
),
GLOB_BRACE
);
if
(
$personsImages
)
{
foreach
(
$personsImages
as
$personsImage
)
{
if
(
is_file
(
$personsImage
))
{
...
...
@@ -167,10 +163,7 @@ class SettingsController extends BaseController
// Delete all podcast image sizes to recreate them
$allPodcasts
=
(
new
PodcastModel
())
->
findAll
();
foreach
(
$allPodcasts
as
$podcast
)
{
$podcastImages
=
glob
(
ROOTPATH
.
'public/'
.
config
(
'App'
)
->
mediaRoot
.
"/podcasts/
{
$podcast
->
handle
}
/*_*
{
jpg,png,webp
}
"
,
GLOB_BRACE
);
$podcastImages
=
glob
(
media_path
(
"/podcasts/
{
$podcast
->
handle
}
/*_*
{
jpg,png,webp
}
"
),
GLOB_BRACE
);
if
(
$podcastImages
)
{
foreach
(
$podcastImages
as
$podcastImage
)
{
...
...
@@ -182,10 +175,7 @@ class SettingsController extends BaseController
}
// Delete all person image sizes to recreate them
$personsImages
=
glob
(
ROOTPATH
.
'public/'
.
config
(
'App'
)
->
mediaRoot
.
'/persons/*_*{jpg,png,webp}'
,
GLOB_BRACE
);
$personsImages
=
glob
(
media_path
(
'/persons/*_*{jpg,png,webp}'
),
GLOB_BRACE
);
if
(
$personsImages
)
{
foreach
(
$personsImages
as
$personsImage
)
{
if
(
is_file
(
$personsImage
))
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment