|
19 | 19 | use ipl\Html\Text; |
20 | 20 | use ipl\Web\Compat\CompatController; |
21 | 21 | use ipl\Web\Widget\ActionLink; |
| 22 | +use ipl\Web\Widget\Icon; |
| 23 | +use ipl\Web\Widget\Link; |
| 24 | +use Throwable; |
22 | 25 |
|
23 | 26 | class MigrationsController extends CompatController |
24 | 27 | { |
@@ -55,24 +58,48 @@ public function indexAction(): void |
55 | 58 |
|
56 | 59 | $migrateListForm = new MigrationForm(); |
57 | 60 | $migrateListForm->setAttribute('id', $this->getRequest()->protectId('migration-form')); |
58 | | - $migrateListForm->setRenderDatabaseUserChange(! $mm->validateDatabasePrivileges()); |
| 61 | + try { |
| 62 | + $migrateListForm->setRenderDatabaseUserChange(! $mm->validateDatabasePrivileges()); |
59 | 63 |
|
60 | | - if ($canApply && $mm->hasPendingMigrations()) { |
61 | | - $migrateAllButton = new SubmitButtonElement(sprintf('migrate-%s', DbMigrationHook::ALL_MIGRATIONS), [ |
| 64 | + if ($canApply && $mm->hasPendingMigrations()) { |
| 65 | + $migrateAllButton = new SubmitButtonElement(sprintf('migrate-%s', DbMigrationHook::ALL_MIGRATIONS), [ |
62 | 66 | 'form' => $migrateListForm->getAttribute('id')->getValue(), |
63 | 67 | 'label' => $this->translate('Migrate All'), |
64 | 68 | 'title' => $this->translate('Migrate all pending migrations') |
65 | | - ]); |
| 69 | + ]); |
66 | 70 |
|
67 | | - // Is the first button, so will be cloned and that the visible |
68 | | - // button is outside the form doesn't matter for Web's JS |
69 | | - $migrateListForm->registerElement($migrateAllButton); |
| 71 | + // Is the first button, so will be cloned and that the visible |
| 72 | + // button is outside the form doesn't matter for Web's JS |
| 73 | + $migrateListForm->registerElement($migrateAllButton); |
70 | 74 |
|
71 | | - // Make sure it looks familiar, even if not inside a form |
72 | | - $migrateAllButton->setWrapper(new HtmlElement('div', Attributes::create(['class' => 'icinga-controls']))); |
| 75 | + // Make sure it looks familiar, even if not inside a form |
| 76 | + $migrateAllButton->setWrapper( |
| 77 | + new HtmlElement('div', Attributes::create(['class' => 'icinga-controls'])) |
| 78 | + ); |
73 | 79 |
|
74 | | - $this->controls->getAttributes()->add('class', 'default-layout'); |
75 | | - $this->addControl($migrateAllButton); |
| 80 | + $this->controls->getAttributes()->add('class', 'default-layout'); |
| 81 | + $this->addControl($migrateAllButton); |
| 82 | + } |
| 83 | + } catch (Throwable $e) { |
| 84 | + $this->addContent( |
| 85 | + new HtmlElement( |
| 86 | + 'div', |
| 87 | + new Attributes(['class' => 'db-connection-warning']), |
| 88 | + new Icon('warning'), |
| 89 | + new HtmlElement('ul', null), |
| 90 | + new HtmlElement( |
| 91 | + 'p', |
| 92 | + null, |
| 93 | + new Text( |
| 94 | + $this->translate(' No Configuration Database selected. |
| 95 | + To establish a valid database connection set the Configuration Database field. ') |
| 96 | + ) |
| 97 | + ), |
| 98 | + new HtmlElement('ul', null), |
| 99 | + new Link($this->translate('Configuration Database'), 'config/general/') |
| 100 | + ) |
| 101 | + ); |
| 102 | + return; |
76 | 103 | } |
77 | 104 |
|
78 | 105 | $this->handleFormatRequest($mm->toArray()); |
|
0 commit comments