1818use BookStack \Facades \Activity ;
1919use BookStack \References \ReferenceStore ;
2020use BookStack \References \ReferenceUpdater ;
21+ use BookStack \Util \DatabaseTransaction ;
2122use Exception ;
2223
2324class PageRepo
@@ -61,8 +62,10 @@ public function getNewDraftPage(Entity $parent)
6162 ]);
6263 }
6364
64- $ page ->save ();
65- $ page ->refresh ()->rebuildPermissions ();
65+ (new DatabaseTransaction (function () use ($ page ) {
66+ $ page ->save ();
67+ $ page ->refresh ()->rebuildPermissions ();
68+ }))->run ();
6669
6770 return $ page ;
6871 }
@@ -72,21 +75,23 @@ public function getNewDraftPage(Entity $parent)
7275 */
7376 public function publishDraft (Page $ draft , array $ input ): Page
7477 {
75- $ draft ->draft = false ;
76- $ draft ->revision_count = 1 ;
77- $ draft ->priority = $ this ->getNewPriority ($ draft );
78- $ this ->updateTemplateStatusAndContentFromInput ($ draft , $ input );
79- $ this ->baseRepo ->update ($ draft , $ input );
80- $ draft ->rebuildPermissions ();
81-
82- $ summary = trim ($ input ['summary ' ] ?? '' ) ?: trans ('entities.pages_initial_revision ' );
83- $ this ->revisionRepo ->storeNewForPage ($ draft , $ summary );
84- $ draft ->refresh ();
85-
86- Activity::add (ActivityType::PAGE_CREATE , $ draft );
87- $ this ->baseRepo ->sortParent ($ draft );
88-
89- return $ draft ;
78+ return (new DatabaseTransaction (function () use ($ draft , $ input ) {
79+ $ draft ->draft = false ;
80+ $ draft ->revision_count = 1 ;
81+ $ draft ->priority = $ this ->getNewPriority ($ draft );
82+ $ this ->updateTemplateStatusAndContentFromInput ($ draft , $ input );
83+ $ this ->baseRepo ->update ($ draft , $ input );
84+ $ draft ->rebuildPermissions ();
85+
86+ $ summary = trim ($ input ['summary ' ] ?? '' ) ?: trans ('entities.pages_initial_revision ' );
87+ $ this ->revisionRepo ->storeNewForPage ($ draft , $ summary );
88+ $ draft ->refresh ();
89+
90+ Activity::add (ActivityType::PAGE_CREATE , $ draft );
91+ $ this ->baseRepo ->sortParent ($ draft );
92+
93+ return $ draft ;
94+ }))->run ();
9095 }
9196
9297 /**
@@ -117,7 +122,7 @@ public function update(Page $page, array $input): Page
117122 $ page ->revision_count ++;
118123 $ page ->save ();
119124
120- // Remove all update drafts for this user & page.
125+ // Remove all update drafts for this user and page.
121126 $ this ->revisionRepo ->deleteDraftsForCurrentUser ($ page );
122127
123128 // Save a revision after updating
@@ -270,16 +275,18 @@ public function move(Page $page, string $parentIdentifier): Entity
270275 throw new PermissionsException ('User does not have permission to create a page within the new parent ' );
271276 }
272277
273- $ page ->chapter_id = ($ parent instanceof Chapter) ? $ parent ->id : null ;
274- $ newBookId = ($ parent instanceof Chapter) ? $ parent ->book ->id : $ parent ->id ;
275- $ page ->changeBook ($ newBookId );
276- $ page ->rebuildPermissions ();
278+ return (new DatabaseTransaction (function () use ($ page , $ parent ) {
279+ $ page ->chapter_id = ($ parent instanceof Chapter) ? $ parent ->id : null ;
280+ $ newBookId = ($ parent instanceof Chapter) ? $ parent ->book ->id : $ parent ->id ;
281+ $ page ->changeBook ($ newBookId );
282+ $ page ->rebuildPermissions ();
277283
278- Activity::add (ActivityType::PAGE_MOVE , $ page );
284+ Activity::add (ActivityType::PAGE_MOVE , $ page );
279285
280- $ this ->baseRepo ->sortParent ($ page );
286+ $ this ->baseRepo ->sortParent ($ page );
281287
282- return $ parent ;
288+ return $ parent ;
289+ }))->run ();
283290 }
284291
285292 /**
0 commit comments