]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/BookshelfController.php
Update settings.php
[bookstack] / app / Http / Controllers / BookshelfController.php
index e63cfd1d5f624ec4b9693e6372b22aae20c00e51..bcf2e12df88a67628bdded31f2db1162ce120098 100644 (file)
@@ -86,8 +86,9 @@ class BookshelfController extends Controller
 
     /**
      * Store a newly created bookshelf in storage.
-     * @param  Request $request
+     * @param Request $request
      * @return Response
+     * @throws \BookStack\Exceptions\ImageUploadException
      */
     public function store(Request $request)
     {
@@ -123,6 +124,7 @@ class BookshelfController extends Controller
         $this->entityContextManager->setShelfContext($shelf->id);
 
         $this->setPageTitle($shelf->getShortName());
+
         return view('shelves.show', [
             'shelf' => $shelf,
             'books' => $books,
@@ -284,10 +286,18 @@ class BookshelfController extends Controller
         $this->entityRepo->updateShelfBooks($shelf, $request->get('books', ''));
 
         // Update the cover image if in request
-        if ($request->has('image') && userCan('image-create-all')) {
-            $image = $this->imageRepo->saveNew($request->file('image'), 'cover', $shelf->id);
+        if ($request->has('image')) {
+            $newImage = $request->file('image');
+            $this->imageRepo->destroyImage($shelf->cover);
+            $image = $this->imageRepo->saveNew($newImage, 'cover_shelf', $shelf->id, 512, 512, true);
             $shelf->image_id = $image->id;
             $shelf->save();
         }
+
+        if ($request->has('image_reset')) {
+            $this->imageRepo->destroyImage($shelf->cover);
+            $shelf->image_id = 0;
+            $shelf->save();
+        }
     }
 }