1day2die 3 лет назад
Родитель
Сommit
39af10ff95
1 измененных файлов с 15 добавлено и 17 удалено
  1. 15 17
      app/Http/Controllers/Admin/SettingsController.php

+ 15 - 17
app/Http/Controllers/Admin/SettingsController.php

@@ -72,33 +72,31 @@ class SettingsController extends Controller
         return redirect()->route('admin.settings.index')->with('success', 'Invoice settings updated!');
     }
 
-    public function rglob($pattern, $flags = 0) {
-        $files = glob($pattern, $flags);
-        foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
-            $files = array_merge($files, $this::rglob($dir.'/'.basename($pattern), $flags));
-        }
-        return $files;
-    }
-
-    public function downloadAllInvoices(){
+    public function downloadAllInvoices()
+    {
         $zip = new ZipArchive;
         $zip_safe_path = storage_path('invoices.zip');
-        $res = $zip->open($zip_safe_path, ZipArchive::CREATE|ZipArchive::OVERWRITE);
+        $res = $zip->open($zip_safe_path, ZipArchive::CREATE | ZipArchive::OVERWRITE);
         $result = $this::rglob(storage_path('app/invoice/*'));
         if ($res === TRUE) {
-            $zip->addFromString("1. Info.txt","This Archive contains all Invoices from all Users!\n If there are no Invoices here, no Invoices have ever been created!");
-            foreach($result as $file){
+            $zip->addFromString("1. Info.txt", "This Archive contains all Invoices from all Users!\nIf there are no Invoices here, no Invoices have ever been created!");
+            foreach ($result as $file) {
                 if (file_exists($file) && is_file($file)) {
-                    $zip->addFile($file,basename($file));
+                    $zip->addFile($file, basename($file));
                 }
             }
             $zip->close();
         }
-        if (file_exists($zip_safe_path) && is_file($zip_safe_path)) {
-            return response()->download($zip_safe_path);
-        }else{
-            $this->index()->with('failure', 'No Invoices in Storage!');
+        return response()->download($zip_safe_path);
+    }
+
+    public function rglob($pattern, $flags = 0)
+    {
+        $files = glob($pattern, $flags);
+        foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
+            $files = array_merge($files, $this::rglob($dir . '/' . basename($pattern), $flags));
         }
+        return $files;
     }
 
 }