summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2021-03-04 12:00:13 +0100
committerYorhel <git@yorhel.nl>2021-03-04 12:06:17 +0100
commit7c9e24b57a5eaa1b026833ca11cba7a451cf8556 (patch)
tree0a4ace42210152f55da88424b75c7fa688120f61
parent5d54a844aba404e16280dcbd1ec3dffc9be4dfe1 (diff)
Releases: Store unknown minage as NULL + fix default for new entries
Fixes https://vndb.org/t950.905, which also reminded me that I can now finally store unknown as NULL rather than -1. The v2rw rewrite was preventing me from changing that earlier, handling NULLs was more annoying in the old v2 code.
-rw-r--r--elm/AdvSearch/Range.elm2
-rw-r--r--elm/ReleaseEdit.elm12
-rw-r--r--lib/Multi/API.pm2
-rw-r--r--lib/VNDB/Func.pm1
-rw-r--r--lib/VNDB/Types.pm3
-rw-r--r--lib/VNWeb/AdvSearch.pm2
-rw-r--r--lib/VNWeb/Filters.pm2
-rw-r--r--lib/VNWeb/Releases/Edit.pm4
-rw-r--r--lib/VNWeb/Releases/Lib.pm2
-rw-r--r--lib/VNWeb/Releases/Page.pm4
-rw-r--r--lib/VNWeb/Releases/VNTab.pm2
-rw-r--r--util/updates/2021-03-04-releases-minage.sql2
12 files changed, 19 insertions, 19 deletions
diff --git a/elm/AdvSearch/Range.elm b/elm/AdvSearch/Range.elm
index bfd6b0a6..7bdcbfdf 100644
--- a/elm/AdvSearch/Range.elm
+++ b/elm/AdvSearch/Range.elm
@@ -204,7 +204,7 @@ votecountView = view False "# Votes" String.fromInt
-minageInit dat = (dat, { op = Lt, val = 13, unk = False, lst = Array.fromList <| List.map Tuple.first <| List.drop 1 GT.ageRatings })
+minageInit dat = (dat, { op = Lt, val = 13, unk = False, lst = Array.fromList <| List.map Tuple.first GT.ageRatings })
minageFromQuery d q =
case q of
diff --git a/elm/ReleaseEdit.elm b/elm/ReleaseEdit.elm
index 280a12cb..ed5d94d5 100644
--- a/elm/ReleaseEdit.elm
+++ b/elm/ReleaseEdit.elm
@@ -48,7 +48,7 @@ type alias Model =
, gtinValid : Bool
, catalog : String
, released : D.RDate
- , minage : Int
+ , minage : Maybe Int
, uncensored : Bool
, resoX : Int
, resoY : Int
@@ -176,7 +176,7 @@ type Msg
| Gtin String
| Catalog String
| Released D.RDate
- | Minage Int
+ | Minage (Maybe Int)
| Uncensored Bool
| Resolution (A.Msg GApi.ApiResolutions)
| Voiced Int
@@ -299,7 +299,7 @@ viewGen model =
, tr [ class "newpart" ] [ td [] [] ]
, formField "rtype::Type" [ inputSelect "rtype" model.rtype RType [] GT.releaseTypes ]
- , formField "minage::Age rating" [ inputSelect "minage" model.minage Minage [] GT.ageRatings, text " (*)" ]
+ , formField "minage::Age rating" [ inputSelect "minage" model.minage Minage [] ((Nothing, "Unknown") :: List.map (Tuple.mapFirst Just) GT.ageRatings), text " (*)" ]
, formField "" [ label [] [ inputCheck "" model.official Official, text " Official (i.e. sanctioned by the original developer of the visual novel)" ] ]
, formField "" [ label [] [ inputCheck "" model.patch Patch , text " This release is a patch to another release.", text " (*)" ] ]
, formField "" [ label [] [ inputCheck "" model.freeware Freeware, text " Freeware (i.e. available at no cost)" ] ]
@@ -348,10 +348,10 @@ viewGen model =
, if model.patch then text "" else
formField "ani_story::Animations"
[ inputSelect "ani_story" model.ani_story AniStory [] GT.animated
- , if model.minage == 18 then text " <= story | ero scenes => " else text ""
- , if model.minage == 18 then inputSelect "" model.ani_ero AniEro [] GT.animated else text ""
+ , if model.minage == Just 18 then text " <= story | ero scenes => " else text ""
+ , if model.minage == Just 18 then inputSelect "" model.ani_ero AniEro [] GT.animated else text ""
]
- , if model.minage /= 18 then text "" else
+ , if model.minage /= Just 18 then text "" else
formField "" [ label [] [ inputCheck "" model.uncensored Uncensored, text " Uncensored (No mosaic or other optical censoring, only check if this release has erotic content)" ] ]
, tr [ class "newpart" ] [ td [ colspan 2 ] [ text "External identifiers & links" ] ]
diff --git a/lib/Multi/API.pm b/lib/Multi/API.pm
index 405c68c3..e5a00530 100644
--- a/lib/Multi/API.pm
+++ b/lib/Multi/API.pm
@@ -628,7 +628,7 @@ my %GET_RELEASE = (
proc => sub {
$_[0]{website} ||= undef;
$_[0]{notes} ||= undef;
- $_[0]{minage} = $_[0]{minage} < 0 ? undef : $_[0]{minage}*1;
+ $_[0]{minage} *= 1 if defined $_[0]{minage};
$_[0]{gtin} ||= undef;
$_[0]{catalog} ||= undef;
$_[0]{resolution} = resolution $_[0];
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index 9e051fae..e1f6ac13 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -190,6 +190,7 @@ sub norm_ip {
sub minage {
my($a, $ex) = @_;
+ return 'Unknown' if !defined $a;
$a = $AGE_RATING{$a};
$ex && $a->{ex} ? "$a->{txt} (e.g. $a->{ex})" : $a->{txt}
}
diff --git a/lib/VNDB/Types.pm b/lib/VNDB/Types.pm
index 272eee8a..86cadae9 100644
--- a/lib/VNDB/Types.pm
+++ b/lib/VNDB/Types.pm
@@ -201,10 +201,7 @@ hash VOICED =>
-# TODO: For some reason the minage column in SQL is nullable but still stores 'unknown' as -1.
-# This should be cleaned up at some point.
hash AGE_RATING =>
- -1 => { txt => 'Unknown', ex => '' },
0 => { txt => 'All ages', ex => 'CERO A' },
6 => { txt => '6+', ex => '' },
7 => { txt => '7+', ex => '' },
diff --git a/lib/VNWeb/AdvSearch.pm b/lib/VNWeb/AdvSearch.pm
index 9fe58d3b..3ecd272b 100644
--- a/lib/VNWeb/AdvSearch.pm
+++ b/lib/VNWeb/AdvSearch.pm
@@ -375,7 +375,7 @@ f r => 8 => 'resolution', { type => 'array', length => 2, values => { ui
f r => 9 => 'resolution-aspect', { type => 'array', length => 2, values => { uint => 1, max => 32767 } },
sql => sub { sql 'NOT r.patch AND r.reso_x', $_[0], \$_->[0], 'AND r.reso_y', $_[0], \$_->[1], 'AND r.reso_x*1000/GREATEST(1, r.reso_y) =', \(int ($_->[0]*1000/max(1,$_->[1]))), $_->[0] ? 'AND r.reso_x > 0' : () };
f r => 10 => 'minage', { required => 0, default => undef, uint => 1, enum => \%AGE_RATING },
- sql => sub { !defined $_ ? sql 'r.minage', $_[0], -1 : sql 'r.minage <> -1 AND r.minage', $_[0], \$_ };
+ sql => sub { defined $_ ? sql 'r.minage', $_[0], \$_ : $_[0] eq '=' ? 'r.minage IS NULL' : 'r.minage IS NOT NULL' };
f r => 11 => 'medium', { required => 0, default => undef, enum => \%MEDIUM },
'=' => sub { !defined $_ ? 'NOT EXISTS(SELECT 1 FROM releases_media rm WHERE rm.id = r.id)' : sql 'EXISTS(SELECT 1 FROM releases_media rm WHERE rm.id = r.id AND rm.medium =', \$_, ')' };
f r => 12 => 'voiced', { uint => 1, enum => \%VOICED }, '=' => sub { sql 'NOT r.patch AND r.voiced =', \$_ };
diff --git a/lib/VNWeb/Filters.pm b/lib/VNWeb/Filters.pm
index 73055afa..93776392 100644
--- a/lib/VNWeb/Filters.pm
+++ b/lib/VNWeb/Filters.pm
@@ -45,7 +45,7 @@ my $RELEASE = form_compile any => {
date_before => { required => 0, range => [0, 99999999] }, # don't use 'rdate' validation here, the search form allows invalid dates
date_after => { required => 0, range => [0, 99999999] }, # ^
released => { undefbool => 1 },
- minage => { undefarray => { enum => \%AGE_RATING } },
+ minage => { undefarray => { enum => [-1, keys %AGE_RATING] } },
lang => { undefarray => { enum => \%LANGUAGE } },
olang => { undefarray => { enum => \%LANGUAGE } },
resolution => { undefarray => {} },
diff --git a/lib/VNWeb/Releases/Edit.pm b/lib/VNWeb/Releases/Edit.pm
index fe6de7b9..2bb09d61 100644
--- a/lib/VNWeb/Releases/Edit.pm
+++ b/lib/VNWeb/Releases/Edit.pm
@@ -21,7 +21,7 @@ my $FORM = {
gtin => { gtin => 1 },
catalog => { required => 0, default => '', maxlength => 50 },
released => { default => 99999999, min => 1, rdate => 1 },
- minage => { int => 1, enum => \%AGE_RATING },
+ minage => { required => 0, default => undef, int => 1, enum => \%AGE_RATING },
uncensored => { anybool => 1 },
reso_x => { uint => 1, range => [0,32767] },
reso_y => { uint => 1, range => [0,32767] },
@@ -136,7 +136,7 @@ elm_api ReleaseEdit => $FORM_OUT, $FORM_IN, sub {
$data->{doujin} = $data->{voiced} = $data->{ani_story} = $data->{ani_ero} = 0 if $data->{patch};
$data->{reso_x} = $data->{reso_y} = 0 if $data->{patch};
$data->{engine} = '' if $data->{patch};
- $data->{uncensored} = $data->{ani_ero} = 0 if $data->{minage} != 18;
+ $data->{uncensored} = $data->{ani_ero} = 0 if !defined $data->{minage} || $data->{minage} != 18;
$_->{qty} = $MEDIUM{$_->{medium}}{qty} ? $_->{qty}||1 : 0 for $data->{media}->@*;
$data->{notes} = bb_subst_links $data->{notes};
die "No VNs selected" if !$data->{vn}->@*;
diff --git a/lib/VNWeb/Releases/Lib.pm b/lib/VNWeb/Releases/Lib.pm
index 3c97d326..e1340e03 100644
--- a/lib/VNWeb/Releases/Lib.pm
+++ b/lib/VNWeb/Releases/Lib.pm
@@ -104,7 +104,7 @@ sub release_row_ {
tr_ sub {
td_ class => 'tc1', sub { rdate_ $r->{released} };
- td_ class => 'tc2', $r->{minage} < 0 ? '' : minage $r->{minage};
+ td_ class => 'tc2', defined $r->{minage} ? minage $r->{minage} : '';
td_ class => 'tc3', sub {
abbr_ class => "icons $_", title => $PLATFORM{$_}, '' for grep $_ ne 'oth', $r->{platforms}->@*;
if($opt->{lang}) {
diff --git a/lib/VNWeb/Releases/Page.pm b/lib/VNWeb/Releases/Page.pm
index 936829e0..e2059e8f 100644
--- a/lib/VNWeb/Releases/Page.pm
+++ b/lib/VNWeb/Releases/Page.pm
@@ -155,12 +155,12 @@ sub _infotable_ {
tr_ sub {
td_ 'Age rating';
td_ minage $r->{minage};
- } if $r->{minage} >= 0;
+ } if defined $r->{minage};
tr_ sub {
td_ 'Censoring';
td_ $r->{uncensored} ? 'No optical censoring (e.g. mosaics)' : 'May include optical censoring (e.g. mosaics)';
- } if $r->{minage} == 18;
+ } if $r->{minage} && $r->{minage} == 18;
for my $t (qw|developer publisher|) {
my @prod = grep $_->{$t}, @{$r->{producers}};
diff --git a/lib/VNWeb/Releases/VNTab.pm b/lib/VNWeb/Releases/VNTab.pm
index e3da0609..cebaf7f6 100644
--- a/lib/VNWeb/Releases/VNTab.pm
+++ b/lib/VNWeb/Releases/VNTab.pm
@@ -121,7 +121,7 @@ my @rel_cols = (
sort_sql => 'r.minage %s, r.released %1$s, r.title %1$s',
button_string => 'Age rating',
default => 1,
- has_data => sub { $_[0]{minage} != -1 },
+ has_data => sub { defined $_[0]{minage} },
draw => sub { txt_ minage $_[0]{minage} },
}, { # Notes
id => 'not',
diff --git a/util/updates/2021-03-04-releases-minage.sql b/util/updates/2021-03-04-releases-minage.sql
new file mode 100644
index 00000000..c4eb0bb4
--- /dev/null
+++ b/util/updates/2021-03-04-releases-minage.sql
@@ -0,0 +1,2 @@
+UPDATE releases SET minage = NULL WHERE minage = -1;
+UPDATE releases_hist SET minage = NULL WHERE minage = -1;