From b7db2094686326ce1639536467c39f4b24d49821 Mon Sep 17 00:00:00 2001
From: Aria <aria@suma-ev.de>
Date: Tue, 30 May 2017 10:25:36 +0200
Subject: [PATCH] =?UTF-8?q?Fehler=20beim=20=C3=96ffnen=20der=20Zip,=20Ursa?=
 =?UTF-8?q?che=20unbekannt?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/Http/Controllers/MailController.php | 33 +++++++++++++++----------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/app/Http/Controllers/MailController.php b/app/Http/Controllers/MailController.php
index 1a1be885e..51a8b122d 100644
--- a/app/Http/Controllers/MailController.php
+++ b/app/Http/Controllers/MailController.php
@@ -335,22 +335,29 @@ class MailController extends Controller
             return redirect(url('synoptic', ['exclude' => $exclude]));
         }
 
-        $zip = new ZipArchive();
 
-        if ($zip->open("langfiles.zip", ZipArchive::OVERWRITE)!==TRUE) {  
-        } else if ($zip->open("langfiles.zip", ZipArchive::CREATE)!==TRUE) {
-            exit("Cannot open".$filename);
-        }
+        if(file_exists("langfiles.zip"))
+            unlink("langfiles.zip");
+
+        $zip = new ZipArchive();
 
+        if ($zip->open("langfiles.zip", ZipArchive::CREATE)) {  
+            exit("Cannot open ".$filename);
+        } 
+            
+        try{
         #Erstelle Ausgabedateien
-        foreach($data as $lang => $entries) {
-            $output = json_encode($entries, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
-            $output = preg_replace("/\{/si", "[", $output);
-            $output = preg_replace("/\}/si", "]", $output);
-            $output = preg_replace("/\": ([\"\[])/si", "\"\t=>\t$1", $output);
-            $output = "<?php\n\nreturn $output;\n";
-            $zip->addEmptyDir($lang);
-            $zip->addFromString($lang."/".$filename, $output);
+            foreach($data as $lang => $entries) {
+                $output = json_encode($entries, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
+                $output = preg_replace("/\{/si", "[", $output);
+                $output = preg_replace("/\}/si", "]", $output);
+                $output = preg_replace("/\": ([\"\[])/si", "\"\t=>\t$1", $output);
+                $output = "<?php\n\nreturn $output;\n";
+                $zip->addEmptyDir($lang);
+                $zip->addFromString($lang."/".$filename, $output);
+            }
+        } catch(ErrorException $e) {
+            exit("Failed to write ".$filename);
         }
 
         $zip->close();
-- 
GitLab