]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/BookController.php
Fixed pagination on change of display type.
[bookstack] / app / Http / Controllers / BookController.php
index 9c1154281be3f47b01ed10ab8efbd73c5db2daee..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
 {
@@ -41,7 +42,7 @@ class BookController extends Controller
         $popular = $this->entityRepo->getPopular('book', 3, 0);
         $books_display = $this->currentUser->books_display;
         $this->setPageTitle('Books');
-        return view('books/index', ['books' => $books, 'recents' => $recents, 'popular' => $popular, 'books_display' => $books_display]);
+        return view('books/index', ['books' => $books, 'recents' => $recents, 'popular' => $popular, 'books_display' => $books_display] );
     }
 
     /**
@@ -133,13 +134,20 @@ class BookController extends Controller
      * @param  $image
      * @return $path
      */
-    public function getBookCoverURL($image)
+    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');
     }