]> BookStack Code Mirror - bookstack/commitdiff
Deletion of image file on book deletion.
authorNilesh Deepak <redacted>
Thu, 6 Jul 2017 04:33:40 +0000 (10:03 +0530)
committerNilesh Deepak <redacted>
Thu, 6 Jul 2017 04:33:40 +0000 (10:03 +0530)
app/Http/Controllers/BookController.php

index aca993bba71f1370458597efa45a95ab6aa3d4b3..b64841220b01f8122f3f2cc505e543defafcf579 100644 (file)
@@ -8,6 +8,7 @@ use BookStack\Services\ExportService;
 use Illuminate\Http\Request;
 use Illuminate\Http\Response;
 use Views;
+use File;
 
 class BookController extends Controller
 {
@@ -135,11 +136,18 @@ class BookController extends Controller
      */
     private function getBookCoverURL($image)
     {
-         $input = time().'-'.$image->getClientOriginalName();
-         $destinationPath = public_path('uploads/book/');
-         $image->move($destinationPath, $input);
-         $path = baseUrl('/uploads/book/').'/'.$input;
-         return $path;
+        if(is_null($image))
+        {
+            return;
+        }
+        else
+        {
+            $input = time().'-'.$image->getClientOriginalName();
+            $destinationPath = public_path('uploads/book/');
+            $image->move($destinationPath, $input);
+            $path = baseUrl('/uploads/book/').'/'.$input;
+            return $path;
+        }
     }
 
     /**
@@ -250,6 +258,8 @@ class BookController extends Controller
         $book = $this->entityRepo->getBySlug('book', $bookSlug);
         $this->checkOwnablePermission('book-delete', $book);
         Activity::addMessage('book_delete', 0, $book->name);
+        $file = basename($book->image);
+        File::delete('uploads/book/'.$file);
         $this->entityRepo->destroyBook($book);
         return redirect('/books');
     }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.