backend bonus log exclude seeding default

This commit is contained in:
xiaomlove
2025-09-17 04:05:36 +07:00
parent 74d722b301
commit 4009337133
16 changed files with 136 additions and 31 deletions
+3 -7
View File
@@ -242,13 +242,9 @@ class SearchBoxRepository extends BaseRepository
return Category::query()->whereIn('id', $idArr)->delete();
}
public function listSections($withCategoryAndTags = true)
public function listSections($id, $withCategoryAndTags = true)
{
$modeIds = [SearchBox::getBrowseMode()];
if (SearchBox::isSpecialEnabled() && Permission::canUploadToSpecialSection()) {
$modeIds[] = SearchBox::getSpecialMode();
}
$searchBoxList = SearchBox::query()->with($withCategoryAndTags ? ['categories'] : [])->find($modeIds);
$searchBoxList = SearchBox::query()->with($withCategoryAndTags ? ['categories'] : [])->find($id);
if ($withCategoryAndTags) {
foreach ($searchBoxList as $searchBox) {
if ($searchBox->showsubcat) {
@@ -260,7 +256,7 @@ class SearchBoxRepository extends BaseRepository
return $searchBoxList;
}
public function buildSearchBoxFormSchema(SearchBox $searchBox, string $namePrefix = ""): Forms\Components\Section
public function buildSearchBoxFormSchema(SearchBox $searchBox, string $namePrefix): Forms\Components\Section
{
$lang = get_langfolder_cookie();
$heading = $searchBox->section_name[$lang] ?? nexus_trans('searchbox.sections.browse');
+43 -4
View File
@@ -1113,16 +1113,55 @@ HTML;
}
}
public function changeCategory(Collection $torrents, int $sectionId, int $categoryId): void
public function changeCategory(Collection $torrents, int $sectionId, array $specificSubCategoryAndTags): void
{
assert_has_permission(Permission::canManageTorrent());
$searchBox = SearchBox::query()->findOrFail($sectionId);
$category = $searchBox->categories()->findOrFail($categoryId);
$torrentIdArr = $torrents->pluck('id')->toArray();
if (empty($torrentIdArr)) {
do_log("torrents is empty", 'warn');
return;
}
$torrentIdStr = implode(',', $torrentIdArr);
do_log("torrentIdStr: $torrentIdStr, sectionId: $sectionId");
$searchBoxRep = new SearchBoxRepository();
$sections = $searchBoxRep->listSections(SearchBox::listAllSectionId(), true)->keyBy('id');
if (!$sections->has($sectionId)) {
throw new NexusException(nexus_trans('upload.invalid_section'));
}
/**
* @var $section SearchBox
*/
$section = $sections->get($sectionId);
$validCategoryIdArr = $section->categories->pluck('id')->toArray();
if (!empty($specificSubCategoryAndTags['category']) && !in_array($specificSubCategoryAndTags['category'], $validCategoryIdArr)) {
throw new NexusException(nexus_trans('upload.invalid_category'));
}
$baseUpdateQuery = Torrent::query()->whereIn('id', $torrentIdArr);
$updateCategoryQuery = $baseUpdateQuery->clone();
if (!empty($validCategoryId)) {
$updateCategoryQuery->whereNotIn('category', $validCategoryIdArr);
}
$updateCategoryResult = $updateCategoryQuery->update(['category' => 0]);
do_log(sprintf("update category = 0 when category not in: %s, result: %s", implode(', ', $validCategoryIdArr), $updateCategoryResult));
foreach (SearchBox::$taxonomies as $name => $info) {
$relationName = "taxonomy_{$name}";
$relation = $section->{$relationName};
if (empty($specificSubCategoryAndTags[$name])) {
continue;
}
//有指定,看是否有效
if (!$relation) {
do_log("searchBox: {$section->id} no relation of $name");
throw new NexusException(nexus_trans('upload.not_supported_sub_category_field', ['field' => $name]));
}
$validIdArr = $relation->pluck('id')->toArray();
if (!in_array($specificSubCategoryAndTags[$name], $validIdArr)) {
do_log("taxonomy {$name}, specific: {$specificSubCategoryAndTags[$name]} not in validIdArr: " . implode(', ', $validIdArr));
throw new NexusException(nexus_trans('upload.not_supported_sub_category_field', ['field' => $name]));
}
}
$operatorId = get_user_id();
$siteLogArr = [];
foreach ($torrents as $torrent) {
@@ -1139,7 +1178,7 @@ HTML;
foreach ($torrents as $torrent) {
fire_event(ModelEventEnum::TORRENT_UPDATED, $torrent);
}
do_log("success change torrent category to $categoryId, torrent count:" . $torrents->count());
do_log("success change to section $sectionId, torrent count:" . $torrents->count());
}
}
+1 -1
View File
@@ -440,7 +440,7 @@ class UploadRepository extends BaseRepository
private function getSubCategoriesAndTags(Request $request, Category $category): array
{
$searchBoxRep = new SearchBoxRepository();
$sections = $searchBoxRep->listSections()->keyBy('id');
$sections = $searchBoxRep->listSections(SearchBox::listAllSectionId())->keyBy('id');
if (!$sections->has($category->mode)) {
throw new NexusException(nexus_trans('upload.invalid_section'));
}