Nicer error message when no DB and backend access attempt

This is for flat-file sites that don't use a database. If debug mode is on, it will show an error page with advice to set up the database. If debug mode is off, it will simply show a 404 page. Previously it was a nasty exception/plain error page.
This commit is contained in:
Samuel Georges 2016-06-05 07:16:11 +10:00
parent 47c038c96e
commit 171b14c6ab
5 changed files with 48 additions and 5 deletions

View File

@ -3,6 +3,9 @@
use Str;
use App;
use File;
use View;
use Config;
use Response;
use Illuminate\Routing\Controller as ControllerBase;
use October\Rain\Router\Helper as RouterHelper;
use Closure;
@ -61,6 +64,15 @@ class BackendController extends ControllerBase
{
$params = RouterHelper::segmentizeUrl($url);
/*
* Database check
*/
if (!App::hasDatabase()) {
return Config::get('app.debug', false)
? Response::make(View::make('backend::no_database'), 200)
: App::make('Cms\Classes\Controller')->run($url);
}
/*
* Look for a Module controller
*/

View File

@ -32,10 +32,6 @@ class Index extends Controller
BackendMenu::setContextOwner('October.Backend');
$this->addCss('/modules/backend/assets/css/dashboard/dashboard.css', 'core');
if (BackendAuth::check()) {
new ReportContainer($this, 'config_dashboard.yaml');
}
}
public function index()
@ -44,15 +40,30 @@ class Index extends Controller
return $redirect;
}
$this->initReportContainer();
$this->pageTitle = 'backend::lang.dashboard.menu_label';
BackendMenu::setContextMainMenu('dashboard');
}
public function index_onInitReportContainer()
{
$this->initReportContainer();
return ['#dashReportContainer' => $this->widget->reportContainer->render()];
}
/**
* Prepare the report widget used by the dashboard
* @param Model $model
* @return void
*/
protected function initReportContainer()
{
new ReportContainer($this, 'config_dashboard.yaml');
}
/**
* Custom permissions check that will redirect to the next
* available menu item, if permission to this page is denied.

View File

@ -19,6 +19,11 @@ return [
'help' => "You don't have the required permissions to view this page.",
'cms_link' => 'Return to the back-end'
],
'no_database' => [
'label' => 'Database missing',
'help' => "A database is required to access the back-end. Check the database is configured and migrated before trying again.",
'cms_link' => 'Return to the homepage'
],
'invalid_token' => [
'label' => 'Invalid security token'
]

View File

@ -12,4 +12,4 @@
<a href="<?= Backend::url('/') ?>"><?= Lang::get('backend::lang.page.access_denied.cms_link') ?></a>
</div>
</body>
</html>
</html>

View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title><?= Lang::get('backend::lang.page.no_database.label') ?></title>
<link href="<?= URL::to('/modules/system/assets/css/styles.css') ?>" rel="stylesheet">
</head>
<body>
<div class="container">
<h1><i class="icon-database warning"></i> <?= Lang::get('backend::lang.page.no_database.label') ?></h1>
<p class="lead"><?= Lang::get('backend::lang.page.no_database.help') ?></p>
<a href="<?= Url::to('/') ?>"><?= Lang::get('backend::lang.page.no_database.cms_link') ?></a>
</div>
</body>
</html>