Added some logic around deleting images

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-07-04 16:33:22 +01:00
parent 5b8f6910fb
commit 2f3be267b3

View file

@ -416,44 +416,64 @@ class SettingsController extends Controller
// Because public demos make people act like dicks // Because public demos make people act like dicks
if (!config('app.lock_passwords')) { if (!config('app.lock_passwords')) {
if ($request->has('site_name')) {
$request->validate(['site_name' => 'required']); $request->validate(['site_name' => 'required']);
$setting->site_name = $request->input('site_name'); }
$setting->site_name = $request->input('site_name', 'Snipe-IT');
$setting->custom_css = $request->input('custom_css'); $setting->custom_css = $request->input('custom_css');
// Logo upload // Logo upload
$setting = $request->handleImages($setting, 600, 'logo', '', 'logo'); $setting = $request->handleImages($setting, 600, 'logo', '', 'logo');
if ('1' == $request->input('clear_logo')) {
if ($request->input('clear_logo') == '1') {
if (($setting->logo) && (Storage::exists($setting->logo))) {
Storage::disk('public')->delete($setting->logo); Storage::disk('public')->delete($setting->logo);
}
$setting->logo = null; $setting->logo = null;
$setting->brand = 1; $setting->brand = 1;
} }
// Email logo upload // Email logo upload
$setting = $request->handleImages($setting, 600, 'email_logo', '', 'email_logo'); $setting = $request->handleImages($setting, 600, 'email_logo', '', 'email_logo');
if ('1' == $request->input('clear_email_logo')) { if ($request->input('clear_email_logo') == '1') {
if (($setting->email_logo) && (Storage::exists($setting->email_logo))) {
Storage::disk('public')->delete($setting->email_logo); Storage::disk('public')->delete($setting->email_logo);
}
$setting->email_logo = null; $setting->email_logo = null;
// If they are uploading an image, validate it and upload it // If they are uploading an image, validate it and upload it
} }
// Label logo upload // Label logo upload
$setting = $request->handleImages($setting, 600, 'label_logo', '', 'label_logo'); $setting = $request->handleImages($setting, 600, 'label_logo', '', 'label_logo');
if ('1' == $request->input('clear_label_logo')) { if ($request->input('clear_label_logo') == '1') {
if (($setting->label_logo) && (Storage::exists($setting->label_logo))) {
Storage::disk('public')->delete($setting->label_logo); Storage::disk('public')->delete($setting->label_logo);
}
$setting->label_logo = null; $setting->label_logo = null;
} }
// Favicon upload // Favicon upload
$setting = $request->handleImages($setting, 100, 'favicon', '', 'favicon'); $setting = $request->handleImages($setting, 100, 'favicon', '', 'favicon');
if ('1' == $request->input('clear_favicon')) { if ('1' == $request->input('clear_favicon')) {
if (($setting->favicon) && (Storage::exists($setting->favicon))) {
Storage::disk('public')->delete($setting->favicon); Storage::disk('public')->delete($setting->favicon);
}
$setting->favicon = null; $setting->favicon = null;
} }
// Default avatar upload // Default avatar upload
$setting = $request->handleImages($setting, 500, 'default_avatar', 'avatars', 'default_avatar'); $setting = $request->handleImages($setting, 500, 'default_avatar', 'avatars', 'default_avatar');
if ($request->input('clear_default_avatar') == '1') { if ($request->input('clear_default_avatar') == '1') {
if (($setting->default_avatar) && (Storage::exists('avatars/'.$setting->default_avatar))) {
Storage::disk('public')->delete('avatars/'.$setting->default_avatar); Storage::disk('public')->delete('avatars/'.$setting->default_avatar);
}
$setting->default_avatar = null; $setting->default_avatar = null;
} }
} }