$page = (new Page())->forceFill([
'name' => trans('entities.pages_initial_name'),
'created_by' => user()->id,
+ 'owned_by' => user()->id,
'updated_by' => user()->id,
'draft' => true,
]);
}
$pageContent = new PageContent($page);
- if (isset($input['html'])) {
- $pageContent->setNewHTML($input['html']);
- } else {
+ if (!empty($input['markdown'] ?? '')) {
$pageContent->setNewMarkdown($input['markdown']);
+ } else {
+ $pageContent->setNewHTML($input['html']);
}
}
/**
* Saves a page revision into the system.
*/
- protected function savePageRevision(Page $page, string $summary = null)
+ protected function savePageRevision(Page $page, string $summary = null): PageRevision
{
$revision = new PageRevision($page->getAttributes());
public function restoreRevision(Page $page, int $revisionId): Page
{
$page->revision_count++;
- $this->savePageRevision($page);
-
$revision = $page->revisions()->where('id', '=', $revisionId)->first();
+
$page->fill($revision->toArray());
$content = new PageContent($page);
$content->setNewHTML($revision->html);
$page->updated_by = user()->id;
$page->refreshSlug();
$page->save();
-
$page->indexForSearch();
+
+ $summary = trans('entities.pages_revision_restored_from', ['id' => strval($revisionId), 'summary' => $revision->summary]);
+ $this->savePageRevision($page, $summary);
+
Activity::addForEntity($page, ActivityType::PAGE_RESTORE);
return $page;
}
return $parentClass::visible()->where('id', '=', $entityId)->first();
}
- /**
- * Update the permissions of a page.
- */
- public function updatePermissions(Page $page, bool $restricted, Collection $permissions = null)
- {
- $this->baseRepo->updatePermissions($page, $restricted, $permissions);
- }
-
/**
* Change the page's parent to the given entity.
*/