-
Notifications
You must be signed in to change notification settings - Fork 282
about/index.php: Add message if database connection fail #5356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
about/index.php: Add message if database connection fail #5356
Conversation
|
Seems like this was already in part addressed by #5236, which hid the stacktrace completely. You're now re-introducing it, but with a different message, even though I said to not show a stacktrace anymore! But anyway, let's start from scratch here. Please do the following:
Then, depending on the individual case, please propose a solution how it can be improved. |
6b82f16 to
15b0148
Compare
- Add error handling for database connection failures - Suppress stacktrace and add error messages for user and admin - Improve user experience with clear error messages
219a4a0 to
038bc99
Compare
Co-authored-by: Ravi Kumar Kempapura Srinivasa <[email protected]>
883278e to
56793c8
Compare
| ]); | ||
|
|
||
| return; | ||
| $hasPending = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason you need this variable $hasPending.
I don't see this variable used anywhere. In the try block, you're assigning it a value, but it's not used afterward. You could consider removing it.
| <table > | ||
| <tr> | ||
| <th> | ||
| <?php if (!isset($config->config_resource)) : ?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| <?php if (!isset($config->config_resource)) : ?> | |
| <?php if (! isset($config->config_resource)) : ?> |
We usually add a space after the ! (not) operator for readability.
| $hasConfigPermission = $this->hasPermission('config/*'); | ||
| $configLink = new HtmlDocument(); | ||
| if ($hasConfigPermission) { | ||
| $warningMessage = $this->translate( | ||
| 'No Configuration Database selected.' | ||
| . 'To establish a valid database connection set the Configuration Database field.' | ||
| ); | ||
|
|
||
| $configLink = new Link($this->translate('Configuration Database'), 'config/general'); | ||
| } else { | ||
| $warningMessage = $this->translate( | ||
| 'No Configuration Database selected.' | ||
| . 'You don`t have permission to change this setting. Please contact an administrator.' | ||
| ); | ||
| } | ||
|
|
||
| $this->addContent( | ||
| new HtmlElement( | ||
| 'div', | ||
| new Attributes(['class' => 'db-connection-warning']), | ||
| new Icon('warning'), | ||
| new HtmlElement( | ||
| 'p', | ||
| null, | ||
| Text::create($warningMessage), | ||
| ), | ||
| $configLink | ||
| ) | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| $hasConfigPermission = $this->hasPermission('config/*'); | |
| $configLink = new HtmlDocument(); | |
| if ($hasConfigPermission) { | |
| $warningMessage = $this->translate( | |
| 'No Configuration Database selected.' | |
| . 'To establish a valid database connection set the Configuration Database field.' | |
| ); | |
| $configLink = new Link($this->translate('Configuration Database'), 'config/general'); | |
| } else { | |
| $warningMessage = $this->translate( | |
| 'No Configuration Database selected.' | |
| . 'You don`t have permission to change this setting. Please contact an administrator.' | |
| ); | |
| } | |
| $this->addContent( | |
| new HtmlElement( | |
| 'div', | |
| new Attributes(['class' => 'db-connection-warning']), | |
| new Icon('warning'), | |
| new HtmlElement( | |
| 'p', | |
| null, | |
| Text::create($warningMessage), | |
| ), | |
| $configLink | |
| ) | |
| ); | |
| $hasConfigPermission = $this->hasPermission('config/*'); | |
| if ($hasConfigPermission) { | |
| $configLink = new Link($this->translate('Configuration Database'), 'config/general'); | |
| $warningMessage = sprintf($this->translate( | |
| 'No configuration database is selected. ' | |
| . 'To establish a valid database connection set the %s field.' | |
| ), $configLink); | |
| } else { | |
| $warningMessage = Text::create( | |
| $this->translate( | |
| 'No configuration database is selected. ' | |
| . 'You don`t have permission to change this setting. Please contact an administrator.' | |
| ) | |
| ); | |
| } | |
| $this->addContent( | |
| new HtmlElement( | |
| 'div', | |
| new Attributes(['class' => 'db-connection-warning']), | |
| new Icon('warning'), | |
| new HtmlElement( | |
| 'p', | |
| null, | |
| HtmlString::create($warningMessage), | |
| ) | |
| ) | |
| ); |
I have changed the message and also included the link within the message, which made more sense to me. Also, add ipl\Html\HtmlString to the usages at the top of the file.
| 'No Configuration Database selected.' | ||
| . 'Please set the field to establish a valid database connection.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 'No Configuration Database selected.' | |
| . 'Please set the field to establish a valid database connection.' | |
| 'The configuration database has not been selected. ' | |
| . 'Please set the required field to establish a valid database connection.' |
| 'No Configuration Database selected.' | ||
| . 'To establish a valid database connection set the Configuration Database field.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 'No Configuration Database selected.' | |
| . 'To establish a valid database connection set the Configuration Database field.' | |
| 'The configuration database is selected. ' | |
| . 'To establish a valid database connection set the configuration database field.' |
I am curious why the link to set the configuration database was not included here like in MyDevicesController.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe there’s a small mistake in the suggested text. The correct version should be: “The configuration database has not been selected.”
Also, if I remember correctly, it wasn’t possible to include a link in a Zend Form warning message, since the link would not be rendered. Perhaps you know a workaround?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe there’s a small mistake in the suggested text. The correct version should be: “The configuration database has not been selected.”
You are right, use the correct version has you have mentioned.
Also, if I remember correctly, it wasn’t possible to include a link in a Zend Form warning message, since the link would not be rendered. Perhaps you know a workaround?
Good question, I will look into it and will let you know if this is possible :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JolienTrog, easiest way is to add an EmptyState widget directly in the view script application/views/scripts/account/index.phtml, just like you did in application/views/scripts/about/index.phtml and use some css styling to make it appear like a warning. This way you could also include the link.
| </div> | ||
| <?php $config = Config::app()->getSection('global') ?> | ||
| <div class="pending-migrations clearfix"> | ||
| <?php if($mm->getPendingMigrations() || (!isset($config->config_resource))) : ?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| <?php if($mm->getPendingMigrations() || (!isset($config->config_resource))) : ?> | |
| <?php if($mm->getPendingMigrations() || (! isset($config->config_resource))) : ?> |
We usually add a space after the ! (not) operator for readability.
| <?= new EmptyState( | ||
| $this->translate('No Configuration Database selected. To establish a valid database connection set: ') | ||
| ) | ||
| ?><td> | ||
| <?= $this->qlink( | ||
| $this->translate('Configuration Database'), | ||
| 'config/general/', | ||
| [], | ||
| ['title' => sprintf($this->translate('Go to Application/General')), 'Configuration Database'] | ||
| ) ?> | ||
| </td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| <?= new EmptyState( | |
| $this->translate('No Configuration Database selected. To establish a valid database connection set: ') | |
| ) | |
| ?><td> | |
| <?= $this->qlink( | |
| $this->translate('Configuration Database'), | |
| 'config/general/', | |
| [], | |
| ['title' => sprintf($this->translate('Go to Application/General')), 'Configuration Database'] | |
| ) ?> | |
| </td> | |
| <?= new EmptyState( | |
| HtmlString::create(sprintf( | |
| $this->translate('No configuration database is selected. To establish a valid database connection set the %s'), | |
| new Link($this->translate('Configuration Database'), 'config/general') | |
| )) | |
| ) | |
| ?> |
HtmlString can render the html in the string. And it looks better to me.
You need to add ipl\Html\HtmlString and ipl\Web\Widget\Link at the top of the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other parts of the code, qlink has always been used. Should I now use new Link just this one time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to check why this is happening. The issue appears to be caused by the current CSS rules, which are preventing the links from displaying on the same line. Consider updating the layout properties that are causing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other parts of the code,
qlinkhas always been used. Should I now usenew Linkjust this one time?
It provides a straightforward way to include the link in the EmptyState widget. Hence, you could use it here.
| $this->controls->getAttributes()->add('class', 'default-layout'); | ||
| $this->addControl($migrateAllButton); | ||
| } | ||
| } catch (Throwable $e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure you need to try { such a large code fragment?
| $this->controls->getAttributes()->add('class', 'default-layout'); | ||
| $this->addControl($migrateAllButton); | ||
| } | ||
| } catch (Throwable $e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given your specific error message, re-consider your caught type. (Throwable)
| ) | ||
| ) | ||
| ); | ||
| return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if the framework has no configuration DB to migrate:
- Modules (the code below) may have pending migrations – but you're blocking them as well
- I'd even guess(!) no configuration DB = no need to migrate framework stuff = fine
|
@nilmerg : What do you think? Should I keep it like this or use the HealthHook instead? |




fixes #5155