diff options
author | Yorhel <git@yorhel.nl> | 2011-02-04 20:18:49 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2011-02-04 20:18:49 +0100 |
commit | ca3505999d11a66591dd8529b492c9b060b89f65 (patch) | |
tree | c6ade67b3a682185c7f13b232900e6351c173e6a | |
parent | 80d22665f3f4a99f60c4b808bb5dc97a1f8f6830 (diff) |
Allow setting tag category for all child tags recursively
Takes the burden out of our dear tag moderators to edit *all* tags
manually on the next update.
-rw-r--r-- | data/lang.txt | 14 | ||||
-rw-r--r-- | lib/VNDB/DB/Tags.pm | 16 | ||||
-rw-r--r-- | lib/VNDB/Handler/Tags.pm | 28 |
3 files changed, 52 insertions, 6 deletions
diff --git a/data/lang.txt b/data/lang.txt index 8a94a3cb..a3911210 100644 --- a/data/lang.txt +++ b/data/lang.txt @@ -4195,6 +4195,20 @@ cs*: hu*: nl : Categorie +:_tagedit_frm_catrec +en : Also edit all child tags to have this category +ru*: +cs*: +hu*: +nl : Zet deze categorie ook voor alle subtags + +:_tagedit_frm_catrec_warn +en : WARNING: This will overwrite the category field for all child tags, this action can not be reverted! +ru*: +cs*: +hu*: +nl : WAARSCHUWING: Hiermee wordt het categoriefeld voor alle subtags overschreven, dit kan niet ongedaan worden gemaakt! + :_tagedit_frm_alias en : Aliases (separated by newlines) diff --git a/lib/VNDB/DB/Tags.pm b/lib/VNDB/DB/Tags.pm index 51ab4b93..d2269e02 100644 --- a/lib/VNDB/DB/Tags.pm +++ b/lib/VNDB/DB/Tags.pm @@ -122,13 +122,17 @@ sub dbTagEdit { $self->dbExec('UPDATE tags !H WHERE id = ?', { $o{upddate} ? ('added = NOW()' => 1) : (), - map { +"$_ = ?" => $o{$_} } qw|name meta description state cat| + map exists($o{$_}) ? ("$_ = ?" => $o{$_}) : (), qw|name meta description state cat| }, $id); - $self->dbExec('DELETE FROM tags_aliases WHERE tag = ?', $id); - $self->dbExec('INSERT INTO tags_aliases (tag, alias) VALUES (?, ?)', $id, $_) for (@{$o{aliases}}); - $self->dbExec('DELETE FROM tags_parents WHERE tag = ?', $id); - $self->dbExec('INSERT INTO tags_parents (tag, parent) VALUES (?, ?)', $id, $_) for(@{$o{parents}}); - $self->dbExec('DELETE FROM tags_vn WHERE tag = ?', $id) if $o{meta} || $o{state} == 1; + if($o{aliases}) { + $self->dbExec('DELETE FROM tags_aliases WHERE tag = ?', $id); + $self->dbExec('INSERT INTO tags_aliases (tag, alias) VALUES (?, ?)', $id, $_) for (@{$o{aliases}}); + } + if($o{parents}) { + $self->dbExec('DELETE FROM tags_parents WHERE tag = ?', $id); + $self->dbExec('INSERT INTO tags_parents (tag, parent) VALUES (?, ?)', $id, $_) for(@{$o{parents}}); + } + $self->dbExec('DELETE FROM tags_vn WHERE tag = ?', $id) if $o{meta} || ($o{state} && $o{state} == 1); } diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm index 50c91455..c7d98060 100644 --- a/lib/VNDB/Handler/Tags.pm +++ b/lib/VNDB/Handler/Tags.pm @@ -204,6 +204,7 @@ sub tagedit { { post => 'name', required => 1, maxlength => 250, regex => [ qr/^[^,]+$/, 'A comma is not allowed in tag names' ] }, { post => 'state', required => 0, default => 0, enum => [ 0..2 ] }, { post => 'cat', required => 1, enum => $self->{tag_categories} }, + { post => 'catrec', required => 0 }, { post => 'meta', required => 0, default => 0 }, { post => 'alias', required => 0, maxlength => 1024, default => '', regex => [ qr/^[^,]+$/s, 'No comma allowed in aliases' ] }, { post => 'description', required => 0, maxlength => 10240, default => '' }, @@ -226,6 +227,7 @@ sub tagedit { $_ = $c->[0]{id}; } } + if(!$frm->{_err}) { $frm->{state} = $frm->{meta} = 0 if !$self->authCan('tagmod'); my %opts = ( @@ -241,6 +243,7 @@ sub tagedit { $tag = $self->dbTagAdd(%opts); } else { $self->dbTagEdit($tag, %opts, upddate => $frm->{state} == 2 && $t->{state} != 2); + _set_childs_cat($self, $tag, $frm->{cat}) if $frm->{catrec}; } $self->dbTagMerge($tag, @merge) if $self->authCan('tagmod') && @merge; $self->resRedirect("/g$tag", 'post'); @@ -283,6 +286,10 @@ sub tagedit { ) : (), [ select => short => 'cat', name => mt('_tagedit_frm_cat'), options => [ map [$_, mt "_tagcat_$_"], @{$self->{tag_categories}} ] ], + $self->authCan('tagmod') && $tag ? ( + [ checkbox => short => 'catrec', name => mt '_tagedit_frm_catrec' ], + [ static => content => mt '_tagedit_frm_catrec_warn' ], + ) : (), [ textarea => short => 'alias', name => mt('_tagedit_frm_alias'), cols => 30, rows => 4 ], [ textarea => short => 'description', name => mt '_tagedit_frm_desc' ], [ static => content => mt '_tagedit_frm_desc_msg' ], @@ -297,6 +304,27 @@ sub tagedit { $self->htmlFooter; } +# recursively edit all child tags and set the category field +# Note: this can be done more efficiently by doing everything in one UPDATE +# query, but that takes more code and this feature isn't used very often +# anyway. +sub _set_childs_cat { + my($self, $tag, $cat) = @_; + my %done; + + my $e; + $e = sub { + my $l = shift; + for (@$l) { + $self->dbTagEdit($_->{id}, cat => $cat) if !$done{$_->{id}}++; + $e->($_->{sub}) if $_->{sub}; + } + }; + + my $childs = $self->dbTagTree($tag, 25); + $e->($childs); +} + sub taglist { my $self = shift; |