diff --git a/app/Models/HitAndRun.php b/app/Models/HitAndRun.php index c93fc77c..6dd8d70d 100644 --- a/app/Models/HitAndRun.php +++ b/app/Models/HitAndRun.php @@ -62,7 +62,12 @@ class HitAndRun extends NexusModel if ($this->status != self::STATUS_INSPECTING) { return '---'; } - $inspectTime = HitAndRun::getConfig('inspect_time', $this->torrent->basic_category->mode); + $searchBoxId = $this->torrent->basic_category->mode ?? 0; + if ($searchBoxId == 0) { + do_log(sprintf('[INVALID_CATEGORY], Torrent: %s', $this->torrent_id), 'error'); + return '---'; + } + $inspectTime = HitAndRun::getConfig('inspect_time', $searchBoxId); $diffInSeconds = Carbon::now()->diffInSeconds($this->snatch->completedat->addHours($inspectTime)); return mkprettytime($diffInSeconds); } @@ -72,7 +77,12 @@ class HitAndRun extends NexusModel if ($this->status != self::STATUS_INSPECTING) { return '---'; } - $seedTimeMinimum = HitAndRun::getConfig('seed_time_minimum', $this->torrent->basic_category->mode); + $searchBoxId = $this->torrent->basic_category->mode ?? 0; + if ($searchBoxId == 0) { + do_log(sprintf('[INVALID_CATEGORY], Torrent: %s', $this->torrent_id), 'error'); + return '---'; + } + $seedTimeMinimum = HitAndRun::getConfig('seed_time_minimum', $searchBoxId); $diffInSeconds = 3600 * $seedTimeMinimum - $this->snatch->seedtime; return mkprettytime($diffInSeconds); } diff --git a/app/Models/Torrent.php b/app/Models/Torrent.php index 9f792ef1..155495e2 100644 --- a/app/Models/Torrent.php +++ b/app/Models/Torrent.php @@ -303,7 +303,12 @@ class Torrent extends NexusModel public function getHrAttribute(): string { // $hrMode = Setting::get('hr.mode'); - $hrMode = HitAndRun::getConfig('mode', $this->basic_category->mode); + $searchBoxId = $this->basic_category->mode ?? 0; + if ($searchBoxId == 0) { + do_log(sprintf('[INVALID_CATEGORY], Torrent: %s, category: %s invalid', $this->id, $this->category), 'error'); + return self::HR_NO; + } + $hrMode = HitAndRun::getConfig('mode', $searchBoxId); if ($hrMode == HitAndRun::MODE_GLOBAL) { return self::HR_YES; } diff --git a/app/Repositories/SearchRepository.php b/app/Repositories/SearchRepository.php index afa9d26b..4054b517 100644 --- a/app/Repositories/SearchRepository.php +++ b/app/Repositories/SearchRepository.php @@ -301,8 +301,12 @@ class SearchRepository extends BaseRepository $idName => $this->getTorrentId($torrent->id), 'routing' => $torrent->owner, ]; + $searchBoxId = $torrent->basic_category->mode ?? 0; + if ($searchBoxId == 0) { + do_log(sprintf('[INVALID_CATEGORY], Torrent: %s', $torrent->id), 'error'); + } $data = Arr::only($torrent->toArray(), $baseFields); - $data['mode'] = $torrent->basic_category->mode; + $data['mode'] = $searchBoxId; $body = array_merge($data, [ '_doc_type' => $docType, 'torrent_id' => $torrent->id, diff --git a/app/Repositories/TrackerRepository.php b/app/Repositories/TrackerRepository.php index c438d3b0..22fee05f 100644 --- a/app/Repositories/TrackerRepository.php +++ b/app/Repositories/TrackerRepository.php @@ -1093,7 +1093,12 @@ class TrackerRepository extends BaseRepository return; } // $hrMode = Setting::get('hr.mode'); - $hrMode = HitAndRun::getConfig('mode', $torrent->basic_category->mode); + $searchBoxId = $torrent->basic_category->mode ?? 0; + if ($searchBoxId == 0) { + do_log(sprintf('[INVALID_CATEGORY], Torrent: %s', $torrent->id), 'error'); + return; + } + $hrMode = HitAndRun::getConfig('mode', $searchBoxId); if ($hrMode == HitAndRun::MODE_DISABLED) { return; } diff --git a/include/constants.php b/include/constants.php index 17c9524b..880949ba 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ findOrFail(intval($torrent), ['id', 'category'])->basic_category->mode; + $torrent = \App\Models\Torrent::query()->findOrFail(intval($torrent), ['id', 'category']); + $searchBoxId = $torrent->basic_category->mode ?? 0; + if ($searchBoxId == 0) { + do_log("[INVALID_CATEGORY], torrent: " . $torrent->id, 'error'); + return false; + } } else { throw new \InvalidArgumentException("Unsupported argument: " . json_encode($torrent)); }