X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fdbstructure.php;h=75623c01c82bdca578a2a1194ed91fb604d8d14a;hb=8f2f7f8380cae8a1074ca96e8518b01fc23bc4a8;hp=1f604ae6e8810fab80621ec5b677ddc524416c8c;hpb=7eeb320085b8164cbac711b925e960ca3c921863;p=friendica.git diff --git a/include/dbstructure.php b/include/dbstructure.php index 1f604ae6e8..75623c01c8 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -1,28 +1,71 @@ config['admin_email']))))."'"; + $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)", + $admin_mail_list + ); - if(is_null($db)) { - @include(".htconfig.php"); - require_once("include/dba.php"); - $db = new dba($db_host, $db_user, $db_pass, $db_data); - unset($db_host, $db_user, $db_pass, $db_data); + // every admin could had different language + + foreach ($adminlist as $admin) { + $lang = (($admin['language'])?$admin['language']:'en'); + push_lang($lang); + + $preamble = deindent(t(" + The friendica developers released update %s recently, + but when I tried to install it, something went terribly wrong. + This needs to be fixed soon and I can't do it alone. Please contact a + friendica developer if you can not help me on your own. My database might be invalid.")); + $body = t("The error message is\n[pre]%s[/pre]"); + $preamble = sprintf($preamble, $update_id); + $body = sprintf($body, $error_message); + + notification(array( + 'type' => "SYSTEM_EMAIL", + 'to_email' => $admin['email'], + 'preamble' => $preamble, + 'body' => $body, + 'language' => $lang, + )); } - update_structure(true, true); -} -if (array_search(__file__,get_included_files())===0){ - dbstructure_run($argv,$argc); - killme(); + + + /* + $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; } + function table_structure($table) { $structures = q("DESCRIBE `%s`", $table); @@ -175,7 +218,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; } } } @@ -623,7 +666,7 @@ function db_definition() { $database["guid"] = array( "fields" => array( "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), - "guid" => array("type" => "varchar(64)", "not null" => "1"), + "guid" => array("type" => "varchar(255)", "not null" => "1"), ), "indexes" => array( "PRIMARY" => array("id"), @@ -664,7 +707,7 @@ function db_definition() { $database["item"] = array( "fields" => array( "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), - "guid" => array("type" => "varchar(64)", "not null" => "1"), + "guid" => array("type" => "varchar(255)", "not null" => "1"), "uri" => array("type" => "varchar(255)", "not null" => "1"), "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "contact-id" => array("type" => "int(11)", "not null" => "1"), @@ -1273,3 +1316,29 @@ function db_definition() { return($database); } + + +/* + * run from command line + */ +function dbstructure_run(&$argv, &$argc) { + global $a, $db; + + if(is_null($a)){ + $a = new App; + } + + if(is_null($db)) { + @include(".htconfig.php"); + require_once("include/dba.php"); + $db = new dba($db_host, $db_user, $db_pass, $db_data); + unset($db_host, $db_user, $db_pass, $db_data); + } + + update_structure(true, true); +} + +if (array_search(__file__,get_included_files())===0){ + dbstructure_run($argv,$argc); + killme(); +}