{"record":{"id":"93c3d91f1356959e","repo":"BookStackApp/BookStack","slug":"errors-page-custom-home-deletion","errorCode":null,"errorMessage":"errors.page_custom_home_deletion","messagePattern":"errors\\.page_custom_home_deletion","errorType":"exception","errorClass":"NotifyException","httpStatus":null,"severity":"error","filePath":"app/Entities/Tools/TrashCan.php","lineNumber":117,"sourceCode":"    }\n\n    /**\n     * Ensure the given entity is deletable.\n     * Is not for permissions, but logical conditions within the application.\n     * Will throw if not deletable.\n     *\n     * @throws NotifyException\n     */\n    protected function ensureDeletable(Entity $entity): void\n    {\n        $customHomeId = intval(explode(':', setting('app-homepage', '0:'))[0]);\n        $customHomeActive = setting('app-homepage-type') === 'page';\n        $removeCustomHome = false;\n\n        // Check custom homepage usage for pages\n        if ($entity instanceof Page && $entity->id === $customHomeId) {\n            if ($customHomeActive) {\n                throw new NotifyException(trans('errors.page_custom_home_deletion'), $entity->getUrl());\n            }\n            $removeCustomHome = true;\n        }\n\n        // Check custom homepage usage within chapters or books\n        if ($entity instanceof Chapter || $entity instanceof Book) {\n            if ($entity->pages()->where('id', '=', $customHomeId)->exists()) {\n                if ($customHomeActive) {\n                    throw new NotifyException(trans('errors.page_custom_home_deletion'), $entity->getUrl());\n                }\n                $removeCustomHome = true;\n            }\n        }\n\n        if ($removeCustomHome) {\n            setting()->remove('app-homepage');\n        }\n    }","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/BookStackApp/BookStack/blob/18f8469a1c72f8cc8497e9372635e6dea5028071/app/Entities/Tools/TrashCan.php#L99-L135","documentation":"TrashCan::ensureDeletable blocks deleting a Page that is currently the instance's custom homepage while the 'app-homepage-type' setting is 'page'. Deleting the active homepage would leave the site without a landing page, so it throws NotifyException with 'errors.page_custom_home_deletion' and a link back to the entity. The check only fires when the custom homepage is active; if inactive, deletion proceeds and the homepage reference is cleaned up.","triggerScenarios":"softDestroyPage (directly or via chapter/book/shelf cascade through ensureDeletable) on the page whose ID matches the 'app-homepage' setting while APP_HOMEPAGE_TYPE=page (set via 'app-homepage-type' setting).","commonSituations":"Admins deleting a landing page created early in setup; bulk deletes inadvertently including the homepage page; environments where the homepage setting was left pointing at a page after redesigns; automated cleanup scripts not aware of the homepage config.","solutions":["Change the homepage type first (Settings > Homepage: set to default or another option), then delete the page.","Set APP_HOMEPAGE_TYPE env / 'app-homepage-type' setting to a non-page value and re-run the deletion.","Point the homepage at a different page ('app-homepage' setting) before deleting the old one.","Catch NotifyException in deletion flows to show the message and redirect to the entity URL as the exception provides."],"exampleFix":"// before\n$trashCan->softDestroyPage($homePage); // throws if active homepage\n// after\nsetting('app-homepage-type', 'default'); // or change via Settings UI\n$trashCan->softDestroyPage($homePage);","handlingStrategy":"validation","validationCode":"if ((int) setting('app-homepage') === $page->id\n    && setting('app-homepage-type') === 'page') {\n    // change homepage first\n    setting('app-homepage-type', 'default');\n}","typeGuard":null,"tryCatchPattern":"try {\n    $trashCan->softDestroyPage($page);\n} catch (\\BookStack\\Exceptions\\NotifyException $e) {\n    return redirect($e->getMessageUrl ?? '/')->with('error', $e->getMessage());\n}","preventionTips":["Check the current homepage page ID before deleting pages","Exclude the configured homepage from bulk-delete jobs","Switch APP_HOMEPAGE_TYPE before tearing down old landing pages"],"tags":["bookstack","configuration","deletion-guard","laravel"],"backgroundTag":"homepage-deletion-blocked","analyzedSha":"18f8469a1c72f8cc8497e9372635e6dea5028071","analyzedAt":"2026-09-02T19:49:33.068Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}