- // Check if set as custom homepage & remove setting if not used or throw error if active
- $customHome = setting('app-homepage', '0:');
- if (intval($page->id) === intval(explode(':', $customHome)[0])) {
- if (setting('app-homepage-type') === 'page') {
- throw new NotifyException(trans('errors.page_custom_home_deletion'), $page->getUrl());
+ $page->delete();
+ }
+
+ /**
+ * Ensure the given entity is deletable.
+ * Is not for permissions, but logical conditions within the application.
+ * Will throw if not deletable.
+ *
+ * @throws NotifyException
+ */
+ protected function ensureDeletable(Entity $entity): void
+ {
+ $customHomeId = intval(explode(':', setting('app-homepage', '0:'))[0]);
+ $customHomeActive = setting('app-homepage-type') === 'page';
+ $removeCustomHome = false;
+
+ // Check custom homepage usage for pages
+ if ($entity instanceof Page && $entity->id === $customHomeId) {
+ if ($customHomeActive) {
+ throw new NotifyException(trans('errors.page_custom_home_deletion'), $entity->getUrl());
+ }
+ $removeCustomHome = true;
+ }
+
+ // Check custom homepage usage within chapters or books
+ if ($entity instanceof Chapter || $entity instanceof Book) {
+ if ($entity->pages()->where('id', '=', $customHomeId)->exists()) {
+ if ($customHomeActive) {
+ throw new NotifyException(trans('errors.page_custom_home_deletion'), $entity->getUrl());
+ }
+ $removeCustomHome = true;