diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/oxfordshire/send-rdi-emails | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/bin/oxfordshire/send-rdi-emails b/bin/oxfordshire/send-rdi-emails deleted file mode 100755 index 9cc3e5502..000000000 --- a/bin/oxfordshire/send-rdi-emails +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env perl - -use strict; -use warnings; -use v5.14; - -BEGIN { - use File::Basename qw(dirname); - use File::Spec; - my $d = dirname(File::Spec->rel2abs($0)); - require "$d/../../setenv.pl"; -} - -use DateTime; -use Try::Tiny; -use FixMyStreet; -use FixMyStreet::Cobrand; -use FixMyStreet::Email; -use FixMyStreet::Integrations::ExorRDI; - -my $end_date = DateTime->now( time_zone => FixMyStreet->time_zone || FixMyStreet->local_time_zone ) - ->truncate(to => 'hour')->set_hour(16); -my $start_date = $end_date->clone->subtract(days => 1); -my $inspection_date = $end_date; # All inspections are considered to have happened on the same date. - -my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('oxfordshire')->new; -$cobrand->set_lang_and_domain('en-gb', 1); -my @inspectors = $cobrand->users->search({ - 'user_body_permissions.permission_type' => 'report_inspect' -}, { - join => 'user_body_permissions', - distinct => 1, -})->all; - -foreach my $inspector (@inspectors) { - my $params = { - start_date => $start_date, - end_date => $end_date, - inspection_date => $inspection_date, - user => $inspector, - mark_as_processed => 1, - }; - my $email_params = { - start_date => $start_date, - end_date => $end_date, - user => $inspector, - staging_site => FixMyStreet->config('STAGING_SITE'), - }; - my $rdi = FixMyStreet::Integrations::ExorRDI->new($params); - try { - my $hdrs = { - To => join('', 'fms', '_', 'admin', '@', $cobrand->admin_user_domain), - _attachments_ => [ { - body_str => $rdi->construct, - attributes => { - filename => $rdi->filename, - charset => 'utf-8', - encoding => 'quoted-printable', - content_type => 'text/csv', - name => $rdi->filename, - } - } ], - }; - - my $result = FixMyStreet::Email::send_cron( - FixMyStreet::DB->schema, - "rdi.txt", $email_params, $hdrs, - undef, 0, $cobrand, - ); - if ($result) { - say "Failed to send inspection for " . $inspector->id; - } - } catch { - die $_ unless $_ =~ /FixMyStreet::Integrations::ExorRDI::Error/; - # Nothing to report, continue - } -} - -1; |