X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/c2e031ae3e012b82978424c5ea89eb416e283b82..refs/pull/3373/head:/app/Entities/Tools/PageEditActivity.php diff --git a/app/Entities/Tools/PageEditActivity.php b/app/Entities/Tools/PageEditActivity.php index 991882bef..9981a6ed7 100644 --- a/app/Entities/Tools/PageEditActivity.php +++ b/app/Entities/Tools/PageEditActivity.php @@ -1,4 +1,4 @@ -aactivePageEditingQuery(60)->get(); $count = $pageDraftEdits->count(); - $userMessage = $count > 1 ? trans('entities.pages_draft_edit_active.start_a', ['count' => $count]) : trans('entities.pages_draft_edit_active.start_b', ['userName' => $pageDraftEdits->first()->createdBy->name]); + $userMessage = trans('entities.pages_draft_edit_active.start_a', ['count' => $count]); + if ($count === 1) { + /** @var PageRevision $firstDraft */ + $firstDraft = $pageDraftEdits->first(); + $userMessage = trans('entities.pages_draft_edit_active.start_b', ['userName' => $firstDraft->createdBy->name ?? '']); + } + $timeMessage = trans('entities.pages_draft_edit_active.time_b', ['minCount'=> 60]); return trans('entities.pages_draft_edit_active.message', ['start' => $userMessage, 'time' => $timeMessage]); } /** - * Check if the page has been updated since the draft has been saved. + * Get any editor clash warning messages to show for the given draft revision. + * + * @param PageRevision|Page $draft * - * @return bool + * @return string[] + */ + public function getWarningMessagesForDraft($draft): array + { + $warnings = []; + + if ($this->hasActiveEditing()) { + $warnings[] = $this->activeEditingMessage(); + } + + if ($draft instanceof PageRevision && $this->hasPageBeenUpdatedSinceDraftCreated($draft)) { + $warnings[] = trans('entities.pages_draft_page_changed_since_creation'); + } + + return $warnings; + } + + /** + * Check if the page has been updated since the draft has been saved. */ - public function hasPageBeenUpdatedSinceDraftSaved(PageRevision $draft): bool + protected function hasPageBeenUpdatedSinceDraftCreated(PageRevision $draft): bool { - return $draft->page->updated_at->timestamp >= $draft->updated_at->timestamp; + return $draft->page->updated_at->timestamp > $draft->created_at->timestamp; } /** * Get the message to show when the user will be editing one of their drafts. - * - * @param PageRevision $draft - * - * @return string */ public function getEditingActiveDraftMessage(PageRevision $draft): string {