aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2019-09-13 16:19:08 +0100
committerDave Arter <davea@mysociety.org>2019-09-13 17:11:04 +0100
commit5bf5c08a3a25c91866ce478f01fc6c4ad9d25eb6 (patch)
tree65b1618f5975337ae6a3c01f1c656e0123c92e9f
parentb39c2b5797bc7022162b3085bfe189ad2254e231 (diff)
[Hounslow] Send report to inbox before Open311 send, not after
-rw-r--r--perllib/FixMyStreet/Cobrand/Hounslow.pm19
-rw-r--r--perllib/FixMyStreet/SendReport/Open311.pm2
2 files changed, 15 insertions, 6 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Hounslow.pm b/perllib/FixMyStreet/Cobrand/Hounslow.pm
index 2987c0ae3..58da5160c 100644
--- a/perllib/FixMyStreet/Cobrand/Hounslow.pm
+++ b/perllib/FixMyStreet/Cobrand/Hounslow.pm
@@ -73,15 +73,24 @@ sub link_to_council_cobrand { "Hounslow Highways" }
# Instead, force the borough council name to be used.
sub all_reports_single_body { { name => "Hounslow Borough Council" } }
-sub open311_post_send {
- my ($self, $row, $h) = @_;
+sub open311_pre_send {
+ my ($self, $row, $open311, $h) = @_;
- # Check Open311 was successful
- return unless $row->external_id;
+ return unless $row->isa("FixMyStreet::DB::Result::Problem");
+
+ # Reload the problem from the DB, as we want to save our changes to it
+ # without affecting the existing instance.
+ $row = $row->result_source->resultset->find( { id => $row->id } );
+
+ # Stop the email being sent for each Open311 failure; only the once.
+ return if $row->get_extra_metadata('hounslow_email_sent');
my $e = join( '@', 'enquiries', $self->council_url . 'highways.org' );
my $sender = FixMyStreet::SendReport::Email->new( to => [ [ $e, 'Hounslow Highways' ] ] );
- $sender->send($row, $h);
+ if (!$sender->send($row, $h)) {
+ $row->set_extra_metadata('hounslow_email_sent', 1);
+ $row->update;
+ }
}
sub open311_config {
diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm
index fcb6f7298..7445699a2 100644
--- a/perllib/FixMyStreet/SendReport/Open311.pm
+++ b/perllib/FixMyStreet/SendReport/Open311.pm
@@ -74,7 +74,7 @@ sub send {
my $open311 = Open311->new( %open311_params );
- $cobrand->call_hook(open311_pre_send => $row, $open311);
+ $cobrand->call_hook(open311_pre_send => $row, $open311, $h);
my $resp = $open311->send_service_request( $row, $h, $contact->email );
if (FixMyStreet->test_mode) {