@@ -118,27 +118,29 @@ public function setContentFromInput(Page $page, array $input): void
118118 */
119119 public function update (Page $ page , array $ input ): Page
120120 {
121- // Hold the old details to compare later
121+ // Hold the old details to compare later.
122122 $ oldName = $ page ->name ;
123123 $ oldHtml = $ page ->html ;
124124 $ oldMarkdown = $ page ->markdown ;
125125
126126 $ this ->updateTemplateStatusAndContentFromInput ($ page , $ input );
127- $ page = $ this ->baseRepo ->update ($ page , $ input );
128127
129- // Update with new details
130- $ page ->revision_count ++;
131- $ page ->save ();
132-
133- // Remove all update drafts for this user and page.
134- $ this ->revisionRepo ->deleteDraftsForCurrentUser ($ page );
135-
136- // Save a revision after updating
128+ // Values used to determine if a change has been made.
137129 $ summary = trim ($ input ['summary ' ] ?? '' );
138- $ htmlChanged = isset ($ input [ ' html ' ] ) && $ input [ ' html ' ] !== $ oldHtml ;
130+ $ htmlChanged = isset ($ page -> html ) && $ page -> html !== $ oldHtml ;
139131 $ nameChanged = isset ($ input ['name ' ]) && $ input ['name ' ] !== $ oldName ;
140- $ markdownChanged = isset ($ input ['markdown ' ]) && $ input ['markdown ' ] !== $ oldMarkdown ;
132+ $ markdownChanged = isset ($ page ->markdown ) && $ page ->markdown !== $ oldMarkdown ;
133+
134+ // Update with new details, only if the page really changed.
141135 if ($ htmlChanged || $ nameChanged || $ markdownChanged || $ summary ) {
136+ $ page = $ this ->baseRepo ->update ($ page , $ input );
137+
138+ $ page ->revision_count ++;
139+ $ page ->save ();
140+
141+ // Remove all update drafts for this user and page.
142+ $ this ->revisionRepo ->deleteDraftsForCurrentUser ($ page );
143+
142144 $ this ->revisionRepo ->storeNewForPage ($ page , $ summary );
143145 }
144146
0 commit comments