summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2010-11-03 10:28:13 +0100
committerYorhel <git@yorhel.nl>2010-11-03 10:28:13 +0100
commit97eb068a5f6b3a6e3c10ffc4f7230bf2342b3102 (patch)
tree18be0d98c584e0242bfed82854fbc2793302250c /lib
parentbfa5493c5caf1f2fe17344773f6bee6c9f55e24d (diff)
Automatically remove duplicate aliases on /v+/edit
And clean up the alias field before it gets inserted into the DB. Does not provide any feedback to the user, let's just hope our users are clever enough to figure out what happened.
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/Handler/VNEdit.pm15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/VNDB/Handler/VNEdit.pm b/lib/VNDB/Handler/VNEdit.pm
index 3ec7528b..44c5ab08 100644
--- a/lib/VNDB/Handler/VNEdit.pm
+++ b/lib/VNDB/Handler/VNEdit.pm
@@ -25,6 +25,8 @@ sub edit {
return $self->htmlDenied if !$self->authCan('edit')
|| $vid && ($v->{locked} && !$self->authCan('lock') || $v->{hidden} && !$self->authCan('del'));
+ my $r = $v ? $self->dbReleaseGet(vid => $v->{id}) : [];
+
my %b4 = !$vid ? () : (
(map { $_ => $v->{$_} } qw|title original desc alias length l_wp l_encubed l_renai l_vnn img_nsfw ihid ilock|),
anime => join(' ', sort { $a <=> $b } map $_->{id}, @{$v->{anime}}),
@@ -70,6 +72,14 @@ sub edit {
$frm->{img_nsfw} = $frm->{img_nsfw} ? 1 : 0;
$frm->{screenshots} = join ' ', map sprintf('%d,%d,%d', $_->[0], $_->[1]?1:0, $_->[2]), sort { $a->[0] <=> $b->[0] } @$screenshots;
+ # 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 && !$self->reqUploadFileName('img') && !grep $frm->{$_} ne $b4{$_}, keys %b4;
@@ -101,7 +111,7 @@ sub edit {
$self->htmlHeader(title => $title, noindex => 1);
$self->htmlMainTabs('v', $v, 'edit') if $vid;
$self->htmlEditMessage('v', $v, $title);
- _form($self, $v, $frm);
+ _form($self, $v, $frm, $r);
$self->htmlFooter;
}
@@ -139,8 +149,7 @@ sub _uploadimage {
sub _form {
- my($self, $v, $frm) = @_;
- my $r = $v ? $self->dbReleaseGet(vid => $v->{id}) : [];
+ my($self, $v, $frm, $r) = @_;
$self->htmlForm({ frm => $frm, action => $v ? "/v$v->{id}/edit" : '/v/new', editsum => 1, upload => 1 },
vn_geninfo => [ mt('_vnedit_geninfo'),
[ input => short => 'title', name => mt '_vnedit_frm_title' ],