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