1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-09 10:22:51 +03:00

Updated book copy to copy shelf relations

Where permission to edit the shelf is allowed.
For #3699
This commit is contained in:
Dan Brown
2022-09-28 14:14:51 +01:00
parent 8f3430d386
commit 60171b3522
3 changed files with 37 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ namespace BookStack\Entities\Tools;
use BookStack\Actions\Tag;
use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Bookshelf;
use BookStack\Entities\Models\Chapter;
use BookStack\Entities\Models\Entity;
use BookStack\Entities\Models\Page;
@@ -71,8 +72,10 @@ class Cloner
$bookDetails = $this->entityToInputData($original);
$bookDetails['name'] = $newName;
// Clone book
$copyBook = $this->bookRepo->create($bookDetails);
// Clone contents
$directChildren = $original->getDirectChildren();
foreach ($directChildren as $child) {
if ($child instanceof Chapter && userCan('chapter-create', $copyBook)) {
@@ -84,6 +87,14 @@ class Cloner
}
}
// Clone bookshelf relationships
/** @var Bookshelf $shelf */
foreach ($original->shelves as $shelf) {
if (userCan('bookshelf-update', $shelf)) {
$shelf->appendBook($copyBook);
}
}
return $copyBook;
}