diff options
author | Yorhel <git@yorhel.nl> | 2015-10-01 20:00:02 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2015-10-01 20:00:02 +0200 |
commit | 4cebc475aa4cd045d16e91616f148454d06d3c7d (patch) | |
tree | 4d56e894c7a50648246e730a0f104fc7b61331b0 /lib/VNDB/Handler | |
parent | 423a37af953817b59879f2d3013a44a54006ec3b (diff) |
VNEdit: Give error on duplicate alias + improved msg on id/page error
Diffstat (limited to 'lib/VNDB/Handler')
-rw-r--r-- | lib/VNDB/Handler/VNEdit.pm | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/VNDB/Handler/VNEdit.pm b/lib/VNDB/Handler/VNEdit.pm index 4ec25605..b1e3a548 100644 --- a/lib/VNDB/Handler/VNEdit.pm +++ b/lib/VNDB/Handler/VNEdit.pm @@ -167,6 +167,14 @@ sub edit { } } if(!$nosubmit && !$frm->{_err}) { + # normalize aliases + $frm->{alias} = join "\n", map { s/^ +//g; s/ +$//g; $_?($_):() } split /\n/, $frm->{alias}; + # throw error on duplicate/existing aliases + my %alias = map +(lc($_),1), $frm->{title}, $frm->{original}, map +($_->{title}, $_->{original}), @$r; + my @e = map $alias{ lc($_) }++ ? [ 'alias', 'existingalias', $_ ] : (), split /\n/, $frm->{alias}; + $frm->{_err} = \@e if @e; + } + if(!$nosubmit && !$frm->{_err}) { # parse and re-sort fields that have multiple representations of the same information my $anime = { map +($_=>1), grep /^[0-9]+$/, split /[ ,]+/, $frm->{anime} }; my $relations = [ map { /^([a-z]+),([0-9]+),([01]),(.+)$/ && (!$vid || $2 != $vid) ? [ $1, $2, $3, $4 ] : () } split /\|\|\|/, $frm->{vnrelations} ]; @@ -183,14 +191,6 @@ sub edit { $frm->{credits} = json_encode \@credits; $frm->{seiyuu} = json_encode \@seiyuu; - # weed out duplicate aliases - my %alias; - $frm->{alias} = join "\n", grep { - my $a = lc $_; - $a && !$alias{$a}++ && $a ne lc($frm->{title}) && $a ne lc($frm->{original}) - && !grep $a eq lc($_->{title}) || $a eq lc($_->{original}), @$r; - } map { s/^ +//g; s/ +$//g; $_ } split /\n/, $frm->{alias}; - # nothing changed? just redirect return $self->resRedirect("/v$vid", 'post') if $vid && !grep $frm->{$_} ne $b4{$_}, keys %b4; |