Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Bugzilla/DB/Schema.pm
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,43 @@ use constant ABSTRACT_SCHEMA => {
],
},

flag_activity => {
FIELDS => [
id => {TYPE => 'MEDIUMSERIAL', NOTNULL => 1, PRIMARYKEY => 1},
flag_when => {TYPE => 'DATETIME', NOTNULL => 1},
type_id => {
TYPE => 'INT2',
NOTNULL => 1,
REFERENCES => {TABLE => 'flagtypes', COLUMN => 'id', DELETE => 'CASCADE'},
},
flag_id => {TYPE => 'INT3', NOTNULL => 1},
setter_id => {
TYPE => 'INT3',
NOTNULL => 1,
REFERENCES => {TABLE => 'profiles', COLUMN => 'userid'},
},
requestee_id => {
TYPE => 'INT3',
REFERENCES => {TABLE => 'profiles', COLUMN => 'userid'},
},
bug_id => {
TYPE => 'INT3',
NOTNULL => 1,
REFERENCES => {TABLE => 'bugs', COLUMN => 'bug_id', DELETE => 'CASCADE'},
},
attachment_id => {
TYPE => 'INT5',
REFERENCES => {TABLE => 'attachments', COLUMN => 'attach_id', DELETE => 'CASCADE'},
},
status => {TYPE => 'CHAR(1)', NOTNULL => 1},
],
INDEXES => [
flag_activity_flag_id_idx => ['flag_id'],
flag_activity_type_id_idx => ['type_id'],
flag_activity_bug_id_idx => ['bug_id'],
],
Comment on lines +765 to +770

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in "Bug 1806896 - Add status/flag_when index to flag_activity" commit

},

# "flagtypes" defines the types of flags that can be set.
flagtypes => {
FIELDS => [
Expand Down
48 changes: 48 additions & 0 deletions Bugzilla/Flag.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ whose names start with _ or a re specifically noted as being private.
use Scalar::Util qw(blessed);
use Storable qw(dclone);

use Bugzilla::FlagActivity;
use Bugzilla::FlagType;
use Bugzilla::Hook;
use Bugzilla::User;
Expand Down Expand Up @@ -489,6 +490,18 @@ sub create {
$params->{creation_date} = $params->{modification_date} = $timestamp;

$flag = $class->SUPER::create($params);

Bugzilla::FlagActivity->create({
flag_when => $timestamp,
setter_id => $flag->setter_id,
status => $flag->status,
type_id => $flag->type_id,
flag_id => $flag->id,
requestee_id => $flag->requestee_id,
bug_id => $flag->bug_id,
attachment_id => $flag->attach_id,
});

return $flag;
}

Expand All @@ -505,6 +518,17 @@ sub update {
$self->{'modification_date'}
= format_time($timestamp, '%Y-%m-%d %T', Bugzilla->local_timezone);
Bugzilla->memcached->clear({table => 'flags', id => $self->id});

Bugzilla::FlagActivity->create({
flag_when => $timestamp,
setter_id => $self->setter_id,
status => $self->status,
type_id => $self->type_id,
flag_id => $self->id,
requestee_id => $self->requestee_id,
bug_id => $self->bug_id,
attachment_id => $self->attach_id,
});
}

# BMO - provide a hook which passes the flag object
Expand Down Expand Up @@ -575,6 +599,18 @@ sub update_flags {
# because that isn't passed to remove_from_db().
Bugzilla::Hook::process('flag_deleted',
{flag => $old_flag, timestamp => $timestamp});

Bugzilla::FlagActivity->create({
flag_when => $timestamp,
setter_id => Bugzilla->user->id,
status => 'X',
type_id => $old_flag->type_id,
flag_id => $old_flag->id,
requestee_id => $old_flag->requestee_id,
bug_id => $old_flag->bug_id,
attachment_id => $old_flag->attach_id,
});

$old_flag->remove_from_db();
}

Expand Down Expand Up @@ -685,6 +721,18 @@ sub force_retarget {
my ($timestamp) = $dbh->selectrow_array('SELECT LOCALTIMESTAMP(0)');
Bugzilla::Hook::process('flag_deleted',
{flag => $flag, timestamp => $timestamp});

Bugzilla::FlagActivity->create({
flag_when => $timestamp,
setter_id => Bugzilla->user->id,
status => 'X',
type_id => $flag->type_id,
flag_id => $flag->id,
requestee_id => $flag->requestee_id,
bug_id => $flag->bug_id,
attachment_id => $flag->attach_id,
});

$flag->remove_from_db();
}
}
Expand Down
115 changes: 115 additions & 0 deletions Bugzilla/FlagActivity.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

package Bugzilla::FlagActivity;

use 5.10.1;
use strict;
use warnings;

use Bugzilla::Error qw(ThrowUserError);
use Bugzilla::Util qw(trim datetime_from);
use List::MoreUtils qw(none);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by modifying line 14 to use Bugzilla::Error qw(ThrowCodeError ThrowUserError);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just use use Bugzilla::Error; which will auto import them. This is what is done in most places in the code already.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line modified to use Bugzilla::Error; (commit "Bug 1806896 - Fix missing ThrowCodeError import in FlagActivity.pm")


use base qw( Bugzilla::Object );

use constant DB_TABLE => 'flag_activity';
use constant LIST_ORDER => 'id';
use constant AUDIT_CREATES => 0;
use constant AUDIT_UPDATES => 0;
use constant AUDIT_REMOVES => 0;

use constant DB_COLUMNS => qw(
id
flag_when
type_id
flag_id
setter_id
requestee_id
bug_id
attachment_id
status
);

sub _check_param_required {
my ($param) = @_;

return sub {
my ($invocant, $value) = @_;
$value = trim($value) or ThrowCodeError('param_required', {param => $param});
return $value;
},;
}

sub _check_date {
my ($invocant, $date) = @_;

$date = trim($date);
datetime_from($date)
or ThrowUserError('illegal_date',
{date => $date, format => 'YYYY-MM-DD HH24:MI:SS'});
return $date;
}

sub _check_status {
my ($self, $status) = @_;

if (none { $status eq $_ } qw( X + - ? )) {
ThrowUserError('flag_status_invalid', {id => $self->id, status => $status});
}
return $status;
}

use constant VALIDATORS => {
flag_when => \&_check_date,
type_id => _check_param_required('type_id'),
flag_id => _check_param_required('flag_id'),
setter_id => _check_param_required('setter_id'),
bug_id => _check_param_required('bug_id'),
status => \&_check_status,
};

sub flag_when { return $_[0]->{flag_when} }
sub type_id { return $_[0]->{type_id} }
sub flag_id { return $_[0]->{flag_id} }
sub setter_id { return $_[0]->{setter_id} }
sub bug_id { return $_[0]->{bug_id} }
sub requestee_id { return $_[0]->{requestee_id} }
sub attachment_id { return $_[0]->{attachment_id} }
sub status { return $_[0]->{status} }

sub type {
my ($self) = @_;
return $self->{type}
//= Bugzilla::FlagType->new({id => $self->type_id, cache => 1});
}

sub setter {
my ($self) = @_;
return $self->{setter}
//= Bugzilla::User->new({id => $self->setter_id, cache => 1});
}

sub requestee {
my ($self) = @_;
return undef unless defined $self->requestee_id;
return $self->{requestee}
//= Bugzilla::User->new({id => $self->requestee_id, cache => 1});
}

sub bug {
my ($self) = @_;
return $self->{bug} //= Bugzilla::Bug->new({id => $self->bug_id, cache => 1});
}

sub attachment {
my ($self) = @_;
return $self->{attachment}
//= Bugzilla::Attachment->new({id => $self->attachment_id, cache => 1});
}

1;
2 changes: 1 addition & 1 deletion extensions/BMO/bin/bug_1022707.pl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
print "Press <enter> to start, or ^C to cancel...\n";
readline;

my $update_fsa_sql = "UPDATE flag_state_activity SET type_id = 4 WHERE "
my $update_fsa_sql = "UPDATE flag_activity SET type_id = 4 WHERE "
. $dbh->sql_in('flag_id', $flag_ids);
my $update_flags_sql
= "UPDATE flags SET type_id = 4 WHERE " . $dbh->sql_in('id', $flag_ids);
Expand Down
14 changes: 7 additions & 7 deletions extensions/BMO/bin/export_bmo_etl.pl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Bugzilla::Group;
use Bugzilla::Logging;
use Bugzilla::User;
use Bugzilla::Extension::Review::FlagStateActivity;
use Bugzilla::FlagActivity;

use HTTP::Headers;
use HTTP::Request;
Expand Down Expand Up @@ -102,7 +102,7 @@
process_bugs();
process_attachments();
process_flags();
process_flag_state_activity();
process_flag_activity();
process_tracking_flags();
process_keywords();
process_see_also();
Expand Down Expand Up @@ -407,18 +407,18 @@ sub process_flags {
}
}

# Process flags that were removed today using the flag_state_activity table
# Process flags that were removed today using the flag_activity table
# These entries will also go into the flags table in BigQuery.
sub process_flag_state_activity {
my $table_name = 'flag_state_activity';
sub process_flag_activity {
my $table_name = 'flag_activity';
my $total_count = 0;
my $last_offset = 0;

logger("Processing $table_name.");

my $sth
= $dbh->prepare(
'SELECT id, flag_when FROM flag_state_activity WHERE status = \'X\' AND flag_when LIKE \''
'SELECT id, flag_when FROM flag_activity WHERE status = \'X\' AND flag_when LIKE \''
. $snapshot_date
. ' %\' ORDER BY id LIMIT ? OFFSET ?');

Expand All @@ -439,7 +439,7 @@ sub process_flag_state_activity {
logger("$table_name id $id with time $mod_time not found in cache.",
DEBUG_OUTPUT);

my $obj = Bugzilla::Extension::Review::FlagStateActivity->new($id);
my $obj = Bugzilla::FlagActivity->new($id);

if (!$obj) {
logger("Object $id not loaded from database or no longer exists");
Expand Down
Loading
Loading