attach torrent tags support delete olds

This commit is contained in:
xiaomlove
2022-09-12 22:02:57 +08:00
parent d5e81ac009
commit e5cb98cf35
8 changed files with 29 additions and 21 deletions
@@ -163,6 +163,7 @@ class TorrentResource extends Resource
$torrentRep = new TorrentRepository();
$torrentRep->setPosState($idArr, $data['pos_state']);
} catch (\Exception $exception) {
do_log($exception->getMessage() . $exception->getTraceAsString(), 'error');
Filament::notify('danger', class_basename($exception));
}
})
@@ -180,6 +181,7 @@ class TorrentResource extends Resource
$torrentRep = new TorrentRepository();
$torrentRep->syncTags($idArr);
} catch (\Exception $exception) {
do_log($exception->getMessage() . $exception->getTraceAsString(), 'error');
Filament::notify('danger', class_basename($exception));
}
})
@@ -188,11 +190,13 @@ class TorrentResource extends Resource
$actions[] = Tables\Actions\BulkAction::make('attach_tag')
->label(__('admin.resources.torrent.bulk_action_attach_tag'))
->form([
Forms\Components\Checkbox::make('remove')->label(__('admin.resources.torrent.bulk_action_attach_tag_remove_old')),
Forms\Components\CheckboxList::make('tags')
->label(__('label.tag.label'))
->columns(4)
->options(TagRepository::createBasicQuery()->pluck('name', 'id')->toArray())
->required(),
])
->icon('heroicon-o-tag')
->action(function (Collection $records, array $data) {
@@ -202,8 +206,9 @@ class TorrentResource extends Resource
$idArr = $records->pluck('id')->toArray();
try {
$torrentRep = new TorrentRepository();
$torrentRep->syncTags($idArr, $data['tags']);
$torrentRep->syncTags($idArr, $data['tags'], $data['remove'] ?? false);
} catch (\Exception $exception) {
do_log($exception->getMessage() . $exception->getTraceAsString(), 'error');
Filament::notify('danger', class_basename($exception));
}
})
+13 -13
View File
@@ -30,6 +30,7 @@ use Hashids\Hashids;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Nexus\Database\NexusDB;
@@ -572,28 +573,27 @@ class TorrentRepository extends BaseRepository
return false;
}
public function syncTags($id, array $tagIdArr = [])
public function syncTags($id, array $tagIdArr = [], $remove = true)
{
user_can('torrentmanage', true);
$idArr = Arr::wrap($id);
return NexusDB::transaction(function () use ($idArr, $tagIdArr) {
$insert = [];
return NexusDB::transaction(function () use ($idArr, $tagIdArr, $remove) {
$sql = "insert into torrent_tags (torrent_id, tag_id, created_at, updated_at) values ";
$time = now()->toDateTimeString();
$values = [];
foreach ($idArr as $torrentId) {
foreach ($tagIdArr as $tagId) {
$insert[] = [
'torrent_id' => $torrentId,
'tag_id' => $tagId,
'created_at' => $time,
'updated_at' => $time,
];
$values[] = sprintf("(%s, %s, '%s', '%s')", $torrentId, $tagId, $time, $time);
}
}
TorrentTag::query()->whereIn('torrent_id', $idArr)->delete();
if (!empty($insert)) {
TorrentTag::query()->insert($insert);
$sql .= implode(', ', $values) . " on duplicate key update updated_at = values(updated_at)";
if ($remove) {
TorrentTag::query()->whereIn('torrent_id', $idArr)->delete();
}
return count($insert);
if (!empty($values)) {
DB::insert($sql);
}
return count($values);
});
}
+4 -1
View File
@@ -138,7 +138,10 @@ class UserRepository extends BaseRepository
throw new \InvalidArgumentException("password confirmation != password");
}
$user = User::query()->findOrFail($id, ['id', 'username', 'class']);
$this->checkPermission(Auth::user(), $user);
$operator = Auth::user();
if ($operator) {
$this->checkPermission($operator, $user);
}
$secret = mksecret();
$passhash = md5($secret . $password . $secret);
$update = [
+2 -5
View File
@@ -50,7 +50,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST")
$title = $SITENAME.$lang_recover['mail_title'];
$body = <<<EOD
{$lang_recover['mail_one']}($email){$lang_recover['mail_two']}$ip{$lang_recover['mail_three']}
<b><a href="javascript:void(null)" onclick="window.open('$baseUrl/recover.php?id={$arr["id"]}&secret=$hash')"> {$lang_recover['mail_this_link']} </a></b><br />
<b><a href="$baseUrl/recover.php?id={$arr["id"]}&secret=$hash" target="_blank"> {$lang_recover['mail_this_link']} </a></b><br />
$baseUrl/recover.php?id={$arr["id"]}&secret=$hash
{$lang_recover['mail_four']}
EOD;
@@ -96,11 +96,8 @@ elseif($_SERVER["REQUEST_METHOD"] == "GET" && $take_recover && isset($_GET["id"]
{$lang_recover['mail_two_one']}{$arr["username"]}
{$lang_recover['mail_two_two']}$newpassword
{$lang_recover['mail_two_three']}
<b><a href="javascript:void(null)" onclick="window.open('$baseUrl/login.php')">{$lang_recover['mail_here']}</a></b>
{$lang_recover['mail_three_1']}
<b><a href="http://www.google.com/support/bin/answer.py?answer=23852" target='_blank'>{$lang_confirm_resend['mail_google_answer']}</a></b>
<b><a href="$baseUrl/login.php">{$lang_recover['mail_here']}</a></b>
{$lang_recover['mail_two_four']}
EOD;
sent_mail($email,$SITENAME,$SITEEMAIL,$title,$body,"details",true,false,'');
+1 -1
View File
@@ -216,7 +216,7 @@ function dltable($name, $arr, $torrent, &$isSeedBoxCaseWhens)
$seederTable = dltable($lang_viewpeerlist['text_seeders'], $seeders, $row, $isSeedBoxCaseWhens);
$leecherTable = dltable($lang_viewpeerlist['text_leechers'], $downloaders, $row, $isSeedBoxCaseWhens);
//update peer is_seed_box
if (!empty($isSeedBoxCaseWhens)) {
if (!empty($isSeedBoxCaseWhens) && get_setting('seed_box.enabled') == 'yes') {
$sql = sprintf(
"update peers set is_seed_box = case id %s end where id in (%s)",
implode(' ', array_values($isSeedBoxCaseWhens)), implode(',', array_keys($isSeedBoxCaseWhens))
+1
View File
@@ -87,6 +87,7 @@ return [
'bulk_action_remove_tag' => 'Remove tag',
'bulk_action_attach_tag' => 'Attach tag',
'action_approval' => 'Approval',
'bulk_action_attach_tag_remove_old' => 'Also delete old tags',
],
'seed_box_record' => [
'toggle_status' => 'Change status',
+1
View File
@@ -87,6 +87,7 @@ return [
'bulk_action_remove_tag' => '清除标签',
'bulk_action_attach_tag' => '设置标签',
'action_approval' => '审核',
'bulk_action_attach_tag_remove_old' => '同时删除旧标签',
],
'seed_box_record' => [
'toggle_status' => '更改状态',
+1
View File
@@ -87,6 +87,7 @@ return [
'bulk_action_remove_tag' => '清除標簽',
'bulk_action_attach_tag' => '設置標簽',
'action_approval' => '審核',
'bulk_action_attach_tag_remove_old' => '同時刪除舊標簽',
],
'seed_box_record' => [
'toggle_status' => '更改狀態',