aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Open311/PostServiceRequestUpdates.pm
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2021-10-07 13:32:40 +0200
committerMarius Halden <marius.h@lden.org>2021-10-07 13:32:40 +0200
commit09dacfc6b8bf62addeee16c20b1d90c2a256da96 (patch)
tree7caa2bf9e92227ab74448f9b746dd28bbcb81b2a /perllib/Open311/PostServiceRequestUpdates.pm
parent585e57484f9c6332668bf1ac0a6a3b39dbe32223 (diff)
parentcea89fb87a96943708a1db0f646492fbfaaf000f (diff)
Merge tag 'v3.1' into fiksgatami-devfiksgatami-dev
Diffstat (limited to 'perllib/Open311/PostServiceRequestUpdates.pm')
-rwxr-xr-xperllib/Open311/PostServiceRequestUpdates.pm49
1 files changed, 38 insertions, 11 deletions
diff --git a/perllib/Open311/PostServiceRequestUpdates.pm b/perllib/Open311/PostServiceRequestUpdates.pm
index fadd063da..b9aa9ed50 100755
--- a/perllib/Open311/PostServiceRequestUpdates.pm
+++ b/perllib/Open311/PostServiceRequestUpdates.pm
@@ -14,14 +14,12 @@ use Open311;
use constant SEND_METHOD_OPEN311 => 'Open311';
has verbose => ( is => 'ro', default => 0 );
-has current_open311 => ( is => 'rw' );
sub send {
my $self = shift;
my $bodies = $self->fetch_bodies;
foreach my $body (values %$bodies) {
- $self->construct_open311($body);
$self->process_body($body);
}
}
@@ -41,18 +39,25 @@ sub fetch_bodies {
}
sub construct_open311 {
- my ($self, $body) = @_;
- my $o = Open311->new($self->open311_params($body));
- $self->current_open311($o);
+ my ($self, $body, $comment) = @_;
+ my $o = Open311->new($self->open311_params($body, $comment));
+ return $o;
}
sub open311_params {
- my ($self, $body) = @_;
+ my ($self, $body, $comment) = @_;
+
+ my $conf = $body;
+ if ($comment) {
+ my $cobrand_logged = $comment->get_cobrand_logged;
+ my $sender = $cobrand_logged->get_body_sender($body, $comment->problem);
+ $conf = $sender->{config};
+ }
my %open311_conf = (
- endpoint => $body->endpoint,
- jurisdiction => $body->jurisdiction,
- api_key => $body->api_key,
+ endpoint => $conf->endpoint,
+ jurisdiction => $conf->jurisdiction,
+ api_key => $conf->api_key,
extended_statuses => $body->send_extended_statuses,
fixmystreet_body => $body,
);
@@ -119,9 +124,9 @@ sub process_update {
return;
}
- my $o = $self->current_open311;
+ my $o = $self->construct_open311($body, $comment);
- $cobrand->call_hook(open311_pre_send => $comment, $o);
+ $cobrand->call_hook(open311_pre_send_updates => $comment);
my $id = $o->post_service_request_update( $comment );
@@ -141,6 +146,28 @@ sub process_update {
}
}
+sub summary_failures {
+ my $self = shift;
+ my $bodies = $self->fetch_bodies;
+ my $params = $self->construct_query(1);
+ my $u = FixMyStreet::DB->resultset("Comment")
+ ->to_body([ keys %$bodies ])
+ ->search({ "me.send_fail_count" => { '>', 0 } })
+ ->search($params, { join => "problem" });
+
+ my $base_url = FixMyStreet->config('BASE_URL');
+ my $sending_errors;
+ while (my $row = $u->next) {
+ my $url = $base_url . "/report/" . $row->problem_id;
+ $sending_errors .= "\n" . '=' x 80 . "\n\n" . "* $url, update " . $row->id . " failed "
+ . $row->send_fail_count . " times, last at " . $row->send_fail_timestamp
+ . ", reason " . $row->send_fail_reason . "\n";
+ }
+ if ($sending_errors) {
+ print '=' x 80 . "\n\n" . "The following updates failed sending:\n$sending_errors";
+ }
+}
+
sub log {
my ($self, $comment, $msg) = @_;
return unless $self->verbose;