Enhance the database structure checks when they failed.
This commit is contained in:
parent
08df06ce60
commit
e21bcb82d2
4 changed files with 71 additions and 22 deletions
23
boot.php
23
boot.php
|
@ -1023,8 +1023,27 @@ if(! function_exists('update_db')) {
|
|||
set_config('database','dbupdate_'.DB_UPDATE_VERSION, time());
|
||||
|
||||
require_once("include/dbstructure.php");
|
||||
update_structure(false, true);
|
||||
|
||||
$retval = update_structure(false, true);
|
||||
if($retval) {
|
||||
//send the administrator an e-mail
|
||||
$email_tpl = get_intltext_template("update_fail_eml.tpl");
|
||||
$email_msg = replace_macros($email_tpl, array(
|
||||
'$sitename' => $a->config['sitename'],
|
||||
'$siteurl' => $a->get_baseurl(),
|
||||
'$update' => DB_UPDATE_VERSION,
|
||||
'$error' => sprintf(t('Update %s failed. See error logs.'), DB_UPDATE_VERSION)
|
||||
));
|
||||
$subject=sprintf(t('Update Error at %s'), $a->get_baseurl());
|
||||
require_once('include/email.php');
|
||||
$subject = email_header_encode($subject,'UTF-8');
|
||||
mail($a->config['admin_email'], $subject, $email_msg,
|
||||
'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME']."\n"
|
||||
.'Content-type: text/plain; charset=UTF-8'."\n"
|
||||
.'Content-transfer-encoding: 8bit');
|
||||
//try the logger
|
||||
logger("CRITICAL: Database structure update failed: ".$retval);
|
||||
break;
|
||||
} else
|
||||
set_config('database','dbupdate_'.DB_UPDATE_VERSION, 'success');
|
||||
|
||||
for($x = $stored; $x < $current; $x ++) {
|
||||
|
|
|
@ -671,23 +671,37 @@ function admin_page_dbsync(&$a) {
|
|||
goaway($a->get_baseurl(true) . '/admin/dbsync');
|
||||
}
|
||||
|
||||
if($a->argc > 2 && intval($a->argv[2])) {
|
||||
if(($a->argc > 2) AND (intval($a->argv[2]) OR ($a->argv[2] === 'check'))) {
|
||||
require_once("include/dbstructure.php");
|
||||
$retval = update_structure(false, true);
|
||||
if (!$retval) {
|
||||
$o .= sprintf(t("Database structure update %s was successfully applied."), DB_UPDATE_VERSION)."<br />";
|
||||
set_config('database', 'dbupdate_'.DB_UPDATE_VERSION, 'success');
|
||||
} else
|
||||
$o .= sprintf(t("Executing of database structure update %s failed with error: %s"),
|
||||
DB_UPDATE_VERSION, $retval)."<br />";
|
||||
if ($a->argv[2] === 'check')
|
||||
return $o;
|
||||
}
|
||||
|
||||
if ($a->argc > 2 && intval($a->argv[2])) {
|
||||
require_once('update.php');
|
||||
$func = 'update_' . intval($a->argv[2]);
|
||||
if(function_exists($func)) {
|
||||
$retval = $func();
|
||||
if($retval === UPDATE_FAILED) {
|
||||
$o .= sprintf( t('Executing %s failed. Check system logs.'), $func);
|
||||
$o .= sprintf(t("Executing %s failed with error: %s"), $func, $retval);
|
||||
}
|
||||
elseif($retval === UPDATE_SUCCESS) {
|
||||
$o .= sprintf( t('Update %s was successfully applied.', $func));
|
||||
$o .= sprintf(t('Update %s was successfully applied.', $func));
|
||||
set_config('database',$func, 'success');
|
||||
}
|
||||
else
|
||||
$o .= sprintf( t('Update %s did not return a status. Unknown if it succeeded.'), $func);
|
||||
$o .= sprintf(t('Update %s did not return a status. Unknown if it succeeded.'), $func);
|
||||
} else {
|
||||
$o .= sprintf(t('There was no additional update function %s that needed to be called.'), $func)."<br />";
|
||||
set_config('database',$func, 'success');
|
||||
}
|
||||
else
|
||||
$o .= sprintf( t('Update function %s could not be found.'), $func);
|
||||
return $o;
|
||||
}
|
||||
|
||||
|
@ -701,9 +715,13 @@ function admin_page_dbsync(&$a) {
|
|||
$failed[] = $upd;
|
||||
}
|
||||
}
|
||||
if(! count($failed))
|
||||
return '<h3>' . t('No failed updates.') . '</h3>';
|
||||
|
||||
if(! count($failed)) {
|
||||
$o = replace_macros(get_markup_template('structure_check.tpl'),array(
|
||||
'$base' => $a->get_baseurl(true),
|
||||
'$banner' => t('No failed updates.'),
|
||||
'$check' => t('Check database structure'),
|
||||
));
|
||||
} else {
|
||||
$o = replace_macros(get_markup_template('failed_updates.tpl'),array(
|
||||
'$base' => $a->get_baseurl(true),
|
||||
'$banner' => t('Failed Updates'),
|
||||
|
@ -712,6 +730,7 @@ function admin_page_dbsync(&$a) {
|
|||
'$apply' => t('Attempt to execute this update step automatically'),
|
||||
'$failed' => $failed
|
||||
));
|
||||
}
|
||||
|
||||
return $o;
|
||||
|
||||
|
|
11
view/templates/structure_check.tpl
Normal file
11
view/templates/structure_check.tpl
Normal file
|
@ -0,0 +1,11 @@
|
|||
{{*
|
||||
* AUTOMATICALLY GENERATED TEMPLATE
|
||||
* DO NOT EDIT THIS FILE, CHANGES WILL BE OVERWRITTEN
|
||||
*
|
||||
*}}
|
||||
<h2>{{$banner}}</h2>
|
||||
|
||||
<p><a href="{{$base}}/admin/dbsync/check">{{$check}}</a></p>
|
||||
|
||||
<hr />
|
||||
|
Loading…
Reference in a new issue