]> git.mxchange.org Git - friendica.git/commitdiff
Enhance the database structure checks when they failed.
authorMichael Vogel <icarus@dabo.de>
Thu, 4 Sep 2014 07:26:56 +0000 (09:26 +0200)
committerMichael Vogel <icarus@dabo.de>
Thu, 4 Sep 2014 07:26:56 +0000 (09:26 +0200)
boot.php
include/dbstructure.php
mod/admin.php
view/templates/structure_check.tpl [new file with mode: 0644]

index c72f8c8bf5decea223f68d453011d1dec49f8f75..5ef24f4944b7060ad5483211e468a3233f4a187f 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -1023,9 +1023,28 @@ if(! function_exists('update_db')) {
                                        set_config('database','dbupdate_'.DB_UPDATE_VERSION, time());
 
                                        require_once("include/dbstructure.php");
-                                       update_structure(false, true);
-
-                                       set_config('database','dbupdate_'.DB_UPDATE_VERSION, 'success');
+                                       $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 ++) {
                                                if(function_exists('update_' . $x)) {
index 654dd7492d9819ea004eb6dce684fb03faec88a7..77482d41ba2edb0b2c0c5b102f1fc534d0d669f8 100644 (file)
@@ -175,7 +175,7 @@ function update_structure($verbose, $action) {
                        if ($action) {
                                $r = @$db->q($sql3);
                                if(false === $r)
-                                       $errors .=  t('Errors encountered performing database changes.').$sql3.EOL;
+                                       $errors .= t('Errors encountered performing database changes.').$sql3.EOL;
                        }
                }
        }
index fa4f6d7fb4d4d7b4bafb3c529c5a841e47745768..24069c5d9b5c046e758957673553990ac18b7853 100644 (file)
@@ -649,7 +649,7 @@ function admin_page_site(&$a) {
                '$proxy_disabled'       => array('proxy_disabled', t("Disable picture proxy"), get_config('system','proxy_disabled'), t("The picture proxy increases performance and privacy. It shouldn't be used on systems with very low bandwith.")),
 
                '$relocate_url'     => array('relocate_url', t("New base url"), $a->get_baseurl(), "Change base url for this server. Sends relocate message to all DFRN contacts of all users."),
-               
+
                '$enable_noscrape'=> array('enable_noscrape', t("Enable noscrape"), get_config('system','enable_noscrape'), t("The noscrape feature speeds up directory submissions by using JSON data instead of HTML scraping.")),
     '$form_security_token' => get_form_security_token("admin_site")
 
@@ -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,17 +715,22 @@ function admin_page_dbsync(&$a) {
                        $failed[] = $upd;
                }
        }
-       if(! count($failed))
-               return '<h3>' . t('No failed updates.') . '</h3>';
-
-       $o = replace_macros(get_markup_template('failed_updates.tpl'),array(
-               '$base' => $a->get_baseurl(true),
-               '$banner' => t('Failed Updates'),
-               '$desc' => t('This does not include updates prior to 1139, which did not return a status.'),
-               '$mark' => t('Mark success (if update was manually applied)'),
-               '$apply' => t('Attempt to execute this update step automatically'),
-               '$failed' => $failed
-       ));
+       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'),
+                       '$desc' => t('This does not include updates prior to 1139, which did not return a status.'),
+                       '$mark' => t('Mark success (if update was manually applied)'),
+                       '$apply' => t('Attempt to execute this update step automatically'),
+                       '$failed' => $failed
+               ));
+       }
 
        return $o;
 
diff --git a/view/templates/structure_check.tpl b/view/templates/structure_check.tpl
new file mode 100644 (file)
index 0000000..09f5fec
--- /dev/null
@@ -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 />
+