Ignore:
Timestamp:
10/24/21 23:23:54 (3 years ago)
Author:
beratkjufliju <kufliju@…>
Branches:
develop, master
Children:
df6e9ec
Parents:
fa80fbe
Message:

bug fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • app/Http/Controllers/Dashboard/DepartmentsController.php

    rfa80fbe r94f05dc  
    4747
    4848        $users = User::all();
    49         Notification::send($users, new NewDepartmentCreated("New department created"));
    5049
    5150        $department->save();
     
    127126        try {
    128127            $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
    129             $flag = false;
    130 
    131128            foreach ($files as $file) {
    132129
     
    154151        $department = Department::find($id);
    155152
    156         $FileSystem = new Filesystem();
    157         $zip_file = Storage::disk('uploads')->path('Department.zip');
     153        $zip_file=Storage::disk('uploads')->path('Department.zip');
    158154        $zip = new \ZipArchive();
    159155        $zip->open($zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
    160         $path = Storage::disk('uploads')->path($department->location) . DIRECTORY_SEPARATOR;
     156        $path = Storage::disk('uploads')->path($department->location);
    161157
    162         try{
     158        try {
    163159            $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
    164160            foreach ($files as $file) {
     161
     162                // We're skipping all subfolders
    165163                if (!$file->isDir()) {
    166164                    $filePath = $file->getRealPath();
     
    169167                    $zip->addFile($filePath, $relativePath);
    170168                }
     169            }
    171170            $zip->close();
    172             $headers = array('Content-Type' => 'application/octet-stream',);
    173             $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . $department->name . '.zip';
     171            $headers = array('Content-Type' => 'application/octet-stream');
     172            $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . '- Departments.zip';
    174173            return response()->download($zip_file, $zip_new_name, $headers);
    175174        }
    176     }
    177     catch(\Exception $e) {
    178             Alert::flash("This department has no files", "warning");
     175        catch(\Exception $e){
     176            Alert::flash("All departments are empty", "warning");
    179177            return redirect()->back();
    180     }
     178        }
    181179    }
    182180}
Note: See TracChangeset for help on using the changeset viewer.