Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions app/Entities/Repos/PageRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,27 +118,29 @@ public function setContentFromInput(Page $page, array $input): void
*/
public function update(Page $page, array $input): Page
{
// Hold the old details to compare later
// Hold the old details to compare later.
$oldName = $page->name;
$oldHtml = $page->html;
$oldMarkdown = $page->markdown;

$this->updateTemplateStatusAndContentFromInput($page, $input);
$page = $this->baseRepo->update($page, $input);

// Update with new details
$page->revision_count++;
$page->save();

// Remove all update drafts for this user and page.
$this->revisionRepo->deleteDraftsForCurrentUser($page);

// Save a revision after updating
// Values used to determine if a change has been made.
$summary = trim($input['summary'] ?? '');
$htmlChanged = isset($input['html']) && $input['html'] !== $oldHtml;
$htmlChanged = isset($page->html) && $page->html !== $oldHtml;
$nameChanged = isset($input['name']) && $input['name'] !== $oldName;
$markdownChanged = isset($input['markdown']) && $input['markdown'] !== $oldMarkdown;
$markdownChanged = isset($page->markdown) && $page->markdown !== $oldMarkdown;

// Update with new details, only if the page really changed.
if ($htmlChanged || $nameChanged || $markdownChanged || $summary) {
$page = $this->baseRepo->update($page, $input);

$page->revision_count++;
$page->save();

// Remove all update drafts for this user and page.
$this->revisionRepo->deleteDraftsForCurrentUser($page);

$this->revisionRepo->storeNewForPage($page, $summary);
}

Expand Down