aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/zurich-overdue-alert83
-rw-r--r--perllib/FixMyStreet/Cobrand/Zurich.pm24
-rw-r--r--templates/email/zurich/alert-moderation-overdue.txt1
3 files changed, 106 insertions, 2 deletions
diff --git a/bin/zurich-overdue-alert b/bin/zurich-overdue-alert
new file mode 100755
index 000000000..aa9f6fe60
--- /dev/null
+++ b/bin/zurich-overdue-alert
@@ -0,0 +1,83 @@
+#!/usr/bin/env perl
+
+# zurich-overdue-alert:
+# Send email alerts to administrators for overdue admin activities.
+#
+# Copyright (c) 2012 UK Citizens Online Democracy. All rights reserved.
+# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
+
+use strict;
+use warnings;
+require 5.8.0;
+
+use DateTime;
+use CronFns;
+use FixMyStreet::App;
+
+my ($verbose, $nomail) = CronFns::options();
+
+# Only run on working days
+my $now = DateTime->now();
+exit if FixMyStreet::Cobrand::Zurich::is_public_holiday($now) or FixMyStreet::Cobrand::Zurich::is_weekend($now);
+
+my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('zurich')->new();
+my %bodies = map { $_->id => $_ } FixMyStreet::App->model("DB::Body")->all;
+
+loop_through( 'alert-moderation-overdue.txt', 0, 1, [ 'unconfirmed', 'confirmed' ] );
+loop_through( 'alert-overdue.txt', 1, 5, 'in progress' );
+
+sub loop_through {
+ my ( $template, $include_parent, $days, $states ) = @_;
+
+ my $reports = FixMyStreet::App->model("DB::Problem")->search( {
+ state => $states,
+ whensent => { '<', FixMyStreet::Cobrand::Zurich::sub_days( $now, $days ) },
+ bodies_str => { '!=', undef },
+ } );
+
+ my %to_send = ();
+ while (my $row = $reports->next) {
+ $to_send{$row->bodies_str} .= '* ' . $row->id . ": '" . $row->title . "'\n\n";
+ }
+
+ my $template_path = FixMyStreet->path_to( "templates", "email", "zurich", $template )->stringify;
+ $template = Utils::read_file( $template_path );
+
+ foreach my $body_id (keys %to_send) {
+ send_alert( $template, $body_id, $to_send{$body_id}, $include_parent );
+ }
+}
+
+sub send_alert {
+ my ( $template, $body_id, $data, $include_parent ) = @_;
+
+ my $body = $bodies{$body_id};
+ my $body_email = $body->endpoint;
+
+ my $h = {
+ data => $data,
+ admin_url => $cobrand->admin_base_url,
+ };
+
+ my $env_to = [ $body_email ];
+ my $to = [ [ $body_email, $body->name ] ];
+ if ( $include_parent ) {
+ my $parent = $body->parent;
+ my $parent_email = $parent->endpoint;
+ push @$env_to, $parent_email;
+ push @$to, [ $parent_email, $parent->name ];
+ }
+
+ my $result = FixMyStreet::App->send_email_cron(
+ {
+ _template_ => $template,
+ _parameters_ => $h,
+ To => $to,
+ From => [ FixMyStreet->config('CONTACT_EMAIL'), FixMyStreet->config('CONTACT_NAME') ],
+ },
+ FixMyStreet->config('CONTACT_EMAIL'),
+ $env_to,
+ $nomail
+ );
+}
+
diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm
index d8a92f8cc..774aad3fa 100644
--- a/perllib/FixMyStreet/Cobrand/Zurich.pm
+++ b/perllib/FixMyStreet/Cobrand/Zurich.pm
@@ -55,13 +55,33 @@ my %public_holidays = map { $_ => 1 } (
'2014-08-01', '2014-09-15', '2014-12-25', '2014-12-26',
);
+sub is_public_holiday {
+ my $dt = shift;
+ return $public_holidays{$dt->ymd};
+}
+
+sub is_weekend {
+ my $dt = shift;
+ return $dt->dow > 5;
+}
+
sub add_days {
my ( $dt, $days ) = @_;
$dt = $dt->clone;
while ( $days > 0 ) {
$dt->add ( days => 1 );
- next if $public_holidays{$dt->ymd};
- next if $dt->dow > 5;
+ next if is_public_holiday($dt) or is_weekend($dt);
+ $days--;
+ }
+ return $dt;
+}
+
+sub sub_days {
+ my ( $dt, $days ) = @_;
+ $dt = $dt->clone;
+ while ( $days > 0 ) {
+ $dt->subtract ( days => 1 );
+ next if is_public_holiday($dt) or is_weekend($dt);
$days--;
}
return $dt;
diff --git a/templates/email/zurich/alert-moderation-overdue.txt b/templates/email/zurich/alert-moderation-overdue.txt
index cf3569bc5..c3aab66d2 100644
--- a/templates/email/zurich/alert-moderation-overdue.txt
+++ b/templates/email/zurich/alert-moderation-overdue.txt
@@ -1,6 +1,7 @@
Subject: eskalierte Meldungen auf Fix my Zurich
Die folgenden Meldungen auf Fix my Zurich sind älter als einen Tag und müssen dringend bearbeitet werden:
+
<?=$values['data']?>
Um diese Meldungen zu moderieren, klicken Sie auf folgende URL: