aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Script/Reports.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/Script/Reports.pm')
-rw-r--r--perllib/FixMyStreet/Script/Reports.pm31
1 files changed, 24 insertions, 7 deletions
diff --git a/perllib/FixMyStreet/Script/Reports.pm b/perllib/FixMyStreet/Script/Reports.pm
index 578d966d6..ecd461cd9 100644
--- a/perllib/FixMyStreet/Script/Reports.pm
+++ b/perllib/FixMyStreet/Script/Reports.pm
@@ -8,7 +8,6 @@ use DateTime::Format::Pg;
use Utils;
use Utils::OpenStreetMap;
-use mySociety::MaPit;
use FixMyStreet;
use FixMyStreet::Cobrand;
@@ -44,7 +43,7 @@ sub send(;$) {
debug_print("starting to loop through unsent problem reports...") if $debug_mode;
while (my $row = $unsent->next) {
- my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($row->cobrand)->new();
+ my $cobrand = $row->get_cobrand_logged;
FixMyStreet::DB->schema->cobrand($cobrand);
if ($debug_mode) {
@@ -127,10 +126,19 @@ sub send(;$) {
$missing = join(' / ', @missing) if @missing;
}
+ my $send_confirmation_email = $cobrand->report_sent_confirmation_email;
+
my @dear;
my %reporters = ();
my $skip = 0;
while (my $body = $bodies->next) {
+ # See if this body wants confirmation email (in case report made on national site, for example)
+ if (my $cobrand_body = $body->get_cobrand_handler) {
+ if (my $id_ref = $cobrand_body->report_sent_confirmation_email) {
+ $send_confirmation_email = $id_ref;
+ }
+ }
+
my $sender_info = $cobrand->get_body_sender( $body, $row->category );
my $sender = "FixMyStreet::SendReport::" . $sender_info->{method};
@@ -140,7 +148,9 @@ sub send(;$) {
}
$reporters{ $sender } ||= $sender->new();
- my $inspection_required = $sender_info->{contact}->get_extra_metadata('inspection_required') if $sender_info->{contact};
+ my $inspection_required = $sender_info->{contact}
+ ? $sender_info->{contact}->get_extra_metadata('inspection_required')
+ : undef;
if ( $inspection_required ) {
my $reputation_threshold = $sender_info->{contact}->get_extra_metadata('reputation_threshold') || 0;
my $reputation_threshold_met = 0;
@@ -211,12 +221,13 @@ sub send(;$) {
# Multiply results together, so one success counts as a success.
my $result = -1;
+ my @methods;
for my $sender ( keys %reporters ) {
debug_print("sending using " . $sender, $row->id) if $debug_mode;
$sender = $reporters{$sender};
my $res = $sender->send( $row, \%h );
$result *= $res;
- $row->add_send_method($sender) if !$res;
+ push @methods, $sender if !$res;
if ( $sender->unconfirmed_counts) {
foreach my $e (keys %{ $sender->unconfirmed_counts } ) {
foreach my $c (keys %{ $sender->unconfirmed_counts->{$e} }) {
@@ -229,12 +240,19 @@ sub send(;$) {
if FixMyStreet->test_mode && $sender->can('open311_test_req_used');
}
+ # Add the send methods now because e.g. Open311
+ # send() calls $row->discard_changes
+ foreach (@methods) {
+ $row->add_send_method($_);
+ }
+
unless ($result) {
$row->update( {
whensent => \'current_timestamp',
lastupdate => \'current_timestamp',
} );
- if ( $cobrand->report_sent_confirmation_email && !$h{anonymous_report}) {
+ if ($send_confirmation_email && !$h{anonymous_report}) {
+ $h{sent_confirm_id_ref} = $row->$send_confirmation_email;
_send_report_sent_email( $row, \%h, $nomail, $cobrand );
}
debug_print("send successful: OK", $row->id) if $debug_mode;
@@ -274,7 +292,7 @@ sub send(;$) {
} );
while (my $row = $unsent->next) {
my $base_url = FixMyStreet->config('BASE_URL');
- $sending_errors .= "* " . $base_url . "/report/" . $row->id . ", failed "
+ $sending_errors .= "\n" . '=' x 80 . "\n\n" . "* " . $base_url . "/report/" . $row->id . ", failed "
. $row->send_fail_count . " times, last at " . $row->send_fail_timestamp
. ", reason " . $row->send_fail_reason . "\n";
}
@@ -304,7 +322,6 @@ sub _send_report_sent_email {
$h,
{
To => $row->user->email,
- From => [ $cobrand->contact_email, $cobrand->contact_name ],
},
undef,
$nomail,