summaryrefslogtreecommitdiffstats
path: root/extensions/FlagTypeComment
diff options
context:
space:
mode:
authorPerl Tidy <perltidy@bugzilla.org>2018-12-05 21:38:52 +0100
committerDylan William Hardison <dylan@hardison.net>2018-12-05 23:49:08 +0100
commit8ec8da0491ad89604700b3e29a227966f6d84ba1 (patch)
tree9d270f173330ca19700e0ba9f2ee931300646de1 /extensions/FlagTypeComment
parenta7bb5a65b71644d9efce5fed783ed545b9336548 (diff)
downloadbugzilla-8ec8da0491ad89604700b3e29a227966f6d84ba1.tar.gz
bugzilla-8ec8da0491ad89604700b3e29a227966f6d84ba1.tar.xz
no bug - reformat all the code using the new perltidy rules
Diffstat (limited to 'extensions/FlagTypeComment')
-rw-r--r--extensions/FlagTypeComment/Extension.pm264
-rw-r--r--extensions/FlagTypeComment/lib/Constants.pm32
2 files changed, 144 insertions, 152 deletions
diff --git a/extensions/FlagTypeComment/Extension.pm b/extensions/FlagTypeComment/Extension.pm
index e7b34113d..e26b08b27 100644
--- a/extensions/FlagTypeComment/Extension.pm
+++ b/extensions/FlagTypeComment/Extension.pm
@@ -39,31 +39,19 @@ our $VERSION = '1';
################
sub db_schema_abstract_schema {
- my ($self, $args) = @_;
- $args->{'schema'}->{'flagtype_comments'} = {
- FIELDS => [
- type_id => {
- TYPE => 'SMALLINT(6)',
- NOTNULL => 1,
- REFERENCES => {
- TABLE => 'flagtypes',
- COLUMN => 'id',
- DELETE => 'CASCADE'
- }
- },
- on_status => {
- TYPE => 'CHAR(1)',
- NOTNULL => 1
- },
- comment => {
- TYPE => 'MEDIUMTEXT',
- NOTNULL => 1
- },
- ],
- INDEXES => [
- flagtype_comments_idx => ['type_id'],
- ],
- };
+ my ($self, $args) = @_;
+ $args->{'schema'}->{'flagtype_comments'} = {
+ FIELDS => [
+ type_id => {
+ TYPE => 'SMALLINT(6)',
+ NOTNULL => 1,
+ REFERENCES => {TABLE => 'flagtypes', COLUMN => 'id', DELETE => 'CASCADE'}
+ },
+ on_status => {TYPE => 'CHAR(1)', NOTNULL => 1},
+ comment => {TYPE => 'MEDIUMTEXT', NOTNULL => 1},
+ ],
+ INDEXES => [flagtype_comments_idx => ['type_id'],],
+ };
}
#############
@@ -71,83 +59,89 @@ sub db_schema_abstract_schema {
#############
sub template_before_process {
- my ($self, $args) = @_;
- my ($vars, $file) = @$args{qw(vars file)};
+ my ($self, $args) = @_;
+ my ($vars, $file) = @$args{qw(vars file)};
- return unless Bugzilla->user->id;
- if (grep { $_ eq $file } FLAGTYPE_COMMENT_TEMPLATES) {
- _set_ftc_states($file, $vars);
- }
+ return unless Bugzilla->user->id;
+ if (grep { $_ eq $file } FLAGTYPE_COMMENT_TEMPLATES) {
+ _set_ftc_states($file, $vars);
+ }
}
sub _set_ftc_states {
- my ($file, $vars) = @_;
- my $dbh = Bugzilla->dbh;
-
- my $ftc_flags;
- my $db_result;
- if ($file =~ /^admin\//) {
- # admin
- my $type = $vars->{'type'} || return;
- my ($target_type, $id);
- if (blessed($type)) {
- ($target_type, $id) = ($type->target_type, $type->id);
- } else {
- ($target_type, $id) = ($type->{target_type}, $type->{id});
- trick_taint($id) if $id;
- }
- if ($target_type eq 'bug') {
- return unless FLAGTYPE_COMMENT_BUG_FLAGS;
- } else {
- return unless FLAGTYPE_COMMENT_ATTACHMENT_FLAGS;
- }
- if ($id) {
- $db_result = $dbh->selectall_arrayref(
- "SELECT type_id AS flagtype, on_status AS state, comment AS text
+ my ($file, $vars) = @_;
+ my $dbh = Bugzilla->dbh;
+
+ my $ftc_flags;
+ my $db_result;
+ if ($file =~ /^admin\//) {
+
+ # admin
+ my $type = $vars->{'type'} || return;
+ my ($target_type, $id);
+ if (blessed($type)) {
+ ($target_type, $id) = ($type->target_type, $type->id);
+ }
+ else {
+ ($target_type, $id) = ($type->{target_type}, $type->{id});
+ trick_taint($id) if $id;
+ }
+ if ($target_type eq 'bug') {
+ return unless FLAGTYPE_COMMENT_BUG_FLAGS;
+ }
+ else {
+ return unless FLAGTYPE_COMMENT_ATTACHMENT_FLAGS;
+ }
+ if ($id) {
+ $db_result = $dbh->selectall_arrayref(
+ "SELECT type_id AS flagtype, on_status AS state, comment AS text
FROM flagtype_comments
- WHERE type_id = ?",
- { Slice => {} }, $id);
- }
- } else {
- # creating/editing attachment / viewing bug
- my $bug;
- if (exists $vars->{'bug'}) {
- $bug = $vars->{'bug'};
- } elsif (exists $vars->{'attachment'}) {
- $bug = $vars->{'attachment'}->{bug};
- } else {
- return;
- }
-
- my $flag_types = Bugzilla::FlagType::match({
- 'target_type' => ($file =~ /^bug/ ? 'bug' : 'attachment'),
- 'product_id' => $bug->product_id,
- 'component_id' => $bug->component_id,
- 'bug_id' => $bug->id,
- 'active_or_has_flags' => $bug->id,
- });
-
- if (@$flag_types) {
- my $types = join(',', map { $_->id } @$flag_types);
- my $states = "'" . join("','", FLAGTYPE_COMMENT_STATES) . "'";
- $db_result = $dbh->selectall_arrayref(
- "SELECT type_id AS flagtype, on_status AS state, comment AS text
- FROM flagtype_comments
- WHERE type_id IN ($types) AND on_status IN ($states)",
- { Slice => {} });
- }
- else {
- $db_result = [];
- }
+ WHERE type_id = ?", {Slice => {}}, $id
+ );
+ }
+ }
+ else {
+ # creating/editing attachment / viewing bug
+ my $bug;
+ if (exists $vars->{'bug'}) {
+ $bug = $vars->{'bug'};
+ }
+ elsif (exists $vars->{'attachment'}) {
+ $bug = $vars->{'attachment'}->{bug};
+ }
+ else {
+ return;
}
- foreach my $row (@$db_result) {
- $ftc_flags->{$row->{'flagtype'}} ||= {};
- $ftc_flags->{$row->{'flagtype'}}{$row->{'state'}} = $row->{text};
+ my $flag_types = Bugzilla::FlagType::match({
+ 'target_type' => ($file =~ /^bug/ ? 'bug' : 'attachment'),
+ 'product_id' => $bug->product_id,
+ 'component_id' => $bug->component_id,
+ 'bug_id' => $bug->id,
+ 'active_or_has_flags' => $bug->id,
+ });
+
+ if (@$flag_types) {
+ my $types = join(',', map { $_->id } @$flag_types);
+ my $states = "'" . join("','", FLAGTYPE_COMMENT_STATES) . "'";
+ $db_result = $dbh->selectall_arrayref(
+ "SELECT type_id AS flagtype, on_status AS state, comment AS text
+ FROM flagtype_comments
+ WHERE type_id IN ($types) AND on_status IN ($states)", {Slice => {}}
+ );
+ }
+ else {
+ $db_result = [];
}
+ }
- $vars->{'ftc_states'} = [ FLAGTYPE_COMMENT_STATES ];
- $vars->{'ftc_flags'} = $ftc_flags;
+ foreach my $row (@$db_result) {
+ $ftc_flags->{$row->{'flagtype'}} ||= {};
+ $ftc_flags->{$row->{'flagtype'}}{$row->{'state'}} = $row->{text};
+ }
+
+ $vars->{'ftc_states'} = [FLAGTYPE_COMMENT_STATES];
+ $vars->{'ftc_flags'} = $ftc_flags;
}
#########
@@ -155,55 +149,55 @@ sub _set_ftc_states {
#########
sub flagtype_end_of_create {
- my ($self, $args) = @_;
- _set_flagtypes($args->{type});
+ my ($self, $args) = @_;
+ _set_flagtypes($args->{type});
}
sub flagtype_end_of_update {
- my ($self, $args) = @_;
- _set_flagtypes($args->{type});
+ my ($self, $args) = @_;
+ _set_flagtypes($args->{type});
}
sub _set_flagtypes {
- my $flag_type = shift;
- my $flagtype_id = $flag_type->id;
- my $input = Bugzilla->input_params;
- my $dbh = Bugzilla->dbh;
-
- foreach my $state (FLAGTYPE_COMMENT_STATES) {
- next if (!defined $input->{"ftc_${flagtype_id}_$state"}
- && !defined $input->{"ftc_new_$state"});
-
- my $text = $input->{"ftc_${flagtype_id}_$state"} || $input->{"ftc_new_$state"} || '';
- $text =~ s/\r\n/\n/g;
- trick_taint($text);
-
- if ($text ne '') {
- if ($dbh->selectrow_array(
- "SELECT 1 FROM flagtype_comments WHERE type_id=? AND on_status=?",
- undef,
- $flagtype_id, $state)
- ) {
- $dbh->do(
- "UPDATE flagtype_comments SET comment=?
- WHERE type_id=? AND on_status=?",
- undef,
- $text, $flagtype_id, $state);
- } else {
- $dbh->do(
- "INSERT INTO flagtype_comments(type_id, on_status, comment)
- VALUES (?, ?, ?)",
- undef,
- $flagtype_id, $state, $text);
- }
-
- } else {
- $dbh->do(
- "DELETE FROM flagtype_comments WHERE type_id=? AND on_status=?",
- undef,
- $flagtype_id, $state);
- }
+ my $flag_type = shift;
+ my $flagtype_id = $flag_type->id;
+ my $input = Bugzilla->input_params;
+ my $dbh = Bugzilla->dbh;
+
+ foreach my $state (FLAGTYPE_COMMENT_STATES) {
+ next
+ if (!defined $input->{"ftc_${flagtype_id}_$state"}
+ && !defined $input->{"ftc_new_$state"});
+
+ my $text
+ = $input->{"ftc_${flagtype_id}_$state"} || $input->{"ftc_new_$state"} || '';
+ $text =~ s/\r\n/\n/g;
+ trick_taint($text);
+
+ if ($text ne '') {
+ if ($dbh->selectrow_array(
+ "SELECT 1 FROM flagtype_comments WHERE type_id=? AND on_status=?", undef,
+ $flagtype_id, $state
+ ))
+ {
+ $dbh->do(
+ "UPDATE flagtype_comments SET comment=?
+ WHERE type_id=? AND on_status=?", undef, $text, $flagtype_id, $state
+ );
+ }
+ else {
+ $dbh->do(
+ "INSERT INTO flagtype_comments(type_id, on_status, comment)
+ VALUES (?, ?, ?)", undef, $flagtype_id, $state, $text
+ );
+ }
+
+ }
+ else {
+ $dbh->do("DELETE FROM flagtype_comments WHERE type_id=? AND on_status=?",
+ undef, $flagtype_id, $state);
}
+ }
}
__PACKAGE__->NAME;
diff --git a/extensions/FlagTypeComment/lib/Constants.pm b/extensions/FlagTypeComment/lib/Constants.pm
index d6242b78b..ee3a54076 100644
--- a/extensions/FlagTypeComment/lib/Constants.pm
+++ b/extensions/FlagTypeComment/lib/Constants.pm
@@ -26,28 +26,26 @@ use warnings;
use base qw(Exporter);
our @EXPORT = qw(
- FLAGTYPE_COMMENT_TEMPLATES
- FLAGTYPE_COMMENT_STATES
- FLAGTYPE_COMMENT_BUG_FLAGS
- FLAGTYPE_COMMENT_ATTACHMENT_FLAGS
+ FLAGTYPE_COMMENT_TEMPLATES
+ FLAGTYPE_COMMENT_STATES
+ FLAGTYPE_COMMENT_BUG_FLAGS
+ FLAGTYPE_COMMENT_ATTACHMENT_FLAGS
);
-use constant FLAGTYPE_COMMENT_STATES => ("?", "+", "-");
-use constant FLAGTYPE_COMMENT_BUG_FLAGS => 0;
+use constant FLAGTYPE_COMMENT_STATES => ("?", "+", "-");
+use constant FLAGTYPE_COMMENT_BUG_FLAGS => 0;
use constant FLAGTYPE_COMMENT_ATTACHMENT_FLAGS => 1;
sub FLAGTYPE_COMMENT_TEMPLATES {
- my @result = ("admin/flag-type/edit.html.tmpl");
- if (FLAGTYPE_COMMENT_BUG_FLAGS) {
- push @result, ("bug/comments.html.tmpl");
- }
- if (FLAGTYPE_COMMENT_ATTACHMENT_FLAGS) {
- push @result, (
- "attachment/edit.html.tmpl",
- "attachment/createformcontents.html.tmpl",
- );
- }
- return @result;
+ my @result = ("admin/flag-type/edit.html.tmpl");
+ if (FLAGTYPE_COMMENT_BUG_FLAGS) {
+ push @result, ("bug/comments.html.tmpl");
+ }
+ if (FLAGTYPE_COMMENT_ATTACHMENT_FLAGS) {
+ push @result,
+ ("attachment/edit.html.tmpl", "attachment/createformcontents.html.tmpl",);
+ }
+ return @result;
}
1;