WelcomeForm: Don't raise sys errors directly but use notifications to notify the user

This commit is contained in:
Yonas Habteab 2022-05-30 10:20:08 +02:00
parent 2105541493
commit 9f7eba4cf8
2 changed files with 12 additions and 3 deletions

View File

@ -26,13 +26,13 @@ class DashletForm extends SetupNewDashboardForm
public function load(BaseDashboard $dashboard) public function load(BaseDashboard $dashboard)
{ {
/** @var Dashlet $dashboard */ /** @var Dashlet $dashboard */
$this->populate(array( $this->populate([
'org_home' => $this->requestUrl->getParam('home'), 'org_home' => $this->requestUrl->getParam('home'),
'org_pane' => $dashboard->getPane()->getName(), 'org_pane' => $dashboard->getPane()->getName(),
'org_dashlet' => $dashboard->getName(), 'org_dashlet' => $dashboard->getName(),
'dashlet' => $dashboard->getTitle(), 'dashlet' => $dashboard->getTitle(),
'url' => $dashboard->getUrl()->getRelativeUrl() 'url' => $dashboard->getUrl()->getRelativeUrl()
)); ]);
} }
protected function assembleNextPageDashboardPart() protected function assembleNextPageDashboardPart()

View File

@ -4,10 +4,12 @@
namespace Icinga\Forms\Dashboard; namespace Icinga\Forms\Dashboard;
use Icinga\Application\Logger;
use Icinga\Application\Modules; use Icinga\Application\Modules;
use Icinga\Web\Dashboard\Dashboard; use Icinga\Web\Dashboard\Dashboard;
use Icinga\Web\Dashboard\DashboardHome; use Icinga\Web\Dashboard\DashboardHome;
use Icinga\Util\DBUtils; use Icinga\Util\DBUtils;
use Icinga\Web\Notification;
use ipl\Html\Form; use ipl\Html\Form;
use ipl\Web\Url; use ipl\Web\Url;
@ -64,8 +66,15 @@ class WelcomeForm extends Form
$conn->commitTransaction(); $conn->commitTransaction();
} catch (\Exception $err) { } catch (\Exception $err) {
$conn->rollBackTransaction(); $conn->rollBackTransaction();
throw $err;
} Logger::error('Unable to apply the system defaults into the DB. An error occurred: %s', $err);
Notification::error(t('Failed to successfully save the data. Please check the logs for details.'));
return;
}
Notification::success(t('Imported system defaults successfully.'));
} }
} }
} }