diff options
-rw-r--r-- | extensions/ExternalBugs/Extension.pm | 45 | ||||
-rw-r--r-- | extensions/ExternalBugs/lib/Job/SFDC.pm | 41 | ||||
-rw-r--r-- | extensions/ExternalBugs/lib/Type/SFDC.pm | 44 | ||||
-rw-r--r-- | extensions/ExternalBugs/lib/Type/SFDC_DEV.pm | 44 | ||||
-rw-r--r-- | extensions/ExternalBugs/lib/Type/SFDC_QA.pm | 44 | ||||
-rw-r--r-- | extensions/ExternalBugs/lib/Type/SFDC_Stage.pm | 44 |
6 files changed, 233 insertions, 29 deletions
diff --git a/extensions/ExternalBugs/Extension.pm b/extensions/ExternalBugs/Extension.pm index 731da83e5..8bddda069 100644 --- a/extensions/ExternalBugs/Extension.pm +++ b/extensions/ExternalBugs/Extension.pm @@ -110,17 +110,15 @@ sub _add_external_bug { # Don't do anything if the external bug already exists for this bug return if any { - $_->ext_bz_id == $ext_bz->{ext_bz_id} + $_->ext_bz_id == $ext_bz->{ext_bz_id} && $_->ext_bz_bug_id eq trim($ext_bz->{ext_bz_bug_id}) - } - @$current_bugs; + } @$current_bugs; # Don't do anything if the external bug already added for this bug return if any { - $_->{ext_bz}->{ext_bz_id} == $ext_bz->{ext_bz_id} + $_->{ext_bz}->{ext_bz_id} == $ext_bz->{ext_bz_id} && $_->{ext_bz}->{ext_bz_bug_id} eq trim($ext_bz->{ext_bz_bug_id}) - } - @{$self->{_added_external_bugs}}; + } @{$self->{_added_external_bugs}}; # Save the external bug details so we can do the create later. push @{$self->{_added_external_bugs}}, {bug_id => $self->id, ext_bz => $ext_bz}; @@ -171,12 +169,12 @@ sub db_schema_abstract_schema { id => {TYPE => 'MEDIUMSERIAL', NOTNULL => 1, PRIMARYKEY => 1}, url => {TYPE => 'varchar(2000)', NOTNULL => 1}, description => {TYPE => 'varchar(2000)', NOTNULL => 1}, - full_url => {TYPE => 'varchar(2000)'}, - type => {TYPE => 'varchar(64)', NOTNULL => 1, DEFAULT => "'None'"}, - can_get => {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => '0'}, - can_send => {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => '0'}, - must_send => {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => '0'}, - send_once => {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => '0'}, + full_url => {TYPE => 'varchar(2000)'}, + type => {TYPE => 'varchar(64)', NOTNULL => 1, DEFAULT => "'None'"}, + can_get => {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => '0'}, + can_send => {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => '0'}, + must_send => {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => '0'}, + send_once => {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => '0'}, ## REDHAT EXTENSION 1326979: change regex to an FK ext_bz_regex_id => {TYPE => 'INT3', REFERENCES => {TABLE => 'ext_bz_regex', COLUMN => 'id'}}, @@ -200,12 +198,12 @@ sub db_schema_abstract_schema { REFERENCES => {TABLE => 'bugs', COLUMN => 'bug_id', DELETE => 'CASCADE'} }, ext_bz_id => { - TYPE => 'INT3', - NOTNULL => 1, + TYPE => 'INT3', + NOTNULL => 1, REFERENCES => {TABLE => 'external_bugzilla', COLUMN => 'id', DELETE => 'CASCADE'} }, - ext_bz_bug_id => {TYPE => 'varchar(64)', NOTNULL => 1}, + ext_bz_bug_id => {TYPE => 'varchar(64)', NOTNULL => 1}, ext_status => {TYPE => 'varchar(64)', NOTNULL => 1, DEFAULT => "'None'"}, ext_priority => {TYPE => 'varchar(64)', NOTNULL => 1, DEFAULT => "'None'"}, ext_description => {TYPE => 'varchar(2000)', NOTNULL => 1, DEFAULT => "'None'"}, @@ -226,8 +224,8 @@ sub db_schema_abstract_schema { $schema->{ext_bz_group_map} = { FIELDS => [ ext_bz_id => { - TYPE => 'INT3', - NOTNULL => 1, + TYPE => 'INT3', + NOTNULL => 1, REFERENCES => {TABLE => 'external_bugzilla', COLUMN => 'id', DELETE => 'CASCADE'} }, @@ -502,7 +500,8 @@ EOS } # Scrub internal links; - $dbh->do(q{ + $dbh->do( + q{ UPDATE ext_bz_bug_map SET ext_status = '', ext_description = '', @@ -520,7 +519,8 @@ AND ( AND ext_bz_bug_id IN ( SELECT DISTINCT bug_id::text FROM bug_group_map ) - }, undef, Bugzilla->params->{'internal_link_name'}); + }, undef, Bugzilla->params->{'internal_link_name'} + ); } my $ext_description @@ -1005,7 +1005,7 @@ sub _sync_internal_links { if ($int_ext_bz && $int_ext_bz->id == $args->{ext_bz_id}) { my $int_bug = Bugzilla::Bug->check($args->{ext_bz_bug_id}); - if (@{$int_bug->groups}) { + if (scalar @{$int_bug->groups_in}) { $args->{is_private} = 1; $args->{ext_status} = ''; $args->{ext_description} = ''; @@ -1160,10 +1160,9 @@ sub bug_end_of_update { ) && ( none { - $_->ext_bz_id == $ext_bug->ext_bz_id + $_->ext_bz_id == $ext_bug->ext_bz_id and $_->ext_bz_bug_id eq $ext_bug->ext_bz_bug_id - } - @$dup_ext_bugs + } @$dup_ext_bugs ) ) { diff --git a/extensions/ExternalBugs/lib/Job/SFDC.pm b/extensions/ExternalBugs/lib/Job/SFDC.pm index cf6844439..145e81cdf 100644 --- a/extensions/ExternalBugs/lib/Job/SFDC.pm +++ b/extensions/ExternalBugs/lib/Job/SFDC.pm @@ -7,6 +7,8 @@ use strict; use warnings; use 5.10.1; +use Scalar::Util qw(blessed); + BEGIN { ## no critic (ProhibitStringyEval) # This is safe and avoids having to conditionally use this module if TheSchwartz is not installed @@ -91,7 +93,14 @@ sub work { $re = qr/^SFDC./; } - my @trackers = grep { $_->type->type =~ /$re/ } @{$bug->external_bugs}; + my @trackers; + + if (exists $job->arg->{ext_bz_type_id}) { + push(@trackers, $job->arg->{ext_bz_type_id}); + } + else { + @trackers = grep { $_->type->type =~ /$re/ } @{$bug->external_bugs}; + } ## RED HAT EXTENSION END 1175565 1262660 unless (scalar @trackers) { @@ -102,21 +111,41 @@ sub work { ## REDHAT EXTENSION START 1132415 # To prevent SFDC from trying to update a bug before it is committed, we # will check it against the recorded delta_ts. If the bug value is earlier, - # it's a good sign that the bug has not been commited - if ($bug->delta_ts lt $delta_ts) { + # it's a good sign that the bug has not been committed + if ($delta_ts && $bug->delta_ts lt $delta_ts) { $job->failed("Bug $bug_id does not exist, or delta_ts is too early"); return; } ## REDHAT EXTENSION END 1132415 - my ($bug_xml_data, $bug_xml_comments) = _fetch_bug_data($bug_id, $start); + my ($bug_xml_data, $bug_xml_comments); + + if (exists $job->arg->{bug_xml_data}) { + $bug_xml_data = $job->arg->{bug_xml_data}; + $bug_xml_comments = $job->arg->{bug_xml_comments}; + + } + else { + ($bug_xml_data, $bug_xml_comments) = _fetch_bug_data($bug_id, $start); + } foreach my $tracker (@trackers) { - my $type = Bugzilla::Extension::ExternalBugs::Type->new($tracker->ext_bz_id); + my $tid; + + if (blessed($tracker)) { + $tid = $tracker->ext_bz_id; + } + else { + $tid = $tracker; + } + + my $type = Bugzilla::Extension::ExternalBugs::Type->check({id => $tid}); # If the tracker is set to 'must_send' OR the tracker is a 'can_send' AND the sync box has been # checked, send the bug. if not, skip this tracker. - if ($type->must_send || ($type->can_send && $should_send->{$tracker->id})) { + if ($type->must_send + || ($type->can_send && (!$should_send || $should_send->{$tracker->id}))) + { my $success = eval { $type->send_to_sfdc($bug_id, $bug_xml_data, $bug_xml_comments,); }; diff --git a/extensions/ExternalBugs/lib/Type/SFDC.pm b/extensions/ExternalBugs/lib/Type/SFDC.pm index 6e76fdb74..abf14356a 100644 --- a/extensions/ExternalBugs/lib/Type/SFDC.pm +++ b/extensions/ExternalBugs/lib/Type/SFDC.pm @@ -151,6 +151,50 @@ sub sfdc_hostname { return Bugzilla->params->{sfdc_hostname}; } +sub send_changes { + my ($self, $params) = @_; + + $logger->debug("SFDC SOAP: Entering send_changes"); + + my $ext_bug = $params->{'ext_bug'}; + my $bug = $params->{'bug'}; + my $start = $params->{'start'}; + + my $serializer = Bugzilla::XMLRPC::Serializer->new(); + + # Send a full copy of the bug report using Bug.get + my $bug_data = Bugzilla::WebService::Bug->get({ + ids => [$bug->id], + extra_fields => ['external_bugs', 'description', 'flags'], + }); + my $bug_xml_data = $serializer->envelope('response', 'Bug.get', $bug_data); + + # Get the comments for this bug + my $bug_comments = Bugzilla::WebService::Bug->comments( + {ids => [$bug->id], new_since => $start}); + my $bug_xml_comments + = $serializer->envelope('response', 'Bug.comments', $bug_comments); + + ## REDHAT EXTENSION 965415: Bugzilla 4.4 switches the above calls to + # the shadow db. You need to switch make to the main one + Bugzilla->switch_to_main_db(); + + # We now need to send the events to the Job Queue. However, we must set + # We need to record the ext_bz info since there is no guarantee that the + # row will exist at the time we send the event. + Bugzilla->job_queue->insert( + 'send_sfdc', + { + ext_bz_type_id => $ext_bug->ext_bz_id, + bug_id => $ext_bug->bug_id, + bug_xml_data => $bug_xml_data, + bug_xml_comments => $bug_xml_comments, + } + ); + + return 1; +} + 1; __END__ diff --git a/extensions/ExternalBugs/lib/Type/SFDC_DEV.pm b/extensions/ExternalBugs/lib/Type/SFDC_DEV.pm index 45b802977..eeeade631 100644 --- a/extensions/ExternalBugs/lib/Type/SFDC_DEV.pm +++ b/extensions/ExternalBugs/lib/Type/SFDC_DEV.pm @@ -148,4 +148,48 @@ sub sfdc_hostname { return $HOSTNAME; } +sub send_changes { + my ($self, $params) = @_; + + $logger->debug("SFDC SOAP: Entering send_changes"); + + my $ext_bug = $params->{'ext_bug'}; + my $bug = $params->{'bug'}; + my $start = $params->{'start'}; + + my $serializer = Bugzilla::XMLRPC::Serializer->new(); + + # Send a full copy of the bug report using Bug.get + my $bug_data = Bugzilla::WebService::Bug->get({ + ids => [$bug->id], + extra_fields => ['external_bugs', 'description', 'flags'], + }); + my $bug_xml_data = $serializer->envelope('response', 'Bug.get', $bug_data); + + # Get the comments for this bug + my $bug_comments = Bugzilla::WebService::Bug->comments( + {ids => [$bug->id], new_since => $start}); + my $bug_xml_comments + = $serializer->envelope('response', 'Bug.comments', $bug_comments); + + ## REDHAT EXTENSION 965415: Bugzilla 4.4 switches the above calls to + # the shadow db. You need to switch make to the main one + Bugzilla->switch_to_main_db(); + + # We now need to send the events to the Job Queue. However, we must set + # We need to record the ext_bz info since there is no guarantee that the + # row will exist at the time we send the event. + Bugzilla->job_queue->insert( + 'send_sfdc', + { + ext_bz_type_id => $ext_bug->ext_bz_id, + bug_id => $ext_bug->bug_id, + bug_xml_data => $bug_xml_data, + bug_xml_comments => $bug_xml_comments, + } + ); + + return 1; +} + 1; diff --git a/extensions/ExternalBugs/lib/Type/SFDC_QA.pm b/extensions/ExternalBugs/lib/Type/SFDC_QA.pm index 1c9e6f20e..00b6719e0 100644 --- a/extensions/ExternalBugs/lib/Type/SFDC_QA.pm +++ b/extensions/ExternalBugs/lib/Type/SFDC_QA.pm @@ -144,6 +144,50 @@ sub send_to_sfdc { return 1; } +sub send_changes { + my ($self, $params) = @_; + + $logger->debug("SFDC SOAP: Entering send_changes"); + + my $ext_bug = $params->{'ext_bug'}; + my $bug = $params->{'bug'}; + my $start = $params->{'start'}; + + my $serializer = Bugzilla::XMLRPC::Serializer->new(); + + # Send a full copy of the bug report using Bug.get + my $bug_data = Bugzilla::WebService::Bug->get({ + ids => [$bug->id], + extra_fields => ['external_bugs', 'description', 'flags'], + }); + my $bug_xml_data = $serializer->envelope('response', 'Bug.get', $bug_data); + + # Get the comments for this bug + my $bug_comments = Bugzilla::WebService::Bug->comments( + {ids => [$bug->id], new_since => $start}); + my $bug_xml_comments + = $serializer->envelope('response', 'Bug.comments', $bug_comments); + + ## REDHAT EXTENSION 965415: Bugzilla 4.4 switches the above calls to + # the shadow db. You need to switch make to the main one + Bugzilla->switch_to_main_db(); + + # We now need to send the events to the Job Queue. However, we must set + # We need to record the ext_bz info since there is no guarantee that the + # row will exist at the time we send the event. + Bugzilla->job_queue->insert( + 'send_sfdc', + { + ext_bz_type_id => $ext_bug->ext_bz_id, + bug_id => $ext_bug->bug_id, + bug_xml_data => $bug_xml_data, + bug_xml_comments => $bug_xml_comments, + } + ); + + return 1; +} + sub sfdc_hostname { return $HOSTNAME; } diff --git a/extensions/ExternalBugs/lib/Type/SFDC_Stage.pm b/extensions/ExternalBugs/lib/Type/SFDC_Stage.pm index 3eceae291..abaf342ef 100644 --- a/extensions/ExternalBugs/lib/Type/SFDC_Stage.pm +++ b/extensions/ExternalBugs/lib/Type/SFDC_Stage.pm @@ -148,6 +148,50 @@ sub sfdc_hostname { return $HOSTNAME; } +sub send_changes { + my ($self, $params) = @_; + + $logger->debug("SFDC SOAP: Entering send_changes"); + + my $ext_bug = $params->{'ext_bug'}; + my $bug = $params->{'bug'}; + my $start = $params->{'start'}; + + my $serializer = Bugzilla::XMLRPC::Serializer->new(); + + # Send a full copy of the bug report using Bug.get + my $bug_data = Bugzilla::WebService::Bug->get({ + ids => [$bug->id], + extra_fields => ['external_bugs', 'description', 'flags'], + }); + my $bug_xml_data = $serializer->envelope('response', 'Bug.get', $bug_data); + + # Get the comments for this bug + my $bug_comments = Bugzilla::WebService::Bug->comments( + {ids => [$bug->id], new_since => $start}); + my $bug_xml_comments + = $serializer->envelope('response', 'Bug.comments', $bug_comments); + + ## REDHAT EXTENSION 965415: Bugzilla 4.4 switches the above calls to + # the shadow db. You need to switch make to the main one + Bugzilla->switch_to_main_db(); + + # We now need to send the events to the Job Queue. However, we must set + # We need to record the ext_bz info since there is no guarantee that the + # row will exist at the time we send the event. + Bugzilla->job_queue->insert( + 'send_sfdc', + { + ext_bz_type_id => $ext_bug->ext_bz_id, + bug_id => $ext_bug->bug_id, + bug_xml_data => $bug_xml_data, + bug_xml_comments => $bug_xml_comments, + } + ); + + return 1; +} + 1; __DATA__ |