diff options
author | Yorhel <git@yorhel.nl> | 2020-09-10 11:27:53 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2020-09-10 11:27:55 +0200 |
commit | 5eae77ca03f359c157460d81a2d36e91e036642f (patch) | |
tree | d6d29081de91d37578e662531e6074c8b104a79c /lib/VNDB/Util/Misc.pm | |
parent | d8885e3793c5906015ccd6af52c263989ec1a76d (diff) |
v2rw/filters: Add experimental validation + move compat to VNWeb
This is a minor start towards rewriting the filter logic in the new v2rw
code. Filters were never validated before (I didn't have a good
framework for it - now I do) and invalid filters would result in a 500.
The new validation code is not yet applied, but failed validations will
be logged so that I can see if it's working correctly.
I mean, what better way to test than to throw it in production?
I'll write new (and more flexible) SQL generation functions for these
filters later, so that v2rw code can get filtered results and I can make
a start on rewriting the pages that depend on the functionality. The
validation schema can also be used to validate the filters stored in the
DB, so I can use it to get rid of the complex handling of stored invalid
filters.
Diffstat (limited to 'lib/VNDB/Util/Misc.pm')
-rw-r--r-- | lib/VNDB/Util/Misc.pm | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/lib/VNDB/Util/Misc.pm b/lib/VNDB/Util/Misc.pm index c08fe1bb..0423e35b 100644 --- a/lib/VNDB/Util/Misc.pm +++ b/lib/VNDB/Util/Misc.pm @@ -40,6 +40,8 @@ sub filFetchDB { my $filters = fil_parse $overwrite // $pref, @{$filfields{$type}}; + VNWeb::Filters::debug_validate($type, $filters); + # compatibility my $compat = $self->filCompat($type, $filters); $self->authPref($prefname => fil_serialize $filters) if $compat && !defined $overwrite; @@ -84,22 +86,7 @@ sub filFetchDB { # Compatibility with old filters. Modifies the filter in-place and returns the number of changes made. sub filCompat { my($self, $type, $fil) = @_; - my $mod = 0; - - # older tag specification (by name rather than ID) - if($type eq 'vn' && ($fil->{taginc} || $fil->{tagexc})) { - my $tagfind = sub { - return map { - my $i = $self->dbTagGet(name => $_)->[0]; - $i && $i->{searchable} ? $i->{id} : (); - } grep $_, ref $_[0] ? @{$_[0]} : ($_[0]||'') - }; - $fil->{tag_inc} //= [ $tagfind->(delete $fil->{taginc}) ] if $fil->{taginc}; - $fil->{tag_exc} //= [ $tagfind->(delete $fil->{tagexc}) ] if $fil->{tagexc}; - $mod++; - } - - $mod; + $type eq 'vn' ? VNWeb::Filters::filter_vn_compat($fil) : 0 } |