]> BookStack Code Mirror - bookstack/blobdiff - app/Repos/PageRepo.php
Prevent duplicate slugs on sort
[bookstack] / app / Repos / PageRepo.php
index 3f8f813947c262d456616d2d937438f3067ddb74..a52cecad3e75b79a7f66d9942b9e2b197872b9e4 100644 (file)
@@ -309,19 +309,20 @@ class PageRepo
     }
 
     /**
-     * Sets the book id for the specified page.
+     * Changes the related book for the specified page.
      * Changes the book id of any relations to the page that store the book id.
      * @param int  $bookId
      * @param Page $page
      * @return Page
      */
-    public function setBookId($bookId, Page $page)
+    public function changeBook($bookId, Page $page)
     {
         $page->book_id = $bookId;
         foreach ($page->activity as $activity) {
             $activity->book_id = $bookId;
             $activity->save();
         }
+        $page->slug = $this->findSuitableSlug($page->name, $bookId, $page->id);
         $page->save();
         return $page;
     }