Dan Brown

Finished refactor of entity repos

Removed entity-specific repos and standardised
the majority of repo calls to be applicable to
all entity types
...@@ -18,11 +18,12 @@ class Chapter extends Entity ...@@ -18,11 +18,12 @@ class Chapter extends Entity
18 18
19 /** 19 /**
20 * Get the pages that this chapter contains. 20 * Get the pages that this chapter contains.
21 + * @param string $dir
21 * @return mixed 22 * @return mixed
22 */ 23 */
23 - public function pages() 24 + public function pages($dir = 'ASC')
24 { 25 {
25 - return $this->hasMany(Page::class)->orderBy('priority', 'ASC'); 26 + return $this->hasMany(Page::class)->orderBy('priority', $dir);
26 } 27 }
27 28
28 /** 29 /**
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
3 use BookStack\Exceptions\FileUploadException; 3 use BookStack\Exceptions\FileUploadException;
4 use BookStack\Attachment; 4 use BookStack\Attachment;
5 use BookStack\Repos\EntityRepo; 5 use BookStack\Repos\EntityRepo;
6 -use BookStack\Repos\PageRepo;
7 use BookStack\Services\AttachmentService; 6 use BookStack\Services\AttachmentService;
8 use Illuminate\Http\Request; 7 use Illuminate\Http\Request;
9 8
...@@ -11,21 +10,18 @@ class AttachmentController extends Controller ...@@ -11,21 +10,18 @@ class AttachmentController extends Controller
11 { 10 {
12 protected $attachmentService; 11 protected $attachmentService;
13 protected $attachment; 12 protected $attachment;
14 - protected $pageRepo;
15 protected $entityRepo; 13 protected $entityRepo;
16 14
17 /** 15 /**
18 * AttachmentController constructor. 16 * AttachmentController constructor.
19 * @param AttachmentService $attachmentService 17 * @param AttachmentService $attachmentService
20 * @param Attachment $attachment 18 * @param Attachment $attachment
21 - * @param PageRepo $pageRepo 19 + * @param EntityRepo $entityRepo
22 */ 20 */
23 - public function __construct(AttachmentService $attachmentService, Attachment $attachment, EntityRepo $entityRepo, PageRepo $pageRepo) 21 + public function __construct(AttachmentService $attachmentService, Attachment $attachment, EntityRepo $entityRepo)
24 { 22 {
25 $this->attachmentService = $attachmentService; 23 $this->attachmentService = $attachmentService;
26 $this->attachment = $attachment; 24 $this->attachment = $attachment;
27 - // TODO - Remove this
28 - $this->pageRepo = $pageRepo;
29 $this->entityRepo = $entityRepo; 25 $this->entityRepo = $entityRepo;
30 parent::__construct(); 26 parent::__construct();
31 } 27 }
......
...@@ -4,10 +4,6 @@ use Activity; ...@@ -4,10 +4,6 @@ use Activity;
4 use BookStack\Repos\EntityRepo; 4 use BookStack\Repos\EntityRepo;
5 use BookStack\Repos\UserRepo; 5 use BookStack\Repos\UserRepo;
6 use Illuminate\Http\Request; 6 use Illuminate\Http\Request;
7 -use BookStack\Http\Requests;
8 -use BookStack\Repos\BookRepo;
9 -use BookStack\Repos\ChapterRepo;
10 -use BookStack\Repos\PageRepo;
11 use Illuminate\Http\Response; 7 use Illuminate\Http\Response;
12 use Views; 8 use Views;
13 9
...@@ -15,26 +11,16 @@ class BookController extends Controller ...@@ -15,26 +11,16 @@ class BookController extends Controller
15 { 11 {
16 12
17 protected $entityRepo; 13 protected $entityRepo;
18 - protected $bookRepo;
19 - protected $pageRepo;
20 - protected $chapterRepo;
21 protected $userRepo; 14 protected $userRepo;
22 15
23 /** 16 /**
24 * BookController constructor. 17 * BookController constructor.
25 * @param EntityRepo $entityRepo 18 * @param EntityRepo $entityRepo
26 - * @param BookRepo $bookRepo
27 - * @param PageRepo $pageRepo
28 - * @param ChapterRepo $chapterRepo
29 * @param UserRepo $userRepo 19 * @param UserRepo $userRepo
30 */ 20 */
31 - public function __construct(EntityRepo $entityRepo, BookRepo $bookRepo, PageRepo $pageRepo, ChapterRepo $chapterRepo, UserRepo $userRepo) 21 + public function __construct(EntityRepo $entityRepo, UserRepo $userRepo)
32 { 22 {
33 $this->entityRepo = $entityRepo; 23 $this->entityRepo = $entityRepo;
34 - // TODO - Remove below
35 - $this->bookRepo = $bookRepo;
36 - $this->pageRepo = $pageRepo;
37 - $this->chapterRepo = $chapterRepo;
38 $this->userRepo = $userRepo; 24 $this->userRepo = $userRepo;
39 parent::__construct(); 25 parent::__construct();
40 } 26 }
...@@ -76,7 +62,7 @@ class BookController extends Controller ...@@ -76,7 +62,7 @@ class BookController extends Controller
76 'name' => 'required|string|max:255', 62 'name' => 'required|string|max:255',
77 'description' => 'string|max:1000' 63 'description' => 'string|max:1000'
78 ]); 64 ]);
79 - $book = $this->bookRepo->createFromInput($request->all()); 65 + $book = $this->entityRepo->createFromInput('book', $request->all());
80 Activity::add($book, 'book_create', $book->id); 66 Activity::add($book, 'book_create', $book->id);
81 return redirect($book->getUrl()); 67 return redirect($book->getUrl());
82 } 68 }
...@@ -90,7 +76,7 @@ class BookController extends Controller ...@@ -90,7 +76,7 @@ class BookController extends Controller
90 { 76 {
91 $book = $this->entityRepo->getBySlug('book', $slug); 77 $book = $this->entityRepo->getBySlug('book', $slug);
92 $this->checkOwnablePermission('book-view', $book); 78 $this->checkOwnablePermission('book-view', $book);
93 - $bookChildren = $this->bookRepo->getChildren($book); 79 + $bookChildren = $this->entityRepo->getBookChildren($book);
94 Views::add($book); 80 Views::add($book);
95 $this->setPageTitle($book->getShortName()); 81 $this->setPageTitle($book->getShortName());
96 return view('books/show', ['book' => $book, 'current' => $book, 'bookChildren' => $bookChildren]); 82 return view('books/show', ['book' => $book, 'current' => $book, 'bookChildren' => $bookChildren]);
...@@ -123,7 +109,7 @@ class BookController extends Controller ...@@ -123,7 +109,7 @@ class BookController extends Controller
123 'name' => 'required|string|max:255', 109 'name' => 'required|string|max:255',
124 'description' => 'string|max:1000' 110 'description' => 'string|max:1000'
125 ]); 111 ]);
126 - $book = $this->bookRepo->updateFromInput($book, $request->all()); 112 + $book = $this->entityRepo->updateFromInput('book', $book, $request->all());
127 Activity::add($book, 'book_update', $book->id); 113 Activity::add($book, 'book_update', $book->id);
128 return redirect($book->getUrl()); 114 return redirect($book->getUrl());
129 } 115 }
...@@ -150,7 +136,7 @@ class BookController extends Controller ...@@ -150,7 +136,7 @@ class BookController extends Controller
150 { 136 {
151 $book = $this->entityRepo->getBySlug('book', $bookSlug); 137 $book = $this->entityRepo->getBySlug('book', $bookSlug);
152 $this->checkOwnablePermission('book-update', $book); 138 $this->checkOwnablePermission('book-update', $book);
153 - $bookChildren = $this->bookRepo->getChildren($book, true); 139 + $bookChildren = $this->entityRepo->getBookChildren($book, true);
154 $books = $this->entityRepo->getAll('book', false); 140 $books = $this->entityRepo->getAll('book', false);
155 $this->setPageTitle(trans('entities.books_sort_named', ['bookName'=>$book->getShortName()])); 141 $this->setPageTitle(trans('entities.books_sort_named', ['bookName'=>$book->getShortName()]));
156 return view('books/sort', ['book' => $book, 'current' => $book, 'books' => $books, 'bookChildren' => $bookChildren]); 142 return view('books/sort', ['book' => $book, 'current' => $book, 'books' => $books, 'bookChildren' => $bookChildren]);
...@@ -165,7 +151,7 @@ class BookController extends Controller ...@@ -165,7 +151,7 @@ class BookController extends Controller
165 public function getSortItem($bookSlug) 151 public function getSortItem($bookSlug)
166 { 152 {
167 $book = $this->entityRepo->getBySlug('book', $bookSlug); 153 $book = $this->entityRepo->getBySlug('book', $bookSlug);
168 - $bookChildren = $this->bookRepo->getChildren($book); 154 + $bookChildren = $this->entityRepo->getBookChildren($book);
169 return view('books/sort-box', ['book' => $book, 'bookChildren' => $bookChildren]); 155 return view('books/sort-box', ['book' => $book, 'bookChildren' => $bookChildren]);
170 } 156 }
171 157
...@@ -202,7 +188,7 @@ class BookController extends Controller ...@@ -202,7 +188,7 @@ class BookController extends Controller
202 188
203 // Update models only if there's a change in parent chain or ordering. 189 // Update models only if there's a change in parent chain or ordering.
204 if ($model->priority !== $priority || $model->book_id !== $bookId || ($isPage && $model->chapter_id !== $chapterId)) { 190 if ($model->priority !== $priority || $model->book_id !== $bookId || ($isPage && $model->chapter_id !== $chapterId)) {
205 - $isPage ? $this->pageRepo->changeBook($bookId, $model) : $this->chapterRepo->changeBook($bookId, $model); 191 + $this->entityRepo->changeBook($isPage?'page':'chapter', $bookId, $model);
206 $model->priority = $priority; 192 $model->priority = $priority;
207 if ($isPage) $model->chapter_id = $chapterId; 193 if ($isPage) $model->chapter_id = $chapterId;
208 $model->save(); 194 $model->save();
...@@ -222,7 +208,7 @@ class BookController extends Controller ...@@ -222,7 +208,7 @@ class BookController extends Controller
222 } 208 }
223 209
224 // Update permissions on changed models 210 // Update permissions on changed models
225 - $this->bookRepo->buildJointPermissions($updatedModels); 211 + $this->entityRepo->buildJointPermissions($updatedModels);
226 212
227 return redirect($book->getUrl()); 213 return redirect($book->getUrl());
228 } 214 }
...@@ -237,8 +223,7 @@ class BookController extends Controller ...@@ -237,8 +223,7 @@ class BookController extends Controller
237 $book = $this->entityRepo->getBySlug('book', $bookSlug); 223 $book = $this->entityRepo->getBySlug('book', $bookSlug);
238 $this->checkOwnablePermission('book-delete', $book); 224 $this->checkOwnablePermission('book-delete', $book);
239 Activity::addMessage('book_delete', 0, $book->name); 225 Activity::addMessage('book_delete', 0, $book->name);
240 - Activity::removeEntity($book); 226 + $this->entityRepo->destroyBook($book);
241 - $this->bookRepo->destroy($book);
242 return redirect('/books'); 227 return redirect('/books');
243 } 228 }
244 229
...@@ -269,7 +254,7 @@ class BookController extends Controller ...@@ -269,7 +254,7 @@ class BookController extends Controller
269 { 254 {
270 $book = $this->entityRepo->getBySlug('book', $bookSlug); 255 $book = $this->entityRepo->getBySlug('book', $bookSlug);
271 $this->checkOwnablePermission('restrictions-manage', $book); 256 $this->checkOwnablePermission('restrictions-manage', $book);
272 - $this->bookRepo->updateEntityPermissionsFromRequest($request, $book); 257 + $this->entityRepo->updateEntityPermissionsFromRequest($request, $book);
273 session()->flash('success', trans('entities.books_permissions_updated')); 258 session()->flash('success', trans('entities.books_permissions_updated'));
274 return redirect($book->getUrl()); 259 return redirect($book->getUrl());
275 } 260 }
......
...@@ -4,32 +4,23 @@ use Activity; ...@@ -4,32 +4,23 @@ use Activity;
4 use BookStack\Repos\EntityRepo; 4 use BookStack\Repos\EntityRepo;
5 use BookStack\Repos\UserRepo; 5 use BookStack\Repos\UserRepo;
6 use Illuminate\Http\Request; 6 use Illuminate\Http\Request;
7 -use BookStack\Repos\BookRepo;
8 -use BookStack\Repos\ChapterRepo;
9 use Illuminate\Http\Response; 7 use Illuminate\Http\Response;
10 use Views; 8 use Views;
11 9
12 class ChapterController extends Controller 10 class ChapterController extends Controller
13 { 11 {
14 12
15 - protected $bookRepo;
16 - protected $chapterRepo;
17 protected $userRepo; 13 protected $userRepo;
18 protected $entityRepo; 14 protected $entityRepo;
19 15
20 /** 16 /**
21 * ChapterController constructor. 17 * ChapterController constructor.
22 * @param EntityRepo $entityRepo 18 * @param EntityRepo $entityRepo
23 - * @param BookRepo $bookRepo
24 - * @param ChapterRepo $chapterRepo
25 * @param UserRepo $userRepo 19 * @param UserRepo $userRepo
26 */ 20 */
27 - public function __construct(EntityRepo $entityRepo, BookRepo $bookRepo, ChapterRepo $chapterRepo, UserRepo $userRepo) 21 + public function __construct(EntityRepo $entityRepo, UserRepo $userRepo)
28 { 22 {
29 $this->entityRepo = $entityRepo; 23 $this->entityRepo = $entityRepo;
30 - // TODO - Remove below
31 - $this->bookRepo = $bookRepo;
32 - $this->chapterRepo = $chapterRepo;
33 $this->userRepo = $userRepo; 24 $this->userRepo = $userRepo;
34 parent::__construct(); 25 parent::__construct();
35 } 26 }
...@@ -63,8 +54,8 @@ class ChapterController extends Controller ...@@ -63,8 +54,8 @@ class ChapterController extends Controller
63 $this->checkOwnablePermission('chapter-create', $book); 54 $this->checkOwnablePermission('chapter-create', $book);
64 55
65 $input = $request->all(); 56 $input = $request->all();
66 - $input['priority'] = $this->bookRepo->getNewPriority($book); 57 + $input['priority'] = $this->entityRepo->getNewBookPriority($book);
67 - $chapter = $this->chapterRepo->createFromInput($input, $book); 58 + $chapter = $this->entityRepo->createFromInput('chapter', $input, $book);
68 Activity::add($chapter, 'chapter_create', $book->id); 59 Activity::add($chapter, 'chapter_create', $book->id);
69 return redirect($chapter->getUrl()); 60 return redirect($chapter->getUrl());
70 } 61 }
...@@ -79,10 +70,10 @@ class ChapterController extends Controller ...@@ -79,10 +70,10 @@ class ChapterController extends Controller
79 { 70 {
80 $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug); 71 $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
81 $this->checkOwnablePermission('chapter-view', $chapter); 72 $this->checkOwnablePermission('chapter-view', $chapter);
82 - $sidebarTree = $this->bookRepo->getChildren($chapter->book); 73 + $sidebarTree = $this->entityRepo->getBookChildren($chapter->book);
83 Views::add($chapter); 74 Views::add($chapter);
84 $this->setPageTitle($chapter->getShortName()); 75 $this->setPageTitle($chapter->getShortName());
85 - $pages = $this->chapterRepo->getChildren($chapter); 76 + $pages = $this->entityRepo->getChapterChildren($chapter);
86 return view('chapters/show', [ 77 return view('chapters/show', [
87 'book' => $chapter->book, 78 'book' => $chapter->book,
88 'chapter' => $chapter, 79 'chapter' => $chapter,
...@@ -153,7 +144,7 @@ class ChapterController extends Controller ...@@ -153,7 +144,7 @@ class ChapterController extends Controller
153 $book = $chapter->book; 144 $book = $chapter->book;
154 $this->checkOwnablePermission('chapter-delete', $chapter); 145 $this->checkOwnablePermission('chapter-delete', $chapter);
155 Activity::addMessage('chapter_delete', $book->id, $chapter->name); 146 Activity::addMessage('chapter_delete', $book->id, $chapter->name);
156 - $this->chapterRepo->destroy($chapter); 147 + $this->entityRepo->destroyChapter($chapter);
157 return redirect($book->getUrl()); 148 return redirect($book->getUrl());
158 } 149 }
159 150
...@@ -206,7 +197,7 @@ class ChapterController extends Controller ...@@ -206,7 +197,7 @@ class ChapterController extends Controller
206 return redirect()->back(); 197 return redirect()->back();
207 } 198 }
208 199
209 - $this->chapterRepo->changeBook($parent->id, $chapter, true); 200 + $this->entityRepo->changeBook('chapter', $parent->id, $chapter, true);
210 Activity::add($chapter, 'chapter_move', $chapter->book->id); 201 Activity::add($chapter, 'chapter_move', $chapter->book->id);
211 session()->flash('success', trans('entities.chapter_move_success', ['bookName' => $parent->name])); 202 session()->flash('success', trans('entities.chapter_move_success', ['bookName' => $parent->name]));
212 203
...@@ -241,7 +232,7 @@ class ChapterController extends Controller ...@@ -241,7 +232,7 @@ class ChapterController extends Controller
241 { 232 {
242 $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug); 233 $chapter = $this->entityRepo->getBySlug('chapter', $chapterSlug, $bookSlug);
243 $this->checkOwnablePermission('restrictions-manage', $chapter); 234 $this->checkOwnablePermission('restrictions-manage', $chapter);
244 - $this->chapterRepo->updateEntityPermissionsFromRequest($request, $chapter); 235 + $this->entityRepo->updateEntityPermissionsFromRequest($request, $chapter);
245 session()->flash('success', trans('entities.chapters_permissions_success')); 236 session()->flash('success', trans('entities.chapters_permissions_success'));
246 return redirect($chapter->getUrl()); 237 return redirect($chapter->getUrl());
247 } 238 }
......
1 <?php namespace BookStack\Http\Controllers; 1 <?php namespace BookStack\Http\Controllers;
2 2
3 use BookStack\Exceptions\ImageUploadException; 3 use BookStack\Exceptions\ImageUploadException;
4 +use BookStack\Repos\EntityRepo;
4 use BookStack\Repos\ImageRepo; 5 use BookStack\Repos\ImageRepo;
5 use Illuminate\Filesystem\Filesystem as File; 6 use Illuminate\Filesystem\Filesystem as File;
6 use Illuminate\Http\Request; 7 use Illuminate\Http\Request;
...@@ -150,12 +151,12 @@ class ImageController extends Controller ...@@ -150,12 +151,12 @@ class ImageController extends Controller
150 151
151 /** 152 /**
152 * Deletes an image and all thumbnail/image files 153 * Deletes an image and all thumbnail/image files
153 - * @param PageRepo $pageRepo 154 + * @param EntityRepo $entityRepo
154 * @param Request $request 155 * @param Request $request
155 * @param int $id 156 * @param int $id
156 * @return \Illuminate\Http\JsonResponse 157 * @return \Illuminate\Http\JsonResponse
157 */ 158 */
158 - public function destroy(PageRepo $pageRepo, Request $request, $id) 159 + public function destroy(EntityRepo $entityRepo, Request $request, $id)
159 { 160 {
160 $image = $this->imageRepo->getById($id); 161 $image = $this->imageRepo->getById($id);
161 $this->checkOwnablePermission('image-delete', $image); 162 $this->checkOwnablePermission('image-delete', $image);
...@@ -163,7 +164,7 @@ class ImageController extends Controller ...@@ -163,7 +164,7 @@ class ImageController extends Controller
163 // Check if this image is used on any pages 164 // Check if this image is used on any pages
164 $isForced = ($request->has('force') && ($request->get('force') === 'true') || $request->get('force') === true); 165 $isForced = ($request->has('force') && ($request->get('force') === 'true') || $request->get('force') === true);
165 if (!$isForced) { 166 if (!$isForced) {
166 - $pageSearch = $pageRepo->searchForImage($image->url); 167 + $pageSearch = $entityRepo->searchForImage($image->url);
167 if ($pageSearch !== false) { 168 if ($pageSearch !== false) {
168 return response()->json($pageSearch, 400); 169 return response()->json($pageSearch, 400);
169 } 170 }
......
...@@ -7,9 +7,6 @@ use BookStack\Repos\UserRepo; ...@@ -7,9 +7,6 @@ use BookStack\Repos\UserRepo;
7 use BookStack\Services\ExportService; 7 use BookStack\Services\ExportService;
8 use Carbon\Carbon; 8 use Carbon\Carbon;
9 use Illuminate\Http\Request; 9 use Illuminate\Http\Request;
10 -use BookStack\Repos\BookRepo;
11 -use BookStack\Repos\ChapterRepo;
12 -use BookStack\Repos\PageRepo;
13 use Illuminate\Http\Response; 10 use Illuminate\Http\Response;
14 use Views; 11 use Views;
15 use GatherContent\Htmldiff\Htmldiff; 12 use GatherContent\Htmldiff\Htmldiff;
...@@ -18,28 +15,18 @@ class PageController extends Controller ...@@ -18,28 +15,18 @@ class PageController extends Controller
18 { 15 {
19 16
20 protected $entityRepo; 17 protected $entityRepo;
21 - protected $pageRepo;
22 - protected $bookRepo;
23 - protected $chapterRepo;
24 protected $exportService; 18 protected $exportService;
25 protected $userRepo; 19 protected $userRepo;
26 20
27 /** 21 /**
28 * PageController constructor. 22 * PageController constructor.
29 * @param EntityRepo $entityRepo 23 * @param EntityRepo $entityRepo
30 - * @param PageRepo $pageRepo
31 - * @param BookRepo $bookRepo
32 - * @param ChapterRepo $chapterRepo
33 * @param ExportService $exportService 24 * @param ExportService $exportService
34 * @param UserRepo $userRepo 25 * @param UserRepo $userRepo
35 */ 26 */
36 - public function __construct(EntityRepo $entityRepo, PageRepo $pageRepo, BookRepo $bookRepo, ChapterRepo $chapterRepo, ExportService $exportService, UserRepo $userRepo) 27 + public function __construct(EntityRepo $entityRepo, ExportService $exportService, UserRepo $userRepo)
37 { 28 {
38 $this->entityRepo = $entityRepo; 29 $this->entityRepo = $entityRepo;
39 - // TODO - remove below;
40 - $this->pageRepo = $pageRepo;
41 - $this->bookRepo = $bookRepo;
42 - $this->chapterRepo = $chapterRepo;
43 $this->exportService = $exportService; 30 $this->exportService = $exportService;
44 $this->userRepo = $userRepo; 31 $this->userRepo = $userRepo;
45 parent::__construct(); 32 parent::__construct();
...@@ -61,7 +48,7 @@ class PageController extends Controller ...@@ -61,7 +48,7 @@ class PageController extends Controller
61 48
62 // Redirect to draft edit screen if signed in 49 // Redirect to draft edit screen if signed in
63 if ($this->signedIn) { 50 if ($this->signedIn) {
64 - $draft = $this->pageRepo->getDraftPage($book, $chapter); 51 + $draft = $this->entityRepo->getDraftPage($book, $chapter);
65 return redirect($draft->getUrl()); 52 return redirect($draft->getUrl());
66 } 53 }
67 54
...@@ -89,8 +76,8 @@ class PageController extends Controller ...@@ -89,8 +76,8 @@ class PageController extends Controller
89 $parent = $chapter ? $chapter : $book; 76 $parent = $chapter ? $chapter : $book;
90 $this->checkOwnablePermission('page-create', $parent); 77 $this->checkOwnablePermission('page-create', $parent);
91 78
92 - $page = $this->pageRepo->getDraftPage($book, $chapter); 79 + $page = $this->entityRepo->getDraftPage($book, $chapter);
93 - $this->pageRepo->publishDraft($page, [ 80 + $this->entityRepo->publishPageDraft($page, [
94 'name' => $request->get('name'), 81 'name' => $request->get('name'),
95 'html' => '' 82 'html' => ''
96 ]); 83 ]);
...@@ -141,12 +128,12 @@ class PageController extends Controller ...@@ -141,12 +128,12 @@ class PageController extends Controller
141 $this->checkOwnablePermission('page-create', $parent); 128 $this->checkOwnablePermission('page-create', $parent);
142 129
143 if ($parent->isA('chapter')) { 130 if ($parent->isA('chapter')) {
144 - $input['priority'] = $this->chapterRepo->getNewPriority($parent); 131 + $input['priority'] = $this->entityRepo->getNewChapterPriority($parent);
145 } else { 132 } else {
146 - $input['priority'] = $this->bookRepo->getNewPriority($parent); 133 + $input['priority'] = $this->entityRepo->getNewBookPriority($parent);
147 } 134 }
148 135
149 - $page = $this->pageRepo->publishDraft($draftPage, $input); 136 + $page = $this->entityRepo->publishPageDraft($draftPage, $input);
150 137
151 Activity::add($page, 'page_create', $book->id); 138 Activity::add($page, 'page_create', $book->id);
152 return redirect($page->getUrl()); 139 return redirect($page->getUrl());
...@@ -164,15 +151,15 @@ class PageController extends Controller ...@@ -164,15 +151,15 @@ class PageController extends Controller
164 try { 151 try {
165 $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug); 152 $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
166 } catch (NotFoundException $e) { 153 } catch (NotFoundException $e) {
167 - $page = $this->pageRepo->findPageUsingOldSlug($pageSlug, $bookSlug); 154 + $page = $this->entityRepo->getPageByOldSlug($pageSlug, $bookSlug);
168 if ($page === null) abort(404); 155 if ($page === null) abort(404);
169 return redirect($page->getUrl()); 156 return redirect($page->getUrl());
170 } 157 }
171 158
172 $this->checkOwnablePermission('page-view', $page); 159 $this->checkOwnablePermission('page-view', $page);
173 160
174 - $sidebarTree = $this->bookRepo->getChildren($page->book); 161 + $sidebarTree = $this->entityRepo->getBookChildren($page->book);
175 - $pageNav = $this->pageRepo->getPageNav($page); 162 + $pageNav = $this->entityRepo->getPageNav($page);
176 163
177 Views::add($page); 164 Views::add($page);
178 $this->setPageTitle($page->getShortName()); 165 $this->setPageTitle($page->getShortName());
...@@ -206,18 +193,18 @@ class PageController extends Controller ...@@ -206,18 +193,18 @@ class PageController extends Controller
206 193
207 // Check for active editing 194 // Check for active editing
208 $warnings = []; 195 $warnings = [];
209 - if ($this->pageRepo->isPageEditingActive($page, 60)) { 196 + if ($this->entityRepo->isPageEditingActive($page, 60)) {
210 - $warnings[] = $this->pageRepo->getPageEditingActiveMessage($page, 60); 197 + $warnings[] = $this->entityRepo->getPageEditingActiveMessage($page, 60);
211 } 198 }
212 199
213 // Check for a current draft version for this user 200 // Check for a current draft version for this user
214 - if ($this->pageRepo->hasUserGotPageDraft($page, $this->currentUser->id)) { 201 + if ($this->entityRepo->hasUserGotPageDraft($page, $this->currentUser->id)) {
215 - $draft = $this->pageRepo->getUserPageDraft($page, $this->currentUser->id); 202 + $draft = $this->entityRepo->getUserPageDraft($page, $this->currentUser->id);
216 $page->name = $draft->name; 203 $page->name = $draft->name;
217 $page->html = $draft->html; 204 $page->html = $draft->html;
218 $page->markdown = $draft->markdown; 205 $page->markdown = $draft->markdown;
219 $page->isDraft = true; 206 $page->isDraft = true;
220 - $warnings [] = $this->pageRepo->getUserPageDraftMessage($draft); 207 + $warnings [] = $this->entityRepo->getUserPageDraftMessage($draft);
221 } 208 }
222 209
223 if (count($warnings) > 0) session()->flash('warning', implode("\n", $warnings)); 210 if (count($warnings) > 0) session()->flash('warning', implode("\n", $warnings));
...@@ -245,7 +232,7 @@ class PageController extends Controller ...@@ -245,7 +232,7 @@ class PageController extends Controller
245 ]); 232 ]);
246 $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug); 233 $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
247 $this->checkOwnablePermission('page-update', $page); 234 $this->checkOwnablePermission('page-update', $page);
248 - $this->pageRepo->updatePage($page, $page->book->id, $request->all()); 235 + $this->entityRepo->updatePage($page, $page->book->id, $request->all());
249 Activity::add($page, 'page_update', $page->book->id); 236 Activity::add($page, 'page_update', $page->book->id);
250 return redirect($page->getUrl()); 237 return redirect($page->getUrl());
251 } 238 }
...@@ -268,11 +255,7 @@ class PageController extends Controller ...@@ -268,11 +255,7 @@ class PageController extends Controller
268 ], 500); 255 ], 500);
269 } 256 }
270 257
271 - if ($page->draft) { 258 + $draft = $this->entityRepo->updatePageDraft($page, $request->only(['name', 'html', 'markdown']));
272 - $draft = $this->pageRepo->updateDraftPage($page, $request->only(['name', 'html', 'markdown']));
273 - } else {
274 - $draft = $this->pageRepo->saveUpdateDraft($page, $request->only(['name', 'html', 'markdown']));
275 - }
276 259
277 $updateTime = $draft->updated_at->timestamp; 260 $updateTime = $draft->updated_at->timestamp;
278 $utcUpdateTimestamp = $updateTime + Carbon::createFromTimestamp(0)->offset; 261 $utcUpdateTimestamp = $updateTime + Carbon::createFromTimestamp(0)->offset;
...@@ -339,7 +322,7 @@ class PageController extends Controller ...@@ -339,7 +322,7 @@ class PageController extends Controller
339 $this->checkOwnablePermission('page-delete', $page); 322 $this->checkOwnablePermission('page-delete', $page);
340 Activity::addMessage('page_delete', $book->id, $page->name); 323 Activity::addMessage('page_delete', $book->id, $page->name);
341 session()->flash('success', trans('entities.pages_delete_success')); 324 session()->flash('success', trans('entities.pages_delete_success'));
342 - $this->pageRepo->destroy($page); 325 + $this->entityRepo->destroyPage($page);
343 return redirect($book->getUrl()); 326 return redirect($book->getUrl());
344 } 327 }
345 328
...@@ -356,7 +339,7 @@ class PageController extends Controller ...@@ -356,7 +339,7 @@ class PageController extends Controller
356 $book = $page->book; 339 $book = $page->book;
357 $this->checkOwnablePermission('page-update', $page); 340 $this->checkOwnablePermission('page-update', $page);
358 session()->flash('success', trans('entities.pages_delete_draft_success')); 341 session()->flash('success', trans('entities.pages_delete_draft_success'));
359 - $this->pageRepo->destroy($page); 342 + $this->entityRepo->destroyPage($page);
360 return redirect($book->getUrl()); 343 return redirect($book->getUrl());
361 } 344 }
362 345
...@@ -383,7 +366,7 @@ class PageController extends Controller ...@@ -383,7 +366,7 @@ class PageController extends Controller
383 public function showRevision($bookSlug, $pageSlug, $revisionId) 366 public function showRevision($bookSlug, $pageSlug, $revisionId)
384 { 367 {
385 $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug); 368 $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
386 - $revision = $this->pageRepo->getRevisionById($revisionId); 369 + $revision = $this->entityRepo->getById('page_revision', $revisionId, false);
387 370
388 $page->fill($revision->toArray()); 371 $page->fill($revision->toArray());
389 $this->setPageTitle(trans('entities.pages_revision_named', ['pageName'=>$page->getShortName()])); 372 $this->setPageTitle(trans('entities.pages_revision_named', ['pageName'=>$page->getShortName()]));
...@@ -404,7 +387,7 @@ class PageController extends Controller ...@@ -404,7 +387,7 @@ class PageController extends Controller
404 public function showRevisionChanges($bookSlug, $pageSlug, $revisionId) 387 public function showRevisionChanges($bookSlug, $pageSlug, $revisionId)
405 { 388 {
406 $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug); 389 $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
407 - $revision = $this->pageRepo->getRevisionById($revisionId); 390 + $revision = $this->entityRepo->getById('page_revision', $revisionId);
408 391
409 $prev = $revision->getPrevious(); 392 $prev = $revision->getPrevious();
410 $prevContent = ($prev === null) ? '' : $prev->html; 393 $prevContent = ($prev === null) ? '' : $prev->html;
...@@ -431,7 +414,7 @@ class PageController extends Controller ...@@ -431,7 +414,7 @@ class PageController extends Controller
431 { 414 {
432 $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug); 415 $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
433 $this->checkOwnablePermission('page-update', $page); 416 $this->checkOwnablePermission('page-update', $page);
434 - $page = $this->pageRepo->restoreRevision($page, $page->book, $revisionId); 417 + $page = $this->entityRepo->restorePageRevision($page, $page->book, $revisionId);
435 Activity::add($page, 'page_restore', $page->book->id); 418 Activity::add($page, 'page_restore', $page->book->id);
436 return redirect($page->getUrl()); 419 return redirect($page->getUrl());
437 } 420 }
...@@ -491,7 +474,7 @@ class PageController extends Controller ...@@ -491,7 +474,7 @@ class PageController extends Controller
491 */ 474 */
492 public function showRecentlyCreated() 475 public function showRecentlyCreated()
493 { 476 {
494 - $pages = $this->pageRepo->getRecentlyCreatedPaginated(20)->setPath(baseUrl('/pages/recently-created')); 477 + $pages = $this->entityRepo->getRecentlyCreatedPaginated('page', 20)->setPath(baseUrl('/pages/recently-created'));
495 return view('pages/detailed-listing', [ 478 return view('pages/detailed-listing', [
496 'title' => trans('entities.recently_created_pages'), 479 'title' => trans('entities.recently_created_pages'),
497 'pages' => $pages 480 'pages' => $pages
...@@ -504,7 +487,7 @@ class PageController extends Controller ...@@ -504,7 +487,7 @@ class PageController extends Controller
504 */ 487 */
505 public function showRecentlyUpdated() 488 public function showRecentlyUpdated()
506 { 489 {
507 - $pages = $this->pageRepo->getRecentlyUpdatedPaginated(20)->setPath(baseUrl('/pages/recently-updated')); 490 + $pages = $this->entityRepo->getRecentlyUpdatedPaginated('page', 20)->setPath(baseUrl('/pages/recently-updated'));
508 return view('pages/detailed-listing', [ 491 return view('pages/detailed-listing', [
509 'title' => trans('entities.recently_updated_pages'), 492 'title' => trans('entities.recently_updated_pages'),
510 'pages' => $pages 493 'pages' => $pages
...@@ -575,7 +558,7 @@ class PageController extends Controller ...@@ -575,7 +558,7 @@ class PageController extends Controller
575 return redirect()->back(); 558 return redirect()->back();
576 } 559 }
577 560
578 - $this->pageRepo->changePageParent($page, $parent); 561 + $this->entityRepo->changePageParent($page, $parent);
579 Activity::add($page, 'page_move', $page->book->id); 562 Activity::add($page, 'page_move', $page->book->id);
580 session()->flash('success', trans('entities.pages_move_success', ['parentName' => $parent->name])); 563 session()->flash('success', trans('entities.pages_move_success', ['parentName' => $parent->name]));
581 564
...@@ -593,7 +576,7 @@ class PageController extends Controller ...@@ -593,7 +576,7 @@ class PageController extends Controller
593 { 576 {
594 $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug); 577 $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
595 $this->checkOwnablePermission('restrictions-manage', $page); 578 $this->checkOwnablePermission('restrictions-manage', $page);
596 - $this->pageRepo->updateEntityPermissionsFromRequest($request, $page); 579 + $this->entityRepo->updateEntityPermissionsFromRequest($request, $page);
597 session()->flash('success', trans('entities.pages_permissions_success')); 580 session()->flash('success', trans('entities.pages_permissions_success'));
598 return redirect($page->getUrl()); 581 return redirect($page->getUrl());
599 } 582 }
......
1 -<?php namespace BookStack\Repos;
2 -
3 -use BookStack\Book;
4 -
5 -class BookRepo extends EntityRepo
6 -{
7 - protected $pageRepo;
8 - protected $chapterRepo;
9 -
10 - /**
11 - * BookRepo constructor.
12 - * @param PageRepo $pageRepo
13 - * @param ChapterRepo $chapterRepo
14 - */
15 - public function __construct(PageRepo $pageRepo, ChapterRepo $chapterRepo)
16 - {
17 - $this->pageRepo = $pageRepo;
18 - $this->chapterRepo = $chapterRepo;
19 - parent::__construct();
20 - }
21 -
22 - /**
23 - * Get a new book instance from request input.
24 - * @param array $input
25 - * @return Book
26 - */
27 - public function createFromInput($input)
28 - {
29 - $book = $this->book->newInstance($input);
30 - $book->slug = $this->findSuitableSlug('book', $book->name);
31 - $book->created_by = user()->id;
32 - $book->updated_by = user()->id;
33 - $book->save();
34 - $this->permissionService->buildJointPermissionsForEntity($book);
35 - return $book;
36 - }
37 -
38 - /**
39 - * Update the given book from user input.
40 - * @param Book $book
41 - * @param $input
42 - * @return Book
43 - */
44 - public function updateFromInput(Book $book, $input)
45 - {
46 - if ($book->name !== $input['name']) {
47 - $book->slug = $this->findSuitableSlug('book', $input['name'], $book->id);
48 - }
49 - $book->fill($input);
50 - $book->updated_by = user()->id;
51 - $book->save();
52 - $this->permissionService->buildJointPermissionsForEntity($book);
53 - return $book;
54 - }
55 -
56 - /**
57 - * Destroy the given book.
58 - * @param Book $book
59 - * @throws \Exception
60 - */
61 - public function destroy(Book $book)
62 - {
63 - foreach ($book->pages as $page) {
64 - $this->pageRepo->destroy($page);
65 - }
66 - foreach ($book->chapters as $chapter) {
67 - $this->chapterRepo->destroy($chapter);
68 - }
69 - $book->views()->delete();
70 - $book->permissions()->delete();
71 - $this->permissionService->deleteJointPermissionsForEntity($book);
72 - $book->delete();
73 - }
74 -
75 - /**
76 - * Get the next child element priority.
77 - * @param Book $book
78 - * @return int
79 - */
80 - public function getNewPriority($book)
81 - {
82 - $lastElem = $this->getChildren($book)->pop();
83 - return $lastElem ? $lastElem->priority + 1 : 0;
84 - }
85 -
86 - /**
87 - * Get all child objects of a book.
88 - * Returns a sorted collection of Pages and Chapters.
89 - * Loads the book slug onto child elements to prevent access database access for getting the slug.
90 - * @param Book $book
91 - * @param bool $filterDrafts
92 - * @return mixed
93 - */
94 - public function getChildren(Book $book, $filterDrafts = false)
95 - {
96 - $q = $this->permissionService->bookChildrenQuery($book->id, $filterDrafts);
97 - $entities = [];
98 - $parents = [];
99 - $tree = [];
100 -
101 - foreach ($q as $index => $rawEntity) {
102 - if ($rawEntity->entity_type === 'Bookstack\\Page') {
103 - $entities[$index] = $this->page->newFromBuilder($rawEntity);
104 - } else if ($rawEntity->entity_type === 'Bookstack\\Chapter') {
105 - $entities[$index] = $this->chapter->newFromBuilder($rawEntity);
106 - $key = $entities[$index]->entity_type . ':' . $entities[$index]->id;
107 - $parents[$key] = $entities[$index];
108 - $parents[$key]->setAttribute('pages', collect());
109 - }
110 - if ($entities[$index]->chapter_id === 0) $tree[] = $entities[$index];
111 - $entities[$index]->book = $book;
112 - }
113 -
114 - foreach ($entities as $entity) {
115 - if ($entity->chapter_id === 0) continue;
116 - $parentKey = 'Bookstack\\Chapter:' . $entity->chapter_id;
117 - $chapter = $parents[$parentKey];
118 - $chapter->pages->push($entity);
119 - }
120 -
121 - return collect($tree);
122 - }
123 -
124 -}
...\ No newline at end of file ...\ No newline at end of file
1 -<?php namespace BookStack\Repos;
2 -
3 -
4 -use Activity;
5 -use BookStack\Book;
6 -use BookStack\Exceptions\NotFoundException;
7 -use Illuminate\Support\Str;
8 -use BookStack\Chapter;
9 -
10 -class ChapterRepo extends EntityRepo
11 -{
12 - protected $pageRepo;
13 -
14 - /**
15 - * ChapterRepo constructor.
16 - * @param $pageRepo
17 - */
18 - public function __construct(PageRepo $pageRepo)
19 - {
20 - $this->pageRepo = $pageRepo;
21 - parent::__construct();
22 - }
23 -
24 - /**
25 - * Get the child items for a chapter
26 - * @param Chapter $chapter
27 - */
28 - public function getChildren(Chapter $chapter)
29 - {
30 - $pages = $this->permissionService->enforcePageRestrictions($chapter->pages())->get();
31 - // Sort items with drafts first then by priority.
32 - return $pages->sortBy(function ($child, $key) {
33 - $score = $child->priority;
34 - if ($child->draft) $score -= 100;
35 - return $score;
36 - });
37 - }
38 -
39 - /**
40 - * Create a new chapter from request input.
41 - * @param $input
42 - * @param Book $book
43 - * @return Chapter
44 - */
45 - public function createFromInput($input, Book $book)
46 - {
47 - $chapter = $this->chapter->newInstance($input);
48 - $chapter->slug = $this->findSuitableSlug('chapter', $chapter->name, false, $book->id);
49 - $chapter->created_by = user()->id;
50 - $chapter->updated_by = user()->id;
51 - $chapter = $book->chapters()->save($chapter);
52 - $this->permissionService->buildJointPermissionsForEntity($chapter);
53 - return $chapter;
54 - }
55 -
56 - /**
57 - * Destroy a chapter and its relations by providing its slug.
58 - * @param Chapter $chapter
59 - */
60 - public function destroy(Chapter $chapter)
61 - {
62 - if (count($chapter->pages) > 0) {
63 - foreach ($chapter->pages as $page) {
64 - $page->chapter_id = 0;
65 - $page->save();
66 - }
67 - }
68 - Activity::removeEntity($chapter);
69 - $chapter->views()->delete();
70 - $chapter->permissions()->delete();
71 - $this->permissionService->deleteJointPermissionsForEntity($chapter);
72 - $chapter->delete();
73 - }
74 -
75 -
76 - /**
77 - * Get a new priority value for a new page to be added
78 - * to the given chapter.
79 - * @param Chapter $chapter
80 - * @return int
81 - */
82 - public function getNewPriority(Chapter $chapter)
83 - {
84 - $lastPage = $chapter->pages->last();
85 - return $lastPage !== null ? $lastPage->priority + 1 : 0;
86 - }
87 -
88 - /**
89 - * Changes the book relation of this chapter.
90 - * @param $bookId
91 - * @param Chapter $chapter
92 - * @param bool $rebuildPermissions
93 - * @return Chapter
94 - */
95 - public function changeBook($bookId, Chapter $chapter, $rebuildPermissions = false)
96 - {
97 - $chapter->book_id = $bookId;
98 - // Update related activity
99 - foreach ($chapter->activity as $activity) {
100 - $activity->book_id = $bookId;
101 - $activity->save();
102 - }
103 - $chapter->slug = $this->findSuitableSlug('chapter', $chapter->name, $chapter->id, $bookId);
104 - $chapter->save();
105 - // Update all child pages
106 - foreach ($chapter->pages as $page) {
107 - $this->pageRepo->changeBook($bookId, $page);
108 - }
109 -
110 - // Update permissions if applicable
111 - if ($rebuildPermissions) {
112 - $chapter->load('book');
113 - $this->permissionService->buildJointPermissionsForEntity($chapter->book);
114 - }
115 -
116 - return $chapter;
117 - }
118 -
119 -}
...\ No newline at end of file ...\ No newline at end of file
...@@ -38,7 +38,7 @@ class TagRepo ...@@ -38,7 +38,7 @@ class TagRepo
38 { 38 {
39 $entityInstance = $this->entity->getEntityInstance($entityType); 39 $entityInstance = $this->entity->getEntityInstance($entityType);
40 $searchQuery = $entityInstance->where('id', '=', $entityId)->with('tags'); 40 $searchQuery = $entityInstance->where('id', '=', $entityId)->with('tags');
41 - $searchQuery = $this->permissionService->enforceEntityRestrictions($searchQuery, $action); 41 + $searchQuery = $this->permissionService->enforceEntityRestrictions($entityType, $searchQuery, $action);
42 return $searchQuery->first(); 42 return $searchQuery->first();
43 } 43 }
44 44
......
...@@ -517,42 +517,6 @@ ORDER BY draft desc, priority asc"; ...@@ -517,42 +517,6 @@ ORDER BY draft desc, priority asc";
517 } 517 }
518 518
519 /** 519 /**
520 - * Add restrictions for a page query
521 - * @param $query
522 - * @param string $action
523 - * @return mixed
524 - */
525 - public function enforcePageRestrictions($query, $action = 'view')
526 - {
527 - // TODO - remove this
528 - return $this->enforceEntityRestrictions('page', $query, $action);
529 - }
530 -
531 - /**
532 - * Add on permission restrictions to a chapter query.
533 - * @param $query
534 - * @param string $action
535 - * @return mixed
536 - */
537 - public function enforceChapterRestrictions($query, $action = 'view')
538 - {
539 - // TODO - remove this
540 - return $this->enforceEntityRestrictions('chapter', $query, $action);
541 - }
542 -
543 - /**
544 - * Add restrictions to a book query.
545 - * @param $query
546 - * @param string $action
547 - * @return mixed
548 - */
549 - public function enforceBookRestrictions($query, $action = 'view')
550 - {
551 - // TODO - remove this
552 - return $this->enforceEntityRestrictions('book', $query, $action);
553 - }
554 -
555 - /**
556 * Add restrictions for a generic entity 520 * Add restrictions for a generic entity
557 * @param string $entityType 521 * @param string $entityType
558 * @param Builder|Entity $query 522 * @param Builder|Entity $query
......
...@@ -168,7 +168,7 @@ class EntityTest extends TestCase ...@@ -168,7 +168,7 @@ class EntityTest extends TestCase
168 $entities = $this->createEntityChainBelongingToUser($creator, $updater); 168 $entities = $this->createEntityChainBelongingToUser($creator, $updater);
169 $this->actingAs($creator); 169 $this->actingAs($creator);
170 app('BookStack\Repos\UserRepo')->destroy($creator); 170 app('BookStack\Repos\UserRepo')->destroy($creator);
171 - app('BookStack\Repos\PageRepo')->saveRevision($entities['page']); 171 + app('BookStack\Repos\EntityRepo')->savePageRevision($entities['page']);
172 172
173 $this->checkEntitiesViewable($entities); 173 $this->checkEntitiesViewable($entities);
174 } 174 }
...@@ -181,7 +181,7 @@ class EntityTest extends TestCase ...@@ -181,7 +181,7 @@ class EntityTest extends TestCase
181 $entities = $this->createEntityChainBelongingToUser($creator, $updater); 181 $entities = $this->createEntityChainBelongingToUser($creator, $updater);
182 $this->actingAs($updater); 182 $this->actingAs($updater);
183 app('BookStack\Repos\UserRepo')->destroy($updater); 183 app('BookStack\Repos\UserRepo')->destroy($updater);
184 - app('BookStack\Repos\PageRepo')->saveRevision($entities['page']); 184 + app('BookStack\Repos\EntityRepo')->savePageRevision($entities['page']);
185 185
186 $this->checkEntitiesViewable($entities); 186 $this->checkEntitiesViewable($entities);
187 } 187 }
......
...@@ -4,13 +4,13 @@ ...@@ -4,13 +4,13 @@
4 class PageDraftTest extends TestCase 4 class PageDraftTest extends TestCase
5 { 5 {
6 protected $page; 6 protected $page;
7 - protected $pageRepo; 7 + protected $entityRepo;
8 8
9 public function setUp() 9 public function setUp()
10 { 10 {
11 parent::setUp(); 11 parent::setUp();
12 $this->page = \BookStack\Page::first(); 12 $this->page = \BookStack\Page::first();
13 - $this->pageRepo = app('\BookStack\Repos\PageRepo'); 13 + $this->entityRepo = app('\BookStack\Repos\EntityRepo');
14 } 14 }
15 15
16 public function test_draft_content_shows_if_available() 16 public function test_draft_content_shows_if_available()
...@@ -20,7 +20,7 @@ class PageDraftTest extends TestCase ...@@ -20,7 +20,7 @@ class PageDraftTest extends TestCase
20 ->dontSeeInField('html', $addedContent); 20 ->dontSeeInField('html', $addedContent);
21 21
22 $newContent = $this->page->html . $addedContent; 22 $newContent = $this->page->html . $addedContent;
23 - $this->pageRepo->saveUpdateDraft($this->page, ['html' => $newContent]); 23 + $this->entityRepo->updatePageDraft($this->page, ['html' => $newContent]);
24 $this->asAdmin()->visit($this->page->getUrl() . '/edit') 24 $this->asAdmin()->visit($this->page->getUrl() . '/edit')
25 ->seeInField('html', $newContent); 25 ->seeInField('html', $newContent);
26 } 26 }
...@@ -33,7 +33,7 @@ class PageDraftTest extends TestCase ...@@ -33,7 +33,7 @@ class PageDraftTest extends TestCase
33 33
34 $newContent = $this->page->html . $addedContent; 34 $newContent = $this->page->html . $addedContent;
35 $newUser = $this->getEditor(); 35 $newUser = $this->getEditor();
36 - $this->pageRepo->saveUpdateDraft($this->page, ['html' => $newContent]); 36 + $this->entityRepo->updatePageDraft($this->page, ['html' => $newContent]);
37 $this->actingAs($newUser)->visit($this->page->getUrl() . '/edit') 37 $this->actingAs($newUser)->visit($this->page->getUrl() . '/edit')
38 ->dontSeeInField('html', $newContent); 38 ->dontSeeInField('html', $newContent);
39 } 39 }
...@@ -41,7 +41,7 @@ class PageDraftTest extends TestCase ...@@ -41,7 +41,7 @@ class PageDraftTest extends TestCase
41 public function test_alert_message_shows_if_editing_draft() 41 public function test_alert_message_shows_if_editing_draft()
42 { 42 {
43 $this->asAdmin(); 43 $this->asAdmin();
44 - $this->pageRepo->saveUpdateDraft($this->page, ['html' => 'test content']); 44 + $this->entityRepo->updatePageDraft($this->page, ['html' => 'test content']);
45 $this->asAdmin()->visit($this->page->getUrl() . '/edit') 45 $this->asAdmin()->visit($this->page->getUrl() . '/edit')
46 ->see('You are currently editing a draft'); 46 ->see('You are currently editing a draft');
47 } 47 }
...@@ -55,7 +55,7 @@ class PageDraftTest extends TestCase ...@@ -55,7 +55,7 @@ class PageDraftTest extends TestCase
55 55
56 $newContent = $this->page->html . $addedContent; 56 $newContent = $this->page->html . $addedContent;
57 $newUser = $this->getEditor(); 57 $newUser = $this->getEditor();
58 - $this->pageRepo->saveUpdateDraft($this->page, ['html' => $newContent]); 58 + $this->entityRepo->updatePageDraft($this->page, ['html' => $newContent]);
59 59
60 $this->actingAs($newUser) 60 $this->actingAs($newUser)
61 ->visit($this->page->getUrl() . '/edit') 61 ->visit($this->page->getUrl() . '/edit')
......
...@@ -13,8 +13,8 @@ class SortTest extends TestCase ...@@ -13,8 +13,8 @@ class SortTest extends TestCase
13 public function test_drafts_do_not_show_up() 13 public function test_drafts_do_not_show_up()
14 { 14 {
15 $this->asAdmin(); 15 $this->asAdmin();
16 - $pageRepo = app('\BookStack\Repos\PageRepo'); 16 + $entityRepo = app('\BookStack\Repos\EntityRepo');
17 - $draft = $pageRepo->getDraftPage($this->book); 17 + $draft = $entityRepo->getDraftPage($this->book);
18 18
19 $this->visit($this->book->getUrl()) 19 $this->visit($this->book->getUrl())
20 ->see($draft->name) 20 ->see($draft->name)
......
...@@ -90,7 +90,7 @@ class ImageTest extends TestCase ...@@ -90,7 +90,7 @@ class ImageTest extends TestCase
90 'type' => 'gallery' 90 'type' => 'gallery'
91 ]); 91 ]);
92 92
93 - $this->assertFalse(file_exists(public_path($relPath)), 'Uploaded image has been deleted'); 93 + $this->assertFalse(file_exists(public_path($relPath)), 'Uploaded image has not been deleted as expected');
94 } 94 }
95 95
96 } 96 }
...\ No newline at end of file ...\ No newline at end of file
......