diff options
author | Yorhel <git@yorhel.nl> | 2015-09-17 16:21:41 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2015-09-17 16:21:41 +0200 |
commit | a16c4bbbbd97fecb7a02a535efce0fefb1424ca9 (patch) | |
tree | df529c5a881dc0b32cc0be2a4f16ab02f960eb11 /lib/VNDB/DB | |
parent | 108c2a8000d1e525c18a4deb3b5412639bda1e3c (diff) |
Created json_validate() for JSON form data, used for Staff alias editor
The intention is to move more JS editing forms to use JSON, but manually
verifying JSON objects is both painful and likely to introduce errors or
vulnerabilities. json_validate() is a bit of a hack, but has the
advantage that its validation syntax is the same as for normal forms,
and it automatically strips whitespace. I intent to give kv_validate()
an upgrade to be more flexible/modular so it can do more custom
normalization. But that's for later.
I've been meaning to rewrite the JS forms anyway together with the large
JS rewrite, but I'm rather lazy. This is one small step in the right
direction anyway.
Note that json_validate() assumes that the JS code will provide
user-friendly messages on bad input, but the staff alias editor doesn't
quite do this yet.
Diffstat (limited to 'lib/VNDB/DB')
-rw-r--r-- | lib/VNDB/DB/Staff.pm | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/VNDB/DB/Staff.pm b/lib/VNDB/DB/Staff.pm index 1b9a10da..4dfe0756 100644 --- a/lib/VNDB/DB/Staff.pm +++ b/lib/VNDB/DB/Staff.pm @@ -126,7 +126,7 @@ sub dbStaffRevisionInsert { my($self, $o) = @_; $self->dbExec('DELETE FROM edit_staff_aliases'); - if ($o->{aid}) { + if($o->{aid}) { $self->dbExec(q| INSERT INTO edit_staff_aliases (id, name, original) VALUES (?, ?, ?)|, $o->{aid}, $o->{name}, $o->{original}); @@ -139,12 +139,11 @@ sub dbStaffRevisionInsert { my %staff = map exists($o->{$_}) ? (qq|"$_" = ?|, $o->{$_}) : (), qw|aid gender lang desc l_wp l_site l_twitter l_anidb|; $self->dbExec('UPDATE edit_staff !H', \%staff) if %staff; - for my $alias (@{$o->{aliases}}) { - if ($alias->[0]) { - $self->dbExec('INSERT INTO edit_staff_aliases (id, name, original) VALUES (!l)', $alias); + for my $a (@{$o->{aliases}}) { + if($a->{aid}) { + $self->dbExec('INSERT INTO edit_staff_aliases (id, name, original) VALUES (!l)', [ @{$a}{qw|aid name orig|} ]); } else { - $self->dbExec('INSERT INTO edit_staff_aliases (name, original) VALUES (?, ?)', - $alias->[1], $alias->[2]); + $self->dbExec('INSERT INTO edit_staff_aliases (name, original) VALUES (?, ?)', $a->{name}, $a->{orig}); } } } |