aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/oxfordshire/send-rdi-emails69
1 files changed, 69 insertions, 0 deletions
diff --git a/bin/oxfordshire/send-rdi-emails b/bin/oxfordshire/send-rdi-emails
new file mode 100755
index 000000000..ef0931d6c
--- /dev/null
+++ b/bin/oxfordshire/send-rdi-emails
@@ -0,0 +1,69 @@
+#!/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 $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,
+ user => $inspector,
+ };
+ my $rdi = FixMyStreet::Integrations::ExorRDI->new($params);
+ try {
+ my $hdrs = {
+ To => join('', 'fms', '_', 'admin', '@', $cobrand->admin_user_domain),
+ _attachments_ => [ {
+ body => $rdi->construct,
+ attributes => {
+ filename => $rdi->filename,
+ charset => 'utf-8',
+ content_type => 'text/csv',
+ name => $rdi->filename,
+ }
+ } ],
+ };
+
+ my $result = FixMyStreet::Email::send_cron(
+ FixMyStreet::DB->storage->schema,
+ "rdi.txt", $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;