mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +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->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));
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
Reference in New Issue
Block a user