/** * Ensures that there is always a 404 page by checking if there's an * instance of ErrorPage with a 404 and 500 error code. If there is not, * one is created when the DB is built. */ public function requireDefaultRecords() { parent::requireDefaultRecords(); if ($this->class === 'ErrorPage' && SiteTree::config()->create_default_pages) { $defaultPages = $this->getDefaultRecords(); foreach ($defaultPages as $defaultData) { $code = $defaultData['ErrorCode']; $page = ErrorPage::get()->filter('ErrorCode', $code)->first(); $pageExists = !empty($page); if (!$pageExists) { $page = new ErrorPage($defaultData); $page->write(); $page->publish('Stage', 'Live'); } // Check if static files are enabled if (!self::config()->enable_static_file) { continue; } // Ensure this page has cached error content $success = true; if (!$page->hasStaticPage()) { // Update static content $success = $page->writeStaticPage(); } elseif ($pageExists) { // If page exists and already has content, no alteration_message is displayed continue; } if ($success) { DB::alteration_message(sprintf('%s error page created', $code), 'created'); } else { DB::alteration_message(sprintf('%s error page could not be created. Please check permissions', $code), 'error'); } } } }