X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fdbstructure.php;h=b8cf8e57ac4881f846cc03a4ec9f94c5c5cc1edf;hb=4584670af446553b6b7f7870e7081620ebaf44ee;hp=268bbbb66944060cb1f9b7d16b9ca464ad3f6716;hpb=638e6491cc305b0455ae890351183e03e0bce52b;p=friendica.git diff --git a/include/dbstructure.php b/include/dbstructure.php index 268bbbb669..b8cf8e57ac 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -1,6 +1,7 @@ database_name())); + dbesc(dba::database_name())); if (!dbm::is_result($r)) { echo t('There are no tables on MyISAM.')."\n"; @@ -30,9 +29,9 @@ function convert_to_innodb() { $sql = sprintf("ALTER TABLE `%s` engine=InnoDB;", dbesc($table['TABLE_NAME'])); echo $sql."\n"; - $result = $db->q($sql); + $result = dba::e($sql); if (!dbm::is_result($result)) { - print_update_error($db, $sql); + print_update_error($sql); } } } @@ -52,7 +51,7 @@ function update_fail($update_id, $error_message) { // No valid result? if (!dbm::is_result($adminlist)) { - logger(sprintf('Cannot notify administrators about update_id=%d, error_message=%s', $update_id, $error_message), LOGGER_WARNING); + logger(sprintf('Cannot notify administrators about update_id=%d, error_message=%s', $update_id, $error_message), LOGGER_NORMAL); // Don't continue return; @@ -73,7 +72,7 @@ function update_fail($update_id, $error_message) { $body = sprintf($body, $error_message); notification(array( - 'type' => "SYSTEM_EMAIL", + 'type' => SYSTEM_EMAIL, 'to_email' => $admin['email'], 'preamble' => $preamble, 'body' => $body, @@ -89,11 +88,11 @@ function update_fail($update_id, $error_message) { $email_tpl = get_intltext_template("update_fail_eml.tpl"); $email_msg = replace_macros($email_tpl, array( '$sitename' => $a->config['sitename'], - '$siteurl' => App::get_baseurl(), + '$siteurl' => System::baseUrl(), '$update' => DB_UPDATE_VERSION, '$error' => sprintf(t('Update %s failed. See error logs.'), DB_UPDATE_VERSION) )); - $subject=sprintf(t('Update Error at %s'), App::get_baseurl()); + $subject=sprintf(t('Update Error at %s'), System::baseUrl()); require_once('include/email.php'); $subject = email_header_encode($subject,'UTF-8'); mail($a->config['admin_email'], $subject, $email_msg, @@ -187,20 +186,19 @@ function print_structure($database) { /** * @brief Print out database error messages * - * @param object $db Database object * @param string $message Message to be added to the error message * * @return string Error message */ -function print_update_error($db, $message) { +function print_update_error($message) { echo sprintf(t("\nError %d occurred during database update:\n%s\n"), - $db->errorno, $db->error); + dba::errorNo(), dba::errorMessage()); return t('Errors encountered performing database changes: ').$message.EOL; } function update_structure($verbose, $action, $tables=null, $definition=null) { - global $a, $db; + global $a; if ($action) { Config::set('system', 'maintenance', 1); @@ -233,8 +231,8 @@ function update_structure($verbose, $action, $tables=null, $definition=null) { } // MySQL >= 5.7.4 doesn't support the IGNORE keyword in ALTER TABLE statements - if ((version_compare($db->server_info(), '5.7.4') >= 0) && - !(strpos($db->server_info(), 'MariaDB') !== false)) { + if ((version_compare(dba::server_info(), '5.7.4') >= 0) && + !(strpos(dba::server_info(), 'MariaDB') !== false)) { $ignore = ''; } else { $ignore = ' IGNORE'; @@ -248,7 +246,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) { if (!isset($database[$name])) { $r = db_create_table($name, $structure["fields"], $verbose, $action, $structure['indexes']); if (!dbm::is_result($r)) { - $errors .= print_update_error($db, $name); + $errors .= print_update_error($name); } $is_new_table = True; } else { @@ -441,37 +439,37 @@ function update_structure($verbose, $action, $tables=null, $definition=null) { // Ensure index conversion to unique removes duplicates if ($is_unique) { if ($ignore != "") { - $db->q("SET session old_alter_table=1;"); + dba::e("SET session old_alter_table=1;"); } else { - $r = $db->q("CREATE TABLE `".$temp_name."` LIKE `".$name."`;"); + $r = dba::e("CREATE TABLE `".$temp_name."` LIKE `".$name."`;"); if (!dbm::is_result($r)) { - $errors .= print_update_error($db, $sql3); + $errors .= print_update_error($sql3); return $errors; } } } - $r = @$db->q($sql3); + $r = @dba::e($sql3); if (!dbm::is_result($r)) { - $errors .= print_update_error($db, $sql3); + $errors .= print_update_error($sql3); } if ($is_unique) { if ($ignore != "") { - $db->q("SET session old_alter_table=0;"); + dba::e("SET session old_alter_table=0;"); } else { - $r = $db->q("INSERT INTO `".$temp_name."` SELECT ".$field_list." FROM `".$name."`".$group_by.";"); + $r = dba::e("INSERT INTO `".$temp_name."` SELECT ".$field_list." FROM `".$name."`".$group_by.";"); if (!dbm::is_result($r)) { - $errors .= print_update_error($db, $sql3); + $errors .= print_update_error($sql3); return $errors; } - $r = $db->q("DROP TABLE `".$name."`;"); + $r = dba::e("DROP TABLE `".$name."`;"); if (!dbm::is_result($r)) { - $errors .= print_update_error($db, $sql3); + $errors .= print_update_error($sql3); return $errors; } - $r = $db->q("RENAME TABLE `".$temp_name."` TO `".$name."`;"); + $r = dba::e("RENAME TABLE `".$temp_name."` TO `".$name."`;"); if (!dbm::is_result($r)) { - $errors .= print_update_error($db, $sql3); + $errors .= print_update_error($sql3); return $errors; } } @@ -521,7 +519,7 @@ function db_field_command($parameters, $create = true) { } function db_create_table($name, $fields, $verbose, $action, $indexes=null) { - global $a, $db; + global $a; $r = true; @@ -550,7 +548,7 @@ function db_create_table($name, $fields, $verbose, $action, $indexes=null) { echo $sql.";\n"; if ($action) - $r = @$db->q($sql); + $r = @dba::e($sql); return $r; } @@ -1572,7 +1570,7 @@ function db_definition() { ), "indexes" => array( "PRIMARY" => array("id"), - "iid" => array("iid"), + "iid" => array("UNIQUE", "iid"), ) ); $database["spam"] = array( @@ -1656,6 +1654,7 @@ function db_definition() { "uid_created" => array("uid","created"), "uid_commented" => array("uid","commented"), "uid_wall_created" => array("uid","wall","created"), + "private_wall_received" => array("private","wall","received"), ) ); $database["tokens"] = array( @@ -1747,6 +1746,7 @@ function db_definition() { "pid" => array("pid"), "parameter" => array("parameter(64)"), "priority_created" => array("priority", "created"), + "executed" => array("executed"), ) ); @@ -1758,18 +1758,16 @@ function db_definition() { * run from command line */ function dbstructure_run(&$argv, &$argc) { - global $a, $db; + global $a; - if (is_null($a)) { + if (empty($a)) { $a = new App(dirname(__DIR__)); } - 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); - } + @include ".htconfig.php"; + require_once "include/dba.php"; + dba::connect($db_host, $db_user, $db_pass, $db_data); + unset($db_host, $db_user, $db_pass, $db_data); if ($argc == 2) { switch ($argv[1]) {