# BMO - allow "end of request" processing
Bugzilla::Hook::process('request_cleanup');
+ Bugzilla::Bug->CLEANUP;
my $main = Bugzilla->request_cache->{dbh_main};
my $shadow = Bugzilla->request_cache->{dbh_shadow};
use File::Copy;
use List::Util qw(max);
+use Scalar::Util qw(weaken);
use Storable qw(dclone);
use base qw(Bugzilla::Object);
=cut
sub bug {
+ my ($self) = @_;
require Bugzilla::Bug;
- return $_[0]->{bug} //= Bugzilla::Bug->new({ id => $_[0]->bug_id, cache => 1 });
+ return $self->{bug} if defined $self->{bug};
+ my $bug = $self->{bug} = Bugzilla::Bug->new({ id => $_[0]->bug_id, cache => 1 });
+ weaken($self->{bug});
+ return $bug;
}
=over
editable_bug_fields
);
+my %CLEANUP;
+
#####################################################################
# Constants
#####################################################################
return $error_self;
}
+ $CLEANUP{$self->id} = $self;
+ weaken($CLEANUP{$self->id});
+
return $self;
}
return $key . ',' . Bugzilla->user->id;
}
+sub CLEANUP {
+ foreach my $bug (values %CLEANUP) {
+ next unless $bug;
+ delete $bug->{depends_on_obj};
+ delete $bug->{blocks_obj};
+ }
+ %CLEANUP = ();
+}
+
sub check {
my $class = shift;
my ($param, $field) = @_;
use Bugzilla::Util;
use List::Util qw(first);
-use Scalar::Util qw(blessed);
+use Scalar::Util qw(blessed weaken);
###############################
#### Initialization ####
sub bug {
my $self = shift;
require Bugzilla::Bug;
- $self->{bug} ||= new Bugzilla::Bug($self->bug_id);
- return $self->{bug};
+ my $bug = $self->{bug} ||= new Bugzilla::Bug($self->bug_id);
+ weaken($self->{bug});
+ return $bug;
}
sub is_about_attachment {
use List::MoreUtils qw(none);
our $VERSION = '1';
+our @FLAG_CACHE;
BEGIN {
*Bugzilla::tracking_flags = \&_tracking_flags;
}
}
+sub request_cleanup {
+ foreach my $flag (@FLAG_CACHE) {
+ my $bug_flag = delete $flag->{bug_flag};
+ if ($bug_flag) {
+ delete $bug_flag->{bug};
+ delete $bug_flag->{tracking_flag};
+ }
+ foreach my $value (@{ $flag->{values} }) {
+ delete $value->{tracking_flag};
+ }
+ }
+ @FLAG_CACHE = ();
+}
+
sub bug_end_of_create {
my ($self, $args) = @_;
my $bug = $args->{'bug'};
return $class->SUPER::new($param);
}
+sub new_from_hash {
+ my $class = shift;
+ my $cache = Bugzilla->request_cache->{'tracking_flags'} //= {};
+ my $flag = $class->SUPER::new_from_hash(@_);
+ if ($flag) {
+ push @Bugzilla::Extension::TrackingFlags::FLAG_CACHE, $flag;
+ }
+ return $flag;
+}
+
sub create {
my $class = shift;
my $params = shift;
use Bugzilla::Error;
use Bugzilla::Group;
use Bugzilla::Util qw(detaint_natural trim);
-use Scalar::Util qw(blessed);
+use Scalar::Util qw(blessed weaken);
###############################
#### Initialization ####
sub comment { return $_[0]->{'comment'}; }
sub tracking_flag {
- return $_[0]->{'tracking_flag'} ||= Bugzilla::Extension::TrackingFlags::Flag->new({
+ return $_[0]->{'tracking_flag'} if $_[0]->{'tracking_flag'};
+ my $tf = $_[0]->{'tracking_flag'} = Bugzilla::Extension::TrackingFlags::Flag->new({
id => $_[0]->tracking_flag_id, cache => 1
});
+ weaken($_[0]->{'tracking_flag'});
+ return $tf;
}
sub setter_group {