delete snatched check user and torrent

This commit is contained in:
xiaomlove
2024-12-17 13:12:58 +08:00
parent ca21b0b7fe
commit edadbf0048
4 changed files with 21 additions and 7 deletions

View File

@@ -16,6 +16,7 @@ use App\Repositories\TagRepository;
use App\Repositories\TorrentRepository;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Pages\Actions\Action;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
@@ -113,7 +114,8 @@ class TorrentResource extends Resource
->defaultSort('id', 'desc')
->filters(self::getFilters())
->actions(self::getActions())
->bulkActions(self::getBulkActions());
->bulkActions(self::getBulkActions())
;
}
@@ -339,6 +341,13 @@ class TorrentResource extends Resource
$actions[] = Tables\Actions\DeleteAction::make('delete')->using(function ($record) {
deletetorrent($record->id);
});
// $actions[] = Tables\Actions\Action::make('view')
// ->action(function (Torrent $record) {
// return [
// 'modelContent' => new HtmlString("ssss")
// ];
// })
// ;
}
return $actions;
}

View File

@@ -10,6 +10,7 @@ use App\Models\Invite;
use App\Models\LoginLog;
use App\Models\Message;
use App\Models\Setting;
use App\Models\Snatch;
use App\Models\User;
use App\Models\UserBanLog;
use App\Models\UserMeta;
@@ -636,9 +637,10 @@ class UserRepository extends BaseRepository
} else {
$uidArr = $id->pluck('id')->toArray();
}
$uidStr = implode(',', $uidArr);
$users = User::query()->with('language')->whereIn('id', $uidArr)->get();
if (empty($uidArr)) {
return;
if ($users->isEmpty()) {
return true;
}
$tables = [
'users' => 'id',
@@ -655,7 +657,7 @@ class UserRepository extends BaseRepository
'oauth_auth_codes' => 'user_id',
];
foreach ($tables as $table => $key) {
\Nexus\Database\NexusDB::table($table)->whereIn($key, $uidArr)->delete();
NexusDB::statement(sprintf("delete from `%s` where `%s` in (%s)", $table, $key, $uidStr));
}
do_log("[DESTROY_USER]: " . json_encode($uidArr), 'error');
$userBanLogs = [];
@@ -667,6 +669,8 @@ class UserRepository extends BaseRepository
];
}
UserBanLog::query()->insert($userBanLogs);
//delete by user, make sure torrent is deleted
NexusDB::statement(sprintf('DELETE FROM snatched WHERE userid IN (%s) and not exists (select 1 from torrents where id = snatched.torrentid)', $uidStr));
if (is_int($id)) {
do_action("user_delete", $id);
fire_event("user_destroyed", $users->first());

View File

@@ -3126,7 +3126,8 @@ function deletetorrent($id, $notify = false) {
$idStr = implode(', ', $idArr ?: [0]);
$torrent_dir = get_setting('main.torrent_dir');
\Nexus\Database\NexusDB::statement("DELETE FROM torrents WHERE id in ($idStr)");
\Nexus\Database\NexusDB::statement("DELETE FROM snatched WHERE torrentid in ($idStr)");
//delete by torrent, make sure user is deleted
\Nexus\Database\NexusDB::statement("DELETE FROM snatched WHERE torrentid in ($idStr) and not exists (select 1 from users where id = snatched.userid)");
foreach(array("peers", "files", "comments") as $x) {
\Nexus\Database\NexusDB::statement("DELETE FROM $x WHERE torrent in ($idStr)");
}

View File

@@ -616,8 +616,8 @@ if (($left > 0 || $event == "completed") && $az['class'] < \App\Models\HitAndRun
if ($snatchInfo['downloaded'] >= $requiredDownloaded) {
$nowStr = date('Y-m-d H:i:s');
$sql = sprintf(
"insert into hit_and_runs (uid, torrent_id, snatched_id, created_at, updated_at) values (%d, %d, %d, '%s', '%s') on duplicate key update created_at = '%s', updated_at = '%s'",
$userid, $torrentid, $snatchInfo['id'], $nowStr, $nowStr, $nowStr, $nowStr
"insert into hit_and_runs (uid, torrent_id, snatched_id, created_at, updated_at) values (%d, %d, %d, '%s', '%s') on duplicate key update updated_at = '%s'",
$userid, $torrentid, $snatchInfo['id'], $nowStr, $nowStr, $nowStr
);
$affectedRows = sql_query($sql);
do_log("$hrLog, total downloaded: {$snatchInfo['downloaded']} >= required: $requiredDownloaded, [INSERT_H&R], sql: $sql, affectedRows: $affectedRows");