summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormorkt <>2015-01-16 15:42:01 +0100
committerYorhel <git@yorhel.nl>2015-01-16 15:42:01 +0100
commit1cc4307e0097877f0e2a26c03c372651a4eb88f4 (patch)
treed3f3c9bf396ac4312359e984ce88e430a39303ce
parentcdc711f2833db79aae7d3a798c406b0501dce233 (diff)
staff: More form verification + support more chars for VN seiyuu linking
-rw-r--r--lib/VNDB/Handler/VNEdit.pm16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/VNDB/Handler/VNEdit.pm b/lib/VNDB/Handler/VNEdit.pm
index b055a87c..caf4b2b1 100644
--- a/lib/VNDB/Handler/VNEdit.pm
+++ b/lib/VNDB/Handler/VNEdit.pm
@@ -85,7 +85,7 @@ sub edit {
|| $vid && (($v->{locked} || $v->{hidden}) && !$self->authCan('dbmod'));
my $r = $v ? $self->dbReleaseGet(vid => $v->{id}) : [];
- my $chars = $v ? $self->dbCharGet(vid => $v->{id}, results => 50) : [];
+ my $chars = $v ? $self->dbCharGet(vid => $v->{id}, results => 100) : [];
my %b4 = !$vid ? () : (
(map { $_ => $v->{$_} } qw|title original desc alias length l_wp l_encubed l_renai image img_nsfw ihid ilock|),
@@ -137,11 +137,18 @@ sub edit {
my $raw_c = $frm->{credits} ? jsonDecode $frm->{credits} : [];
my $raw_s = $frm->{seiyuu} ? jsonDecode $frm->{seiyuu} : [];
+ # ensure submitted alias IDs exist within database
+ my @alist = map $_->{aid}, @$raw_c, @$raw_s;
+ my %staff = @alist ? map +($_->{aid} => 1), @{$self->dbStaffGet(aid => \@alist)} : ();
+ return unless %staff; # exit from the eval block if staff list is empty
+
# check for duplicate credits
- my $last_c;
+ my $last_c = { aid => 0, role => '' };
for my $c (sort { $a->{aid} <=> $b->{aid} || $a->{role} cmp $b->{role} } @$raw_c) {
+ next unless exists $staff{$c->{aid}};
# discard entries with identical name & role
next if $last_c->{aid} == $c->{aid} && $last_c->{role} eq $c->{role};
+ $c->{aid} += 0;
push @credits, $c;
$last_c = $c;
}
@@ -149,11 +156,12 @@ sub edit {
# if character list is empty, any seiyuu data will be discarded
if (@$chars && @$raw_s) {
my %vn_chars = map +($_->{id} => 1), @$chars;
- my $last_s;
+ my $last_s = { aid => 0, cid => 0 };
for my $s (sort { $a->{aid} <=> $b->{aid} || $a->{cid} <=> $b->{cid} } @$raw_s) {
- next unless exists $vn_chars{$s->{cid}}; # weed out odd characters
+ next unless $staff{$s->{aid}} && $vn_chars{$s->{cid}}; # weed out odd credits
next if $last_s->{aid} == $s->{aid} && $last_s->{cid} == $s->{cid};
$s->{cid} += 0; # force numeric conversion
+ $s->{aid} += 0;
push @seiyuu, $s;
$last_s = $s;
}