3 namespace BookStack\Entities\Tools;
5 use BookStack\Entities\Models\Entity;
6 use BookStack\Entities\Models\Page;
7 use BookStack\Entities\Repos\PageRepo;
17 public function __construct(PageRepo $pageRepo)
19 $this->pageRepo = $pageRepo;
23 * Clone the given page into the given parent using the provided name.
25 public function clonePage(Page $original, Entity $parent, string $newName): Page
27 $copyPage = $this->pageRepo->getNewDraftPage($parent);
28 $pageData = $original->getAttributes();
31 $pageData['name'] = $newName;
33 // Copy tags from previous page if set
34 if ($original->tags) {
35 $pageData['tags'] = [];
36 foreach ($original->tags as $tag) {
37 $pageData['tags'][] = ['name' => $tag->name, 'value' => $tag->value];
41 return $this->pageRepo->publishDraft($copyPage, $pageData);