From 52867d0faa8b1ee6ddbdef9495fa277cddeeb048 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Fri, 19 Aug 2022 17:02:35 +0800 Subject: [PATCH] add reset user id auto_increment command --- .../Commands/UserResetIdAutoIncrement.php | 90 +++++++++++++++++++ include/constants.php | 5 +- include/functions.php | 6 +- public/ipsearch.php | 2 +- public/usercp.php | 14 +-- 5 files changed, 104 insertions(+), 13 deletions(-) create mode 100644 app/Console/Commands/UserResetIdAutoIncrement.php diff --git a/app/Console/Commands/UserResetIdAutoIncrement.php b/app/Console/Commands/UserResetIdAutoIncrement.php new file mode 100644 index 00000000..456e189f --- /dev/null +++ b/app/Console/Commands/UserResetIdAutoIncrement.php @@ -0,0 +1,90 @@ +options(); + $requires = ['auto_increment', 'admin', 'password', 'email']; + foreach ($requires as $option) { + if (empty($options[$option])) { + $this->error("Require --$option"); + return 1; + } + } + $log = "options: " . json_encode($options); + $this->info($log); + + $tablesToTruncate = [ + 'adclicks', 'attachments', 'attendance', 'attendance_logs', 'bitbucket', 'blocks', 'bonus_logs', 'bookmarks', 'cheaters', 'chronicle', + 'claims', 'comments', 'complain_replies', 'complains', 'exam_progress', 'exam_users', 'forummods', 'friends', 'fun', 'funds', 'funvotes', + 'hit_and_runs', 'invites', 'iplog', 'loginattempts', 'lucky_draw_winning_records', 'magic', 'messages', 'offers', 'offervotes', 'peers', + 'pmboxes', 'pollanswers', 'posts', 'prolinkclicks', 'readposts', 'reports', 'requests', 'seed_box_records', 'shoutbox', 'snatched', + 'staffmessages', 'sticky_promotion_appends', 'sticky_promotion_participators', 'sticky_promotions', 'subs', 'suggest', 'thanks', 'topics', + 'torrent_operation_logs', 'torrent_secrets', 'torrents', 'user_ban_logs', 'user_medals', 'user_metas', 'user_permissions', 'user_roles', + 'username_change_logs', 'users', + ]; + $allTables = DB::select('show tables'); + foreach ($allTables as $tableObj) { + $tableName = current($tableObj); + if (in_array($tableName, $tablesToTruncate)) { + $this->info("truncate table: $tableName ..."); + DB::table($tableName)->truncate(); + } + } + $statement = "alter table users auto_increment = " . $options['auto_increment']; + $this->info($statement); + $result = DB::statement($statement); + + $userRep = new UserRepository(); + $insert = [ + 'username' => $options['admin'], + 'email' => $options['email'], + 'password' => $options['password'], + 'password_confirmation' => $options['password'], + 'class' => User::CLASS_STAFF_LEADER, + 'id' => 1, + ]; + $userRep->store($insert); + + $log = sprintf('[%s], %s, result: %s', nexus()->getRequestId(), __METHOD__, var_export($result, true)); + $this->info($log); + do_log($log); + } +} diff --git a/include/constants.php b/include/constants.php index 1dfb8182..09fd47be 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,12 +1,13 @@ ".PROJECTNAME.""); defined('THISTRACKER') || define("THISTRACKER","General"); +defined('CONTENT_WIDTH') || define("CONTENT_WIDTH", 1200); defined('ROOT_PATH') || define('ROOT_PATH', dirname(__DIR__) . '/'); defined('DEFAULT_TRACKER_URI') || define('DEFAULT_TRACKER_URI', '/announce.php'); if (!defined('RUNNING_IN_OCTANE')) { diff --git a/include/functions.php b/include/functions.php index 7688c170..1317c560 100644 --- a/include/functions.php +++ b/include/functions.php @@ -615,7 +615,7 @@ function begin_main_frame($caption = "", $center = false, $width = 100) $tdextra .= " align=\"center\""; if (!str_ends_with($width, '%')) { - $width = 1200 * $width / 100; + $width = CONTENT_WIDTH * $width / 100; } print("" . @@ -2551,7 +2551,7 @@ foreach (\Nexus\Nexus::getAppendHeaders() as $value) { -
+
- +
". +print("
". "". "". "".
".$lang_usercp['col_topic_title']."".$lang_usercp['col_replies']."/".$lang_usercp['col_views']."".$lang_usercp['col_topic_starter']."