$page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
$book = $page->book;
$this->checkOwnablePermission('page-delete', $page);
+ $this->entityRepo->destroyPage($page);
+
Activity::addMessage('page_delete', $book->id, $page->name);
session()->flash('success', trans('entities.pages_delete_success'));
- $this->entityRepo->destroyPage($page);
return redirect($book->getUrl());
}
use BookStack\Chapter;
use BookStack\Entity;
use BookStack\Exceptions\NotFoundException;
+use BookStack\Exceptions\NotifyException;
use BookStack\Page;
use BookStack\PageRevision;
use BookStack\Services\AttachmentService;
/**
* Destroy a given page along with its dependencies.
* @param Page $page
+ * @throws NotifyException
*/
public function destroyPage(Page $page)
{
$this->permissionService->deleteJointPermissionsForEntity($page);
$this->searchService->deleteEntityTerms($page);
+ // Check if set as custom homepage
+ $customHome = setting('app-homepage', '0:');
+ if (intval($page->id) === intval(explode(':', $customHome)[0])) {
+ throw new NotifyException(trans('errors.page_custom_home_deletion'), $page->getUrl());
+ }
+
// Delete Attached Files
$attachmentService = app(AttachmentService::class);
foreach ($page->attachments as $attachment) {
// Pages
'page_draft_autosave_fail' => 'Failed to save draft. Ensure you have internet connection before saving this page',
+ 'page_custom_home_deletion' => 'Cannot delete a page while it is set as a homepage',
// Entities
'entity_not_found' => 'Entity not found',
$homeVisit->assertSee('Recent Activity');
}
- public function test_custom_homepage() {
+ public function test_custom_homepage()
+ {
$this->asEditor();
$name = 'My custom homepage';
$content = 'This is the body content of my custom homepage.';
$homeVisit->assertSee('Recently Updated Pages');
$homeVisit->assertSee('Recent Activity');
}
+
+ public function test_delete_custom_homepage()
+ {
+ $this->asEditor();
+ $name = 'My custom homepage';
+ $content = 'This is the body content of my custom homepage.';
+ $customPage = $this->newPage(['name' => $name, 'html' => $content]);
+ $this->setSettings(['app-homepage' => $customPage->id]);
+
+ $homeVisit = $this->get('/');
+ $homeVisit->assertSee($name);
+
+ $pageDeleteReq = $this->delete($customPage->getUrl());
+ $pageDeleteReq->assertStatus(302);
+ $pageDeleteReq->assertRedirect($customPage->getUrl());
+ $pageDeleteReq->assertSessionHas('error');
+ $pageDeleteReq->assertSessionMissing('success');
+
+ $homeVisit = $this->get('/');
+ $homeVisit->assertSee($name);
+ $homeVisit->assertStatus(200);
+ }
}