use BookStack\Entities\Repos\BookRepo;
use BookStack\Entities\Tools\BookContents;
use BookStack\Entities\Tools\Cloner;
+use BookStack\Entities\Tools\HierarchyTransformer;
use BookStack\Entities\Tools\PermissionsUpdater;
use BookStack\Entities\Tools\ShelfContext;
use BookStack\Exceptions\ImageUploadException;
public function store(Request $request, string $shelfSlug = null)
{
$this->checkPermission('book-create-all');
- $this->validate($request, [
+ $validated = $this->validate($request, [
'name' => ['required', 'string', 'max:255'],
'description' => ['string', 'max:1000'],
'image' => array_merge(['nullable'], $this->getImageValidationRules()),
+ 'tags' => ['array'],
]);
$bookshelf = null;
$this->checkOwnablePermission('bookshelf-update', $bookshelf);
}
- $book = $this->bookRepo->create($request->all());
+ $book = $this->bookRepo->create($validated);
if ($bookshelf) {
$bookshelf->appendBook($book);
'name' => ['required', 'string', 'max:255'],
'description' => ['string', 'max:1000'],
'image' => array_merge(['nullable'], $this->getImageValidationRules()),
+ 'tags' => ['array'],
]);
if ($request->has('image_reset')) {
$validated['image'] = null;
- } else if (is_null($validated['image'])) {
+ } elseif (array_key_exists('image', $validated) && is_null($validated['image'])) {
unset($validated['image']);
}
return redirect($bookCopy->getUrl());
}
+
+ /**
+ * Convert the chapter to a book.
+ */
+ public function convertToShelf(HierarchyTransformer $transformer, string $bookSlug)
+ {
+ $book = $this->bookRepo->getBySlug($bookSlug);
+ $this->checkOwnablePermission('book-update', $book);
+ $this->checkOwnablePermission('book-delete', $book);
+ $this->checkPermission('bookshelf-create-all');
+ $this->checkPermission('book-create-all');
+
+ $shelf = $transformer->transformBookToShelf($book);
+
+ return redirect($shelf->getUrl());
+ }
}