X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FDatabase%2FDBStructure.php;h=4a9bc69f618e14f1a4a2896497da01f11c941fa0;hb=b0d8a2fcd087c2a7c34460ced3c7334eccaa1c0a;hp=9abae944ae0e873d8b67a065a95f49fc2f49a07c;hpb=7ee8bdafc53a88fe51f233e14169bb4af0d376ab;p=friendica.git diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php index 9abae944ae..4a9bc69f61 100644 --- a/src/Database/DBStructure.php +++ b/src/Database/DBStructure.php @@ -8,6 +8,7 @@ use Exception; use Friendica\Core\Config; use Friendica\Core\Hook; use Friendica\Core\L10n; +use Friendica\Core\Logger; use Friendica\Util\DateTimeFormat; require_once 'boot.php'; @@ -22,6 +23,10 @@ require_once 'include/text.php'; */ class DBStructure { + const UPDATE_NOT_CHECKED = 0; // Database check wasn't executed before + const UPDATE_SUCCESSFUL = 1; // Database check was successful + const UPDATE_FAILED = 2; // Database check failed + /** * Database structure definition loaded from config/dbstructure.php * @@ -52,58 +57,6 @@ class DBStructure } } - /* - * send the email and do what is needed to do on update fails - * - * @param update_id (int) number of failed update - * @param error_message (str) error message - */ - public static function updateFail($update_id, $error_message) { - $a = get_app(); - - //send the administrators an e-mail - $admin_mail_list = "'".implode("','", array_map(['Friendica\Database\DBA', 'escape'], explode(",", str_replace(" ", "", Config::get('config', 'admin_email')))))."'"; - $adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)", - $admin_mail_list - ); - - // No valid result? - if (!DBA::isResult($adminlist)) { - logger(sprintf('Cannot notify administrators about update_id=%d, error_message=%s', $update_id, $error_message), LOGGER_INFO); - - // Don't continue - return; - } - - // every admin could had different language - foreach ($adminlist as $admin) { - $lang = (($admin['language'])?$admin['language']:'en'); - L10n::pushLang($lang); - - $preamble = deindent(L10n::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.", - $update_id)); - $body = L10n::t("The error message is\n[pre]%s[/pre]", $error_message); - - notification([ - 'uid' => $admin['uid'], - 'type' => SYSTEM_EMAIL, - 'to_email' => $admin['email'], - 'preamble' => $preamble, - 'body' => $body, - 'language' => $lang] - ); - L10n::popLang(); - } - - //try the logger - logger("CRITICAL: Database structure update failed: ".$error_message); - } - - private static function tableStructure($table) { $structures = q("DESCRIBE `%s`", $table); @@ -221,7 +174,7 @@ class DBStructure $errors = ''; - logger('updating structure', LOGGER_DEBUG); + Logger::log('updating structure', Logger::DEBUG); // Get the current structure $database = []; @@ -234,7 +187,7 @@ class DBStructure foreach ($tables AS $table) { $table = current($table); - logger(sprintf('updating structure for table %s ...', $table), LOGGER_DEBUG); + Logger::log(sprintf('updating structure for table %s ...', $table), Logger::DEBUG); $database[$table] = self::tableStructure($table); } } @@ -534,9 +487,9 @@ class DBStructure Config::set('system', 'maintenance_reason', ''); if ($errors) { - Config::set('system', 'dbupdate', DB_UPDATE_FAILED); + Config::set('system', 'dbupdate', self::UPDATE_FAILED); } else { - Config::set('system', 'dbupdate', DB_UPDATE_SUCCESSFUL); + Config::set('system', 'dbupdate', self::UPDATE_SUCCESSFUL); } }