Skip to main content
Topic: Errors.... (Read 6010 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: Errors....

Reply #15

I'd like to see maybe a place in General Settings, where the admin can insert an email address, or a URL, to be pasted onto the error pages, as a "Contact us if you see this page" kind of thing.

Should work, as I know some fields do not get added to the database.
Like template edit settings.

Re: Errors....

Reply #16

Here, I think, an email is already set to be sent on this error.
Code: [Select]
// Language files aren't loaded yet :(.
 $db_error = $db->last_error($db->connection());
 @mail($webmaster_email, $mbname . ': Database Error!', 'There has been a problem with the database!' . ($db_error == '' ? '' : "\n" . $db->db_title() . ' reported:' . "\n" . $db_error) . "\n\n" . 'This is a notice email to let you know that the system could not connect to the database, contact your host if this continues.');
 }

But if you really really want to do it, as addon or modifications, find this code in Errors.php under display_db_error.
Code: [Select]
echo '<!DOCTYPE html>
<html>
 <head>
 <meta name="robots" content="noindex" />
 <title>Connection Problems</title>
 </head>
 <body>
 <h3>Connection Problems</h3>
 Sorry, we were unable to connect to the database.  This may be caused by the server being busy.  Please try again later.
 </body>
</html>';
Then replace its place with this:
Code: [Select]
	require_once(__DIR__ . '/../themes/default/Errors.template.php');
template_display_db_error();

Move the above echoed html code (or customized it) into Errors.template.php in default themes folder under a (newly created) function template_display_db_error. You may later call the said from admin page to edit or change it accordingly.

Edited: Simplified.
Last Edit: February 24, 2016, 09:01:57 am by ahrasis

Re: Errors....

Reply #17

Template settings are saved in the database.
The only settings not saved in the database are those is the Settings.php file.
Bugs creator.
Features destroyer.
Template killer.

Re: Errors....

Reply #18

Quote from: Flavio93Zena (#OpIsis) – And then I wonder... Does it really worth it to go through so much of an hassle just for an error page that will hopefully be displayed the fewer the better?
Probably not, or at least not for core. Easy to do as a mod if anyone wants to do it. Easy to do manually on a per-site basis if anyone wants to do that (I've done it before). But probably not worth adding more stuff to the core build. I just mentioned a way of doing it without too much drama because somebody asked.
Master of Expletives: Now with improved family f@&king friendliness! :D

Sources code: making easy front end changes difficult since 1873. :P

Re: Errors....

Reply #19

Quote from: emanuele –
Quote from: Burke Knight – Like template edit settings.
Template settings are saved in the database.
The only settings not saved in the database are those is the Settings.php file.


Template edits like in non-hook mods?
Never knew that, as never had database calls in most of my SMF mods.

Re: Errors....

Reply #20

Settings are not edits. :P
I guess you lost me somewhere, oh well.
Bugs creator.
Features destroyer.
Template killer.

Re: Errors....

Reply #21

I think he means the page where admin can modify any theme template file (which we already have).

The idea could be, create a file for it in default theme folder, move the html page code in Errors.php to that file, include / display the page on database connection error, the file can be modify via the above said page.

Does it make sense?

Re: Errors....

Reply #22

Ok, let me try to explain it another way so that it may be becomes a little more clear:
0) all the data related to the theme (paths, urls, settings) are stored in the database,
1) we are talking about the case Elk is not able to connect to the database,
2) if Elk cannot connect to the db it cannot (reliably) know where the theme is (because this data is stored in the database, see point 0),
3) if Elk cannot (reliably) know where the theme is, it cannot load a theme file.

From that we find out that:
1) the html is in Errors.php because in that case Elk cannot be sure where the files are (please, remember Elk allows to store themes in arbitrary directories),
2) we cannot more the HTML code to a template file because in case of database error we are not sure where the themes directory is (the paths are stored in the database!).

There is a possible mid/long term solution to this, but I don't want to mention it here and now because I know it will derail the topic even more, so let's do what we can with what we have.
We know in most of the cases the default theme is under forum/themes/default, so (as I said two days ago) Elk can probe and see if the theme is actually there, if it is there, it can try to use it (because the theme may be in the expected place, but assets may be served from another url nothing is completely sure in this case), otherwise dull empty screen.

At the moment, this is the only possible workaround.

About additional links/emails/whatever, if I'm not wrong, in case of database errors Elk already sends out an email to the "forum email" (the one set in server config IIRC), what is possible is to let admins specify multiple email addresses there. Anything more would require more settings stored in Settings.php (that is something I would avoid if at all possible) or a working database connection (that in the case at hands we don't have).
Bugs creator.
Features destroyer.
Template killer.

Re: Errors....

Reply #23

Edited: It seems using the DIR . '../themes/default/ is better than $_SERVER['DOCUMENT_ROOT'] . '/themes/default/ since ElkArte forum might not be in the root folder. Please refer to edited Reply #18.
Last Edit: February 24, 2016, 09:05:30 am by ahrasis