Skip to content

Commit c7f8e22

Browse files
committed
update: store null for metadata id if they do not exist
And make it difficult / encourage users to submit the ids instead of leaving them empty.
1 parent 5418fe8 commit c7f8e22

15 files changed

+1170
-515
lines changed

app/DTO/TorrentSearchFiltersDTO.php

+37-7
Original file line numberDiff line numberDiff line change
@@ -534,22 +534,52 @@ final public function toMeilisearchFilter(): array
534534
}
535535

536536
if ($this->tmdbId !== null) {
537-
$filters[] = [
538-
'tmdb_movie_id = '.$this->tmdbId,
539-
'tmdb_tv_id = '.$this->tmdbId,
540-
];
537+
if ($this->tmdbId === 0) {
538+
$filters[] = [
539+
'tmdb_movie_id IS NULL AND tmdb_tv_id IS NOT NULL',
540+
'tmdb_tv_id IS NULL AND tmdb_movie_id IS NOT NULL',
541+
'tmdb_movie_id = 0 AND tmdb_tv_id != 0',
542+
'tmdb_tv_id = 0 AND tmdb_movie_id != 0',
543+
];
544+
} else {
545+
$filters[] = [
546+
'tmdb_movie_id = '.$this->tmdbId,
547+
'tmdb_tv_id = '.$this->tmdbId,
548+
];
549+
}
541550
}
542551

543552
if ($this->imdbId !== null) {
544-
$filters[] = 'imdb = '.$this->imdbId;
553+
if ($this->imdbId === 0) {
554+
$filters[] = [
555+
'imdb IS NULL',
556+
'imdb = 0',
557+
];
558+
} else {
559+
$filters[] = 'imdb = '.$this->imdbId;
560+
}
545561
}
546562

547563
if ($this->tvdbId !== null) {
548-
$filters[] = 'tvdb = '.$this->tvdbId;
564+
if ($this->tvdbId === 0) {
565+
$filters[] = [
566+
'tvdb IS NULL',
567+
'tvdb = 0',
568+
];
569+
} else {
570+
$filters[] = 'tvdb = '.$this->tvdbId;
571+
}
549572
}
550573

551574
if ($this->malId !== null) {
552-
$filters[] = 'mal = '.$this->malId;
575+
if ($this->malId === 0) {
576+
$filters[] = [
577+
'mal IS NULL',
578+
'mal = 0',
579+
];
580+
} else {
581+
$filters[] = 'mal = '.$this->malId;
582+
}
553583
}
554584

555585
if ($this->playlistId !== null) {

app/Http/Requests/StoreTorrentRequest.php

+39-31
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ public function authorize(): bool
3838
return true;
3939
}
4040

41+
/**
42+
* Prepare the data for validation.
43+
*/
44+
protected function prepareForValidation(): void
45+
{
46+
$this->merge([
47+
'tmdb_movie_id' => $this->has('movie_exists_on_tmdb') ? ($this->input('tmdb_movie_id') ?: null) : null,
48+
'tmdb_tv_id' => $this->has('tv_exists_on_tmdb') ? ($this->input('tmdb_tv_id') ?: null) : null,
49+
'imdb' => $this->has('title_exists_on_imdb') ? ($this->input('imdb') ?: null) : null,
50+
'tvdb' => $this->has('tv_exists_on_tvdb') ? ($this->input('tvdb') ?: null) : null,
51+
'mal' => $this->has('anime_exists_on_mal') ? ($this->input('mal') ?: null) : null,
52+
'igdb' => $this->has('game_exists_on_igdb') ? ($this->input('igdb') ?: null) : null,
53+
]);
54+
}
55+
4156
/**
4257
* Get the validation rules that apply to the request.
4358
*
@@ -48,6 +63,12 @@ public function rules(Request $request): array
4863
$user = $request->user()->loadExists('internals');
4964
$category = Category::findOrFail($request->integer('category_id'));
5065

66+
$mustBeNull = function (string $attribute, mixed $value, callable $fail): void {
67+
if ($value !== null) {
68+
$fail("The {$attribute} must be null.");
69+
}
70+
};
71+
5172
return [
5273
'torrent' => [
5374
'required',
@@ -141,64 +162,68 @@ function (string $attribute, mixed $value, Closure $fail): void {
141162
],
142163
'imdb' => [
143164
Rule::when($category->movie_meta || $category->tv_meta, [
144-
'required',
165+
'required_with:title_exists_on_imdb',
166+
'nullable',
145167
'decimal:0',
146168
'min:0',
147169
]),
148170
Rule::when(!($category->movie_meta || $category->tv_meta), [
149-
Rule::in([0]),
171+
$mustBeNull,
150172
]),
151173
],
152174
'tvdb' => [
153175
Rule::when($category->tv_meta, [
154-
'required',
176+
'required_with:tv_exists_on_tvdb',
177+
'nullable',
155178
'decimal:0',
156179
'min:0',
157180
]),
158181
Rule::when(!$category->tv_meta, [
159-
Rule::in([0]),
182+
$mustBeNull,
160183
]),
161184
],
162185
'tmdb_movie_id' => [
163186
Rule::when($category->movie_meta, [
164-
'required',
187+
'required_with:movie_exists_on_tmdb',
188+
'nullable',
165189
'decimal:0',
166190
'min:0',
167191
]),
168192
Rule::when(!$category->movie_meta, [
169-
Rule::in([0]),
170-
'exclude',
193+
$mustBeNull,
171194
]),
172195
],
173196
'tmdb_tv_id' => [
174197
Rule::when($category->tv_meta, [
175-
'required',
198+
'required_with:tv_exists_on_tmdb',
199+
'nullable',
176200
'decimal:0',
177201
'min:0',
178202
]),
179203
Rule::when(!$category->tv_meta, [
180-
Rule::in([0]),
181-
'exclude',
204+
$mustBeNull,
182205
]),
183206
],
184207
'mal' => [
185208
Rule::when($category->movie_meta || $category->tv_meta, [
186-
'required',
209+
'required_with:anime_exists_on_mal',
210+
'nullable',
187211
'decimal:0',
188212
'min:0',
189213
]),
190214
Rule::when(!($category->movie_meta || $category->tv_meta), [
191-
Rule::in([0]),
215+
$mustBeNull,
192216
]),
193217
],
194218
'igdb' => [
195219
Rule::when($category->game_meta, [
196-
'required',
220+
'required_with:game_exists_on_igdb',
221+
'nullable',
197222
'decimal:0',
198223
'min:0',
199224
]),
200225
Rule::when(!$category->game_meta, [
201-
Rule::in([0]),
226+
$mustBeNull,
202227
]),
203228
],
204229
'season_number' => [
@@ -253,21 +278,4 @@ function (string $attribute, mixed $value, Closure $fail): void {
253278
],
254279
];
255280
}
256-
257-
/**
258-
* Get the error messages for the defined validation rules.
259-
*
260-
* @return array<string, string>
261-
*/
262-
public function messages(): array
263-
{
264-
return [
265-
'igdb.in' => 'The IGDB ID must be 0 if the media doesn\'t exist on IGDB or you\'re not uploading a game.',
266-
'tmdb_movie_id.in' => 'The TMDB ID must be 0 if the media doesn\'t exist on TMDB or you\'re not uploading a tv show or movie.',
267-
'tmdb_tv_id.in' => 'The TMDB ID must be 0 if the media doesn\'t exist on TMDB or you\'re not uploading a tv show or movie.',
268-
'imdb.in' => 'The IMDB ID must be 0 if the media doesn\'t exist on IMDB or you\'re not uploading a tv show or movie.',
269-
'tvdb.in' => 'The TVDB ID must be 0 if the media doesn\'t exist on TVDB or you\'re not uploading a tv show.',
270-
'mal.in' => 'The MAL ID must be 0 if the media doesn\'t exist on MAL or you\'re not uploading a tv or movie.',
271-
];
272-
}
273281
}

app/Http/Requests/StoreTorrentRequestRequest.php

+40-19
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ public function authorize(): bool
3131
return true;
3232
}
3333

34+
/**
35+
* Prepare the data for validation.
36+
*/
37+
protected function prepareForValidation(): void
38+
{
39+
$this->merge([
40+
'tmdb_movie_id' => $this->has('movie_exists_on_tmdb') ? ($this->input('tmdb_movie_id') ?: null) : null,
41+
'tmdb_tv_id' => $this->has('tv_exists_on_tmdb') ? ($this->input('tmdb_tv_id') ?: null) : null,
42+
'imdb' => $this->has('title_exists_on_imdb') ? ($this->input('imdb') ?: null) : null,
43+
'tvdb' => $this->has('tv_exists_on_tvdb') ? ($this->input('tvdb') ?: null) : null,
44+
'mal' => $this->has('anime_exists_on_mal') ? ($this->input('mal') ?: null) : null,
45+
'igdb' => $this->has('game_exists_on_igdb') ? ($this->input('igdb') ?: null) : null,
46+
]);
47+
}
48+
3449
/**
3550
* Get the validation rules that apply to the request.
3651
*
@@ -40,69 +55,81 @@ public function rules(Request $request): array
4055
{
4156
$category = Category::findOrFail($request->integer('category_id'));
4257

58+
$mustBeNull = function (string $attribute, mixed $value, callable $fail): void {
59+
if ($value !== null) {
60+
$fail("The {$attribute} must be null.");
61+
}
62+
};
63+
4364
return [
4465
'name' => [
4566
'required',
4667
'max:180',
4768
],
4869
'imdb' => [
4970
Rule::when($category->movie_meta || $category->tv_meta, [
50-
'required',
71+
'required_with:title_exists_on_imdb',
72+
'nullable',
5173
'decimal:0',
5274
'min:0',
5375
]),
5476
Rule::when(!($category->movie_meta || $category->tv_meta), [
55-
Rule::in([0]),
77+
$mustBeNull,
5678
]),
5779
],
5880
'tvdb' => [
5981
Rule::when($category->tv_meta, [
60-
'required',
82+
'required_with:tv_exists_on_tvdb',
83+
'nullable',
6184
'decimal:0',
6285
'min:0',
6386
]),
6487
Rule::when(!$category->tv_meta, [
65-
Rule::in([0]),
88+
$mustBeNull,
6689
]),
6790
],
6891
'tmdb_movie_id' => [
6992
Rule::when($category->movie_meta, [
70-
'required',
93+
'required_with:movie_exists_on_tmdb',
94+
'nullable',
7195
'decimal:0',
7296
'min:0',
7397
]),
7498
Rule::when(!$category->movie_meta, [
75-
Rule::in([0]),
99+
$mustBeNull,
76100
]),
77101
],
78102
'tmdb_tv_id' => [
79103
Rule::when($category->tv_meta, [
80-
'required',
104+
'required_with:tv_exists_on_tmdb',
105+
'nullable',
81106
'decimal:0',
82107
'min:0',
83108
]),
84109
Rule::when(!$category->tv_meta, [
85-
Rule::in([0]),
110+
$mustBeNull,
86111
]),
87112
],
88113
'mal' => [
89114
Rule::when($category->movie_meta || $category->tv_meta, [
90-
'required',
115+
'required_with:anime_exists_on_mal',
116+
'nullable',
91117
'decimal:0',
92118
'min:0',
93119
]),
94120
Rule::when(!($category->movie_meta || $category->tv_meta), [
95-
Rule::in([0]),
121+
$mustBeNull,
96122
]),
97123
],
98124
'igdb' => [
99125
Rule::when($category->game_meta, [
100-
'required',
126+
'required_with:game_exists_on_igdb',
127+
'nullable',
101128
'decimal:0',
102129
'min:0',
103130
]),
104131
Rule::when(!$category->game_meta, [
105-
Rule::in([0]),
132+
$mustBeNull,
106133
]),
107134
],
108135
'category_id' => [
@@ -142,13 +169,7 @@ public function rules(Request $request): array
142169
public function messages(): array
143170
{
144171
return [
145-
'igdb.in' => 'The IGDB ID must be 0 if the media doesn\'t exist on IGDB or you\'re not requesting a game.',
146-
'tmdb_movie_id.in' => 'The TMDB ID must be 0 if the media doesn\'t exist on TMDB or you\'re not requesting a tv show or movie.',
147-
'tmdb_tv_id.in' => 'The TMDB ID must be 0 if the media doesn\'t exist on TMDB or you\'re not requesting a tv show or movie.',
148-
'imdb.in' => 'The IMDB ID must be 0 if the media doesn\'t exist on IMDB or you\'re not requesting a tv show or movie.',
149-
'tvdb.in' => 'The TVDB ID must be 0 if the media doesn\'t exist on TVDB or you\'re not requesting a tv show.',
150-
'mal.in' => 'The MAL ID must be 0 if the media doesn\'t exist on MAL or you\'re not requesting a tv or movie.',
151-
'bounty.max' => 'You do not have enough BON to make this request.',
172+
'bounty.max' => 'You do not have enough BON to make this request.',
152173
];
153174
}
154175
}

0 commit comments

Comments
 (0)