From 56994c542aff08e6eba913c6afcebf8f3fac485b Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Mon, 9 Jun 2025 02:29:15 +0700 Subject: [PATCH] user add last_announce_at/seeding_torrent_count/seeding_torrent_size --- app/Console/Commands/Test.php | 9 +++++ .../Resources/Oauth/AuthCodeResource.php | 2 +- app/Jobs/CalculateUserSeedBonus.php | 7 +++- app/Jobs/CheckCleanup.php | 2 +- app/Repositories/UpgradeRepository.php | 20 ++++++++++ ..._handle_not_null_default_0000_datetime.php | 15 +------- ...ing_torrent_count_field_to_users_table.php | 30 +++++++++++++++ ...4_153154_update_invalid_datetime_value.php | 37 +++++++++++++++++++ include/constants.php | 4 +- public/announce.php | 1 + public/invite.php | 17 ++++----- public/takesignup.php | 2 +- 12 files changed, 116 insertions(+), 30 deletions(-) create mode 100644 app/Repositories/UpgradeRepository.php create mode 100644 database/migrations/2025_06_03_140409_add_seeding_torrent_count_field_to_users_table.php create mode 100644 database/migrations/2025_06_04_153154_update_invalid_datetime_value.php diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index 5f8228ad..7c984b73 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -14,6 +14,7 @@ use App\Repositories\ExamRepository; use App\Repositories\SeedBoxRepository; use App\Repositories\UploadRepository; use Illuminate\Console\Command; +use Illuminate\Support\Facades\DB; use Nexus\PTGen\PTGen; use NexusPlugin\Menu\Filament\MenuItemResource\Pages\ManageMenuItems; use NexusPlugin\Menu\MenuRepository; @@ -59,7 +60,15 @@ class Test extends Command */ public function handle() { + $failedJob = DB::table('failed_jobs')->find(555); + $payload = json_decode($failedJob->payload, true); + dd($payload); + + $base64 = $payload['data']['command']; + $job = unserialize($base64); + + dd($job); } } diff --git a/app/Filament/Resources/Oauth/AuthCodeResource.php b/app/Filament/Resources/Oauth/AuthCodeResource.php index 9541ec70..0333c55f 100644 --- a/app/Filament/Resources/Oauth/AuthCodeResource.php +++ b/app/Filament/Resources/Oauth/AuthCodeResource.php @@ -46,7 +46,7 @@ class AuthCodeResource extends Resource return $table ->columns([ Tables\Columns\TextColumn::make('id'), - Tables\Columns\TextColumn::make('user.username') + Tables\Columns\TextColumn::make('user_id') ->label(__('label.username')) ->formatStateUsing(fn ($record) => username_for_admin($record->user_id)), Tables\Columns\TextColumn::make('client.name') diff --git a/app/Jobs/CalculateUserSeedBonus.php b/app/Jobs/CalculateUserSeedBonus.php index eff77bd9..99602f58 100644 --- a/app/Jobs/CalculateUserSeedBonus.php +++ b/app/Jobs/CalculateUserSeedBonus.php @@ -90,6 +90,7 @@ class CalculateUserSeedBonus implements ShouldQueue do_log("$logPrefix, [GET_UID_REAL], count: " . count($results) . ", logFile: $logFile"); $fd = fopen($logFile, 'a'); $seedPointsUpdates = $seedPointsPerHourUpdates = $seedBonusUpdates = []; + $seedingTorrentCountUpdates = $seedingTorrentSizeUpdates = []; $logStr = ""; foreach ($results as $userInfo) { @@ -129,6 +130,8 @@ class CalculateUserSeedBonus implements ShouldQueue // NexusDB::statement($sql); $seedPointsUpdates[] = sprintf("when %d then ifnull(seed_points, 0) + %f", $uid, $seed_points); $seedPointsPerHourUpdates[] = sprintf("when %d then %f", $uid, $seedBonusResult['seed_points']); + $seedingTorrentCountUpdates[] = sprintf("when %d then %f", $uid, $seedBonusResult['count']); + $seedingTorrentSizeUpdates[] = sprintf("when %d then %f", $uid, $seedBonusResult['size']); $seedBonusUpdates[] = sprintf("when %d then seedbonus + %f", $uid, $all_bonus); if ($fd) { $log = sprintf( @@ -145,8 +148,8 @@ class CalculateUserSeedBonus implements ShouldQueue } $nowStr = now()->toDateTimeString(); $sql = sprintf( - "update users set seed_points = case id %s end, seed_points_per_hour = case id %s end, seedbonus = case id %s end, seed_points_updated_at = '%s' where id in (%s)", - implode(" ", $seedPointsUpdates), implode(" ", $seedPointsPerHourUpdates), implode(" ", $seedBonusUpdates), $nowStr, $idStr + "update users set seed_points = case id %s end, seed_points_per_hour = case id %s end, seedbonus = case id %s end, seeding_torrent_count = case id %s end, seeding_torrent_size = case id %s end, seed_points_updated_at = '%s' where id in (%s)", + implode(" ", $seedPointsUpdates), implode(" ", $seedPointsPerHourUpdates), implode(" ", $seedBonusUpdates), implode(" ", $seedingTorrentCountUpdates), implode(" ", $seedingTorrentSizeUpdates), $nowStr, $idStr ); $result = NexusDB::statement($sql); if ($delIdRedisKey) { diff --git a/app/Jobs/CheckCleanup.php b/app/Jobs/CheckCleanup.php index 570f002a..2378bab0 100644 --- a/app/Jobs/CheckCleanup.php +++ b/app/Jobs/CheckCleanup.php @@ -12,7 +12,7 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -class CheckCleanup implements ShouldQueue +class CheckCleanup { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; diff --git a/app/Repositories/UpgradeRepository.php b/app/Repositories/UpgradeRepository.php new file mode 100644 index 00000000..0f08e311 --- /dev/null +++ b/app/Repositories/UpgradeRepository.php @@ -0,0 +1,20 @@ + ['editdate'], + 'invites' => ['time_invited'], + 'offers' => ['allowedtime'], + 'peers' => ['last_action', 'prev_action'], + 'posts' => ['editdate'], + 'snatched' => ['last_action', 'completedat'], + 'torrents' => ['last_action', 'promotion_until', 'picktime', 'last_reseed'], + 'users' => [ + 'last_login', 'last_access', 'last_home', 'last_offer', 'forum_access', 'last_staffmsg', + 'last_pm', 'last_comment', 'last_post', 'donoruntil', 'warneduntil', 'noaduntil', 'vip_until', + 'leechwarnuntil', 'lastwarned', + ], + ]; +} diff --git a/database/migrations/2022_04_05_022036_handle_not_null_default_0000_datetime.php b/database/migrations/2022_04_05_022036_handle_not_null_default_0000_datetime.php index 9ed075ed..8d1f57fb 100644 --- a/database/migrations/2022_04_05_022036_handle_not_null_default_0000_datetime.php +++ b/database/migrations/2022_04_05_022036_handle_not_null_default_0000_datetime.php @@ -13,20 +13,7 @@ return new class extends Migration */ public function up() { - $tableFields = [ - 'comments' => ['editdate'], - 'invites' => ['time_invited'], - 'offers' => ['allowedtime'], - 'peers' => ['last_action', 'prev_action'], - 'posts' => ['editdate'], - 'snatched' => ['last_action', 'completedat'], - 'torrents' => ['last_action', 'promotion_until', 'picktime', 'last_reseed'], - 'users' => [ - 'last_login', 'last_access', 'last_home', 'last_offer', 'forum_access', 'last_staffmsg', - 'last_pm', 'last_comment', 'last_post', 'donoruntil', 'warneduntil', 'noaduntil', 'vip_until', - 'leechwarnuntil', 'lastwarned', - ], - ]; + $tableFields = \App\Repositories\UpgradeRepository::DATETIME_INVALID_VALUE_FIELDS; foreach ($tableFields as $table => $fields) { $columnInfo = \Nexus\Database\NexusDB::getMysqlColumnInfo($table); diff --git a/database/migrations/2025_06_03_140409_add_seeding_torrent_count_field_to_users_table.php b/database/migrations/2025_06_03_140409_add_seeding_torrent_count_field_to_users_table.php new file mode 100644 index 00000000..6a2b82e9 --- /dev/null +++ b/database/migrations/2025_06_03_140409_add_seeding_torrent_count_field_to_users_table.php @@ -0,0 +1,30 @@ +integer("seeding_torrent_count")->default(0); + $table->bigInteger("seeding_torrent_size")->default(0); + $table->dateTime("last_announce_at")->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn("seeding_torrent_count", "seeding_torrent_size", "last_announce_at"); + }); + } +}; diff --git a/database/migrations/2025_06_04_153154_update_invalid_datetime_value.php b/database/migrations/2025_06_04_153154_update_invalid_datetime_value.php new file mode 100644 index 00000000..775cce11 --- /dev/null +++ b/database/migrations/2025_06_04_153154_update_invalid_datetime_value.php @@ -0,0 +1,37 @@ + $fields) { + $columnInfo = \Nexus\Database\NexusDB::getMysqlColumnInfo($table); + foreach ($fields as $field) { + if (isset($columnInfo[$field]) && $columnInfo[$field]['DATA_TYPE'] == 'datetime') { + \Illuminate\Support\Facades\DB::statement("update $table set $field = null where $field = '0000-00-00 00:00:00'"); + } + } + } + $columnInfo = \Nexus\Database\NexusDB::getMysqlColumnInfo("snatched"); + if (isset($columnInfo["finish_ip"])) { + \Illuminate\Support\Facades\DB::statement("alter table snatched drop column finish_ip"); + } + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // + } +}; diff --git a/include/constants.php b/include/constants.php index 65b18d67..c4ab8af0 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ ".$lang_invite['text_no_invites'].""); } else { list($pagertop, $pagerbottom, $limit) = pager($pageSize, $number, "?id=$id&menu=$menuSelected&"); - $haremAdditionFactor = get_setting('bonus.harem_addition'); - $ret = sql_query("SELECT id, username, email, uploaded, downloaded, status, warned, enabled, donor, email FROM users WHERE $whereStr $limit") or sqlerr(); + $haremAdditionFactor = (float)get_setting('bonus.harem_addition'); + $ret = sql_query("SELECT id, username, email, uploaded, downloaded, status, warned, enabled, donor, email,seeding_torrent_count, seeding_torrent_size, last_announce_at FROM users WHERE $whereStr $limit") or sqlerr(); $num = mysql_num_rows($ret); print(" @@ -208,7 +208,6 @@ JS; $status = "".$lang_invite['text_confirmed'].""; else $status = "".$lang_invite['text_pending'].""; - $seedBonusResult = calculate_seed_bonus($arr['id']); print(" ".get_username($arr['id'])." {$arr['email']} @@ -216,15 +215,15 @@ JS; " . mksize($arr['uploaded']) . " " . mksize($arr['downloaded']) . " $ratio -{$seedBonusResult['count']} -".mksize($seedBonusResult['size'])." -".number_format($seedBonusResult['seed_points'], 3)." +".number_format($arr['seeding_torrent_count'])." +".mksize($arr['seeding_torrent_size'])." +".number_format($arr['seed_points_per_hour'], 3)." "); if ($haremAdditionFactor > 0) { - print ("".number_format($seedBonusResult['seed_points'] * $haremAdditionFactor, 3).""); + print ("".number_format(floatval($arr['seed_points_per_hour']) * $haremAdditionFactor, 3).""); } - print("{$seedBonusResult['last_action']}"); + print("{$arr['last_announce_at']}"); print("$status"); if ($CURUSER['id'] == $id || get_user_class() >= UC_SYSOP){ print(""); @@ -240,7 +239,7 @@ JS; if ($CURUSER['id'] == $id || get_user_class() >= UC_SYSOP) { $pendingcount = number_format(get_row_count("users", "WHERE status='pending' AND invited_by={$CURUSER['id']}")); - $colSpan = 7; + $colSpan = 12; if (isset($haremAdditionFactor) && $haremAdditionFactor > 0) { $colSpan += 1; } diff --git a/public/takesignup.php b/public/takesignup.php index a801b5e2..d96ef3d6 100644 --- a/public/takesignup.php +++ b/public/takesignup.php @@ -229,7 +229,7 @@ if ($type == 'invite') $dt = date("Y-m-d H:i:s"); $locale = get_user_locale($inviter); $subject = nexus_trans("user.msg_invited_user_has_registered", [], $locale); - $msg = nexus_trans("user.msg_user_you_invited", [],$locale).$usern.nexus_trans("user.msg_has_registered", [], $locale); + $msg = nexus_trans("user.msg_user_you_invited", [],$locale).$wantusername.nexus_trans("user.msg_has_registered", [], $locale); //sql_query("UPDATE users SET uploaded = uploaded + 10737418240 WHERE id = $inviter"); //add 10GB to invitor's uploading credit \App\Models\Message::add([ 'sender' => 0,