Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Update) Override freeleech & doubleup tags when featured #4436

Open
wants to merge 8 commits into
base: 8.x.x
Choose a base branch
from
32 changes: 28 additions & 4 deletions app/DTO/TorrentSearchFiltersDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,14 @@ final public function toSqlQueryBuilder(): Closure
->when(
config('other.freeleech'),
fn ($query) => $query->whereBetween('free', [0, 100]),
fn ($query) => $query->whereIntegerInRaw('free', (array) $this->free)
fn ($query) => $query->where(fn ($query) =>
$query
->whereIntegerInRaw('free', (array) $this->free)
->when(
in_array(100, $this->free, true),
AnabolicsAnonymous marked this conversation as resolved.
Show resolved Hide resolved
fn ($query) => $query->orWhere('featured', '=', 1)
AnabolicsAnonymous marked this conversation as resolved.
Show resolved Hide resolved
)
)
)
)
->when($this->filename !== '', fn ($query) => $query->whereRelation('files', 'name', '=', $this->filename))
Expand All @@ -335,7 +342,14 @@ final public function toSqlQueryBuilder(): Closure
)
)
)
->when($this->doubleup, fn ($query) => $query->where('doubleup', '=', 1))
->when(
$this->doubleup,
fn ($query) => $query->where(fn ($query) =>
$query
->where('doubleup', '=', 1)
->orWhere('featured', '=', 1)
)
)
->when($this->featured, fn ($query) => $query->where('featured', '=', 1))
->when($this->refundable, fn ($query) => $query->where('refundable', '=', true))
->when($this->stream, fn ($query) => $query->where('stream', '=', 1))
Expand Down Expand Up @@ -542,12 +556,22 @@ final public function toMeilisearchFilter(): array

if ($this->free !== []) {
if (!config('other.freeleech')) {
$filters[] = 'free IN '.json_encode(array_map('intval', $this->free));
if (in_array("100", $this->free, true)) {
AnabolicsAnonymous marked this conversation as resolved.
Show resolved Hide resolved
$filters[] = [
'free IN '.json_encode(array_map('intval', $this->free)),
'featured = true',
];
} else {
$filters[] = 'free IN '.json_encode(array_map('intval', $this->free));
}
}
}

if ($this->doubleup) {
$filters[] = 'doubleup = true';
$filters[] = [
'doubleup = true',
'featured = true',
];
}

if ($this->featured) {
Expand Down