18
18
use BookStack \Facades \Activity ;
19
19
use BookStack \References \ReferenceStore ;
20
20
use BookStack \References \ReferenceUpdater ;
21
+ use BookStack \Util \DatabaseTransaction ;
21
22
use Exception ;
22
23
23
24
class PageRepo
@@ -61,8 +62,10 @@ public function getNewDraftPage(Entity $parent)
61
62
]);
62
63
}
63
64
64
- $ page ->save ();
65
- $ page ->refresh ()->rebuildPermissions ();
65
+ (new DatabaseTransaction (function () use ($ page ) {
66
+ $ page ->save ();
67
+ $ page ->refresh ()->rebuildPermissions ();
68
+ }))->run ();
66
69
67
70
return $ page ;
68
71
}
@@ -72,26 +75,29 @@ public function getNewDraftPage(Entity $parent)
72
75
*/
73
76
public function publishDraft (Page $ draft , array $ input ): Page
74
77
{
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
-
81
- $ summary = trim ($ input ['summary ' ] ?? '' ) ?: trans ('entities.pages_initial_revision ' );
82
- $ this ->revisionRepo ->storeNewForPage ($ draft , $ summary );
83
- $ draft ->refresh ();
84
-
85
- Activity::add (ActivityType::PAGE_CREATE , $ draft );
86
- $ this ->baseRepo ->sortParent ($ draft );
87
-
88
- 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 ();
89
95
}
90
96
91
97
/**
92
98
* Directly update the content for the given page from the provided input.
93
99
* Used for direct content access in a way that performs required changes
94
- * (Search index & reference regen) without performing an official update.
100
+ * (Search index and reference regen) without performing an official update.
95
101
*/
96
102
public function setContentFromInput (Page $ page , array $ input ): void
97
103
{
@@ -116,7 +122,7 @@ public function update(Page $page, array $input): Page
116
122
$ page ->revision_count ++;
117
123
$ page ->save ();
118
124
119
- // Remove all update drafts for this user & page.
125
+ // Remove all update drafts for this user and page.
120
126
$ this ->revisionRepo ->deleteDraftsForCurrentUser ($ page );
121
127
122
128
// Save a revision after updating
@@ -269,16 +275,18 @@ public function move(Page $page, string $parentIdentifier): Entity
269
275
throw new PermissionsException ('User does not have permission to create a page within the new parent ' );
270
276
}
271
277
272
- $ page ->chapter_id = ($ parent instanceof Chapter) ? $ parent ->id : null ;
273
- $ newBookId = ($ parent instanceof Chapter) ? $ parent ->book ->id : $ parent ->id ;
274
- $ page ->changeBook ($ newBookId );
275
- $ 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 ();
276
283
277
- Activity::add (ActivityType::PAGE_MOVE , $ page );
284
+ Activity::add (ActivityType::PAGE_MOVE , $ page );
278
285
279
- $ this ->baseRepo ->sortParent ($ page );
286
+ $ this ->baseRepo ->sortParent ($ page );
280
287
281
- return $ parent ;
288
+ return $ parent ;
289
+ }))->run ();
282
290
}
283
291
284
292
/**
0 commit comments