diff options
author | Dave Arter <davea@mysociety.org> | 2017-09-05 12:10:28 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-09-11 12:49:06 +0100 |
commit | 2cc255b912dc0f79de270be682a9e85d7fb95d7a (patch) | |
tree | 975b0c325836c33a5b548c65d66127802d25efe4 /perllib | |
parent | c03096d4ffe3e17d504239ec4c0f006b1266c8e5 (diff) |
[Oxfordshire] Log when problems sent by RDI email.
The timestamp of when a problem was included in an RDI is shown on the
problem’s inspector form. Also check back and include any inspected
reports that for some reason haven't been instructed yet.
Fixes mysociety/fixmystreetforcouncils#223.
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/Integrations/ExorRDI.pm | 28 |
2 files changed, 25 insertions, 4 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm b/perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm index b03a2ab98..0fd9fe023 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm @@ -59,6 +59,7 @@ sub download : Path('download') : Args(0) { inspection_date => $start_date, end_date => $end_date + $one_day, user => $c->get_param('user_id'), + mark_as_processed => 0, }; my $rdi = FixMyStreet::Integrations::ExorRDI->new($params); diff --git a/perllib/FixMyStreet/Integrations/ExorRDI.pm b/perllib/FixMyStreet/Integrations/ExorRDI.pm index 4ce888cff..fc7e9d673 100644 --- a/perllib/FixMyStreet/Integrations/ExorRDI.pm +++ b/perllib/FixMyStreet/Integrations/ExorRDI.pm @@ -23,7 +23,7 @@ use Scalar::Util 'blessed'; use FixMyStreet::DB; use namespace::clean; -has [qw(start_date end_date inspection_date)] => ( +has [qw(start_date end_date inspection_date mark_as_processed)] => ( is => 'ro', required => 1, ); @@ -43,13 +43,23 @@ sub construct { my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('oxfordshire')->new; my $dtf = $cobrand->problems->result_source->storage->datetime_parser; + my $missed_cutoff = DateTime->now - DateTime::Duration->new( hours => 24 ); my %params = ( -and => [ state => [ 'action scheduled' ], external_id => { '!=' => undef }, - 'admin_log_entries.action' => 'inspected', - 'admin_log_entries.whenedited' => { '>=', $dtf->format_datetime($self->start_date) }, - 'admin_log_entries.whenedited' => { '<=', $dtf->format_datetime($self->end_date) }, + -or => [ + -and => [ + 'admin_log_entries.action' => 'inspected', + 'admin_log_entries.whenedited' => { '>=', $dtf->format_datetime($self->start_date) }, + 'admin_log_entries.whenedited' => { '<=', $dtf->format_datetime($self->end_date) }, + ], + -and => [ + extra => { -not_like => '%rdi_processed%' }, + 'admin_log_entries.action' => 'inspected', + 'admin_log_entries.whenedited' => { '<=', $dtf->format_datetime($missed_cutoff) }, + ] + ] ] ); @@ -198,6 +208,16 @@ sub construct { 0, 0, 0 # error counts, always zero ); + if ($self->mark_as_processed) { + # Mark all these problems are having been included in an RDI + my $now = DateTime->now->strftime( '%Y-%m-%d %H:%M' ); + $problems->reset; + while ( my $report = $problems->next ) { + $report->set_extra_metadata('rdi_processed' => $now); + $report->update; + } + } + # The RDI format is very weird CSV - each line must be wrapped in # double quotes. return join "", map { "\"$_\"\r\n" } @$body; |