From e0f192777f763cff8e4bbf5316f7d233d73d04b4 Mon Sep 17 00:00:00 2001 From: Peter Papp Date: Sun, 17 Jan 2021 13:30:18 +0100 Subject: [PATCH] - zip folder fix for sisters directories --- app/Http/Helpers/helpers.php | 21 ++++++++++++++------- app/Http/Tools/Editor.php | 4 ++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/Http/Helpers/helpers.php b/app/Http/Helpers/helpers.php index d6542705..8fb6a658 100644 --- a/app/Http/Helpers/helpers.php +++ b/app/Http/Helpers/helpers.php @@ -742,27 +742,34 @@ function remove_accents($string) { * Get all files from folder and get their folder location in VueFileManager directories * * @param $folders - * @param array $files + * @param null $files * @param array $path * @return array */ -function get_files_for_zip($folders, $files = [], $path = []) +function get_files_for_zip($folders, $files, $path = []) { // Return file list if (!isset($folders->folders)) { - return $files; + return $files->unique()->values()->all(); } - // Push path + // Push file path array_push($path, $folders->name); - // Write file list - foreach ($folders->files as $file) { - array_push($files, [ + // Push file to collection + $folders->files->each(function ($file) use ($files, $path) { + $files->push([ 'name' => $file->name, 'basename' => $file->basename, 'folder_path' => implode('/', $path), ]); + }); + + // Get all children folders and folders within + if ($folders->folders->isNotEmpty()) { + $folders->folders->map(function ($folder) use ($files, $path) { + return get_files_for_zip($folder, $files, $path); + }); } return get_files_for_zip($folders->folders->first(), $files, $path); diff --git a/app/Http/Tools/Editor.php b/app/Http/Tools/Editor.php index fd7dbdf8..67970957 100644 --- a/app/Http/Tools/Editor.php +++ b/app/Http/Tools/Editor.php @@ -30,6 +30,7 @@ class Editor * Zip requested folder * * @param $unique_id + * @param $shared * @return mixed * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ @@ -42,8 +43,7 @@ class Editor ->with('folders') ->first(); - - $files = get_files_for_zip($requested_folder); + $files = get_files_for_zip($requested_folder, collect([])); // Local storage instance $disk_local = Storage::disk('local');