summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2018-10-02 15:09:12 +0200
committerYorhel <git@yorhel.nl>2018-10-02 15:10:24 +0200
commitbfb19401c38f68a3145ca49948667470a9370aa0 (patch)
tree7dc3b1524f3bbe1bdd5726ec77aa511bfb6775ff
parent6bd0b0cd1f3892253d881f71533940f0cf07c13d (diff)
Fix release filter compatibility handling on VN browser
filFetchDB() is not used for the release filter on the VN browsing interface, so I've moved the compatibility stuff into a separate filCompat() method that can be called from Handler::VNBrowse.
-rw-r--r--lib/VNDB/Handler/VNBrowse.pm1
-rw-r--r--lib/VNDB/Util/Misc.pm28
2 files changed, 13 insertions, 16 deletions
diff --git a/lib/VNDB/Handler/VNBrowse.pm b/lib/VNDB/Handler/VNBrowse.pm
index da3f3782..edc42621 100644
--- a/lib/VNDB/Handler/VNBrowse.pm
+++ b/lib/VNDB/Handler/VNBrowse.pm
@@ -52,6 +52,7 @@ sub list {
$f->{o} = $f->{s} eq 'tagscore' ? 'd' : 'a' if !$f->{o};
my $rfil = fil_parse $f->{rfil}, @{$VNDB::Util::Misc::filfields{release}};
+ $self->filCompat(release => $rfil);
$f->{rfil} = fil_serialize $rfil, @{$VNDB::Util::Misc::filfields{release}};
my($list, $np) = $self->filFetchDB(vn => $f->{fil}, {
diff --git a/lib/VNDB/Util/Misc.pm b/lib/VNDB/Util/Misc.pm
index ee7e8875..e223f777 100644
--- a/lib/VNDB/Util/Misc.pm
+++ b/lib/VNDB/Util/Misc.pm
@@ -8,7 +8,7 @@ use TUWF ':html';
use VNDB::Func;
use VNDB::BBCode ();
-our @EXPORT = qw|filFetchDB bbSubstLinks|;
+our @EXPORT = qw|filFetchDB filCompat bbSubstLinks|;
our %filfields = (
@@ -40,8 +40,7 @@ sub filFetchDB {
my $filters = fil_parse $overwrite // $pref, @{$filfields{$type}};
# compatibility
- my $compat = ($type eq 'vn' && _fil_vn_compat($self, $filters))
- || ($type eq 'release' && _fil_release_compat($self, $filters));
+ my $compat = $self->filCompat($type, $filters);
$self->authPref($prefname => fil_serialize $filters) if $compat && !defined $overwrite;
# write the definite filter string in $overwrite
@@ -81,11 +80,13 @@ sub filFetchDB {
}
-sub _fil_vn_compat {
- my($self, $fil) = @_;
+# 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($fil->{taginc} || $fil->{tagexc}) {
+ if($type eq 'vn' && ($fil->{taginc} || $fil->{tagexc})) {
my $tagfind = sub {
return map {
my $i = $self->dbTagGet(name => $_)->[0];
@@ -94,20 +95,15 @@ sub _fil_vn_compat {
};
$fil->{tag_inc} //= [ $tagfind->(delete $fil->{taginc}) ] if $fil->{taginc};
$fil->{tag_exc} //= [ $tagfind->(delete $fil->{tagexc}) ] if $fil->{tagexc};
- return 1;
+ $mod++;
}
- return 0;
-}
-
-
-sub _fil_release_compat {
- my($self, $fil) = @_;
- if($fil->{resolution} && $fil->{resolution} =~ /^[0-9]+$/) {
+ if($type eq 'release' && $fil->{resolution} && $fil->{resolution} =~ /^[0-9]+$/) {
$fil->{resolution} = (keys %{$self->{resolutions}})[$fil->{resolution}] || 'unknown';
- return 1;
+ $mod++;
}
- return 0;
+
+ $mod;
}