From 7a42b81a9752c03ddbb9745cde4a0a6ba3bac680 Mon Sep 17 00:00:00 2001 From: Luca Date: Thu, 25 Jun 2020 12:53:12 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20per=20evitare=20eliminazione=20dell'inter?= =?UTF-8?q?a=20cartella=20quando=20filename=20=C3=A8=20vuoto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Uploads.php | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/Uploads.php b/src/Uploads.php index f9dd0fba4..f8b4585ec 100755 --- a/src/Uploads.php +++ b/src/Uploads.php @@ -250,36 +250,37 @@ class Uploads */ public static function delete($filename, $data) { - $database = database(); + if (!empty($filename)){ + $database = database(); - $name = $database->selectOne('zz_files', ['name'], [ - 'filename' => $filename, - 'id_module' => !empty($data['id_module']) && empty($data['id_plugin']) ? $data['id_module'] : null, - 'id_plugin' => !empty($data['id_plugin']) ? $data['id_plugin'] : null, - 'id_record' => $data['id_record'], - ])['name']; - - $fileinfo = self::fileInfo($filename); - $directory = DOCROOT.'/'.self::getDirectory($data['id_module'], $data['id_plugin']); - - $files = [ - $directory.'/'.$fileinfo['basename'], - $directory.'/'.$fileinfo['filename'].'_thumb600.'.$fileinfo['extension'], - $directory.'/'.$fileinfo['filename'].'_thumb100.'.$fileinfo['extension'], - $directory.'/'.$fileinfo['filename'].'_thumb250.'.$fileinfo['extension'], - ]; - - if (delete($files)) { - $database->delete('zz_files', [ - 'filename' => $fileinfo['basename'], + $name = $database->selectOne('zz_files', ['name'], [ + 'filename' => $filename, 'id_module' => !empty($data['id_module']) && empty($data['id_plugin']) ? $data['id_module'] : null, 'id_plugin' => !empty($data['id_plugin']) ? $data['id_plugin'] : null, 'id_record' => $data['id_record'], - ]); + ])['name']; - return $name; + $fileinfo = self::fileInfo($filename); + $directory = DOCROOT.'/'.self::getDirectory($data['id_module'], $data['id_plugin']); + + $files = [ + $directory.'/'.$fileinfo['basename'], + $directory.'/'.$fileinfo['filename'].'_thumb600.'.$fileinfo['extension'], + $directory.'/'.$fileinfo['filename'].'_thumb100.'.$fileinfo['extension'], + $directory.'/'.$fileinfo['filename'].'_thumb250.'.$fileinfo['extension'], + ]; + + if (delete($files)) { + $database->delete('zz_files', [ + 'filename' => $fileinfo['basename'], + 'id_module' => !empty($data['id_module']) && empty($data['id_plugin']) ? $data['id_module'] : null, + 'id_plugin' => !empty($data['id_plugin']) ? $data['id_plugin'] : null, + 'id_record' => $data['id_record'], + ]); + + return $name; + } } - return null; }