diff options
author | Yorhel <git@yorhel.nl> | 2008-11-22 09:42:00 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2008-11-22 09:42:00 +0100 |
commit | aac83c8b840f62d3febf2212b86bf7cf40eb3fa1 (patch) | |
tree | 2168e7f510a68913f8829e0a69a9b401f2cfa7d7 /lib/VNDB | |
parent | 1104001784aa76b9ad8c454336b103d8365cb779 (diff) |
Wrote a generic function to handle all /[vrp]+/(lock|hide) URIs
They pretty much all work the same anyway
Diffstat (limited to 'lib/VNDB')
-rw-r--r-- | lib/VNDB/DB/Misc.pm | 14 | ||||
-rw-r--r-- | lib/VNDB/DB/Producers.pm | 11 | ||||
-rw-r--r-- | lib/VNDB/Handler/Misc.pm | 17 | ||||
-rw-r--r-- | lib/VNDB/Handler/Producers.pm | 12 |
4 files changed, 31 insertions, 23 deletions
diff --git a/lib/VNDB/DB/Misc.pm b/lib/VNDB/DB/Misc.pm index 6fb82801..d8348e71 100644 --- a/lib/VNDB/DB/Misc.pm +++ b/lib/VNDB/DB/Misc.pm @@ -6,7 +6,7 @@ use warnings; use Exporter 'import'; our @EXPORT = qw| - dbStats dbRevisionInsert dbItemInsert dbRevisionGet + dbStats dbRevisionInsert dbItemInsert dbRevisionGet dbItemMod |; @@ -145,5 +145,17 @@ sub dbRevisionGet { } +# Lock or hide a DB item +# arguments: v/r/p, id, %options ->( hidden, locked ) +sub dbItemMod { + my($self, $type, $id, %o) = @_; + $self->dbExec('UPDATE !s !H WHERE id = ?', + {qw|v vn r releases p producers|}->{$type}, + { map { ($_.' = ?', int $o{$_}) } keys %o }, $id + ); +} + + + 1; diff --git a/lib/VNDB/DB/Producers.pm b/lib/VNDB/DB/Producers.pm index 8b8b29aa..99989d80 100644 --- a/lib/VNDB/DB/Producers.pm +++ b/lib/VNDB/DB/Producers.pm @@ -5,7 +5,7 @@ use strict; use warnings; use Exporter 'import'; -our @EXPORT = qw|dbProducerGet dbProducerMod dbProducerEdit dbProducerAdd|; +our @EXPORT = qw|dbProducerGet dbProducerEdit dbProducerAdd|; # options: results, page, id, search, char, rev @@ -79,15 +79,6 @@ sub dbProducerGet { } -# arguments: id, %options ->( hidden, locked ) -sub dbProducerMod { - my($self, $id, %o) = @_; - $self->dbExec('UPDATE producers !H WHERE id = ?', { - map { ($_.' = ?', int $o{$_}) } keys %o - }, $id); -} - - # arguments: id, %options ->( editsum + insert_rev ) # returns: ( local revision, global revision ) sub dbProducerEdit { diff --git a/lib/VNDB/Handler/Misc.pm b/lib/VNDB/Handler/Misc.pm index fe81a1f0..6a9924c9 100644 --- a/lib/VNDB/Handler/Misc.pm +++ b/lib/VNDB/Handler/Misc.pm @@ -12,6 +12,7 @@ YAWF::register( qr{}, \&homepage, qr{(?:([upvr])([1-9]\d*)/)?hist}, \&history, qr{nospam}, \&nospam, + qr{([vrp])([1-9]\d*)/(lock|hide)}, \&itemmod, # redirects for old URLs qr{(.*[^/]+)/+}, sub { $_[0]->resRedirect("/$_[1]", 'perm') }, @@ -177,5 +178,21 @@ sub nospam { } +# /hide and /lock for v/r/p+ pages +sub itemmod { + my($self, $type, $iid, $act) = @_; + return $self->htmlDenied if !$self->authCan($act eq 'hide' ? 'del' : 'lock'); + + my $obj = $type eq 'v' ? $self->dbVNGet(id => $iid)->[0] : + $type eq 'r' ? undef : # $self->dbReleaseGet(id => $iid)->[0] : + $self->dbProducerGet(id => $iid)->[0]; + return 404 if !$obj->{id}; + + $self->dbItemMod($type, $iid, $act eq 'hide' ? (hidden => !$obj->{hidden}) : (locked => !$obj->{locked})); + + $self->resRedirect("/$type$iid", 'temp'); +} + + 1; diff --git a/lib/VNDB/Handler/Producers.pm b/lib/VNDB/Handler/Producers.pm index 234280b7..27f3a852 100644 --- a/lib/VNDB/Handler/Producers.pm +++ b/lib/VNDB/Handler/Producers.pm @@ -11,7 +11,6 @@ YAWF::register( qr{p([1-9]\d*)(?:\.([1-9]\d*))?} => \&page, qr{p(?:([1-9]\d*)(?:\.([1-9]\d*))?/edit|/new)} => \&edit, - qr{p([1-9]\d*)/(lock|hide)} => \&mod, qr{p/([a-z0]|all)} => \&list, ); @@ -166,17 +165,6 @@ sub edit { } -# /hide and /lock -sub mod { - my($self, $pid, $act) = @_; - return $self->htmlDenied if !$self->authCan($act eq 'hide' ? 'del' : 'lock'); - my $p = $self->dbProducerGet(id => $pid)->[0]; - return 404 if !$p->{id}; - $self->dbProducerMod($pid, $act eq 'hide' ? (hidden => !$p->{hidden}) : (locked => !$p->{locked})); - $self->resRedirect("/p$pid", 'temp'); -} - - sub list { my($self, $char) = @_; |