aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/send-comments56
-rw-r--r--perllib/FixMyStreet/Cobrand/BathNES.pm6
-rw-r--r--templates/email/default/alert-update.html2
-rw-r--r--templates/email/default/alert-update.txt2
4 files changed, 62 insertions, 4 deletions
diff --git a/bin/send-comments b/bin/send-comments
index 4293417f5..333bc2a00 100755
--- a/bin/send-comments
+++ b/bin/send-comments
@@ -5,13 +5,10 @@
# In Open311 parlance these are 'service request updates' and are sent using
# mySociety's proposed extension to the Open311 Georeport v2 spec:
# https://github.com/mysociety/fixmystreet/wiki/Open311-FMS---Proposed-differences-to-Open311
-#
-# Copyright (c) 2011 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 v5.14;
BEGIN {
use File::Basename qw(dirname);
@@ -26,6 +23,8 @@ use DateTime;
use FixMyStreet;
use FixMyStreet::Cobrand;
use FixMyStreet::DB;
+use FixMyStreet::Email;
+use FixMyStreet::Map;
use Open311;
# send_method config values found in by-area config data, for selecting to appropriate method
@@ -35,6 +34,7 @@ use constant SEND_METHOD_OPEN311 => 'Open311';
use constant COUNCIL_ID_OXFORDSHIRE => 2237;
use constant COUNCIL_ID_BROMLEY => 2482;
use constant COUNCIL_ID_LEWISHAM => 2492;
+use constant COUNCIL_ID_BANES => 2551;
# Set up site, language etc.
my ($verbose, $nomail) = CronFns::options();
@@ -144,6 +144,7 @@ while ( my $body = $bodies->next ) {
my $id = $o->post_service_request_update( $comment );
if ( $id ) {
+ send_comment_email($comment, $cobrand) if $body->areas->{+COUNCIL_ID_BANES};
$comment->update( {
external_id => $id,
whensent => \'current_timestamp',
@@ -170,3 +171,50 @@ sub retry_timeout {
return 0;
}
+
+=head2 send_comment_email
+
+Some cobrands (e.g. BANES) want to receive an email for every update that's sent
+via Open311. This function is called after each update is sent, and sends the
+alert-update.txt templated email to the cobrand's update_email (or
+contact_email if update_email isn't defined.)
+
+=cut
+sub send_comment_email {
+ my ($comment, $cobrand) = @_;
+
+ my $handler = $cobrand->call_hook(get_body_handler_for_problem => $comment->problem) or return;
+
+ # Set up map/language so things don't error
+ FixMyStreet::Map::set_map_class($handler->map_type);
+ $handler->set_lang_and_domain( $comment->lang, 1, FixMyStreet->path_to('locale')->stringify );
+ my $to = $cobrand->call_hook('update_email') || $cobrand->contact_email;
+
+ # Construct the data the alert-update email template needs
+ # (bit annoying that we can't just put $comment in data!)
+ my %data = (
+ cobrand => $handler,
+ hide_unsubscribe => 1,
+ data => [ {
+ item_photo => $comment->photo,
+ item_text => $comment->text,
+ item_name => $comment->name,
+ item_anonymous => $comment->anonymous,
+ confirmed => $comment->confirmed,
+ get_first_image_fp => sub { $comment->get_first_image_fp },
+ } ],
+ report => $comment->problem,
+ problem_url => $handler->base_url_for_report($comment->problem) . $comment->problem->url,
+ );
+
+ FixMyStreet::Email::send_cron(
+ FixMyStreet::DB->schema,
+ "alert-update.txt",
+ \%data,
+ { To => $to },
+ undef,
+ 0,
+ $handler,
+ $comment->lang,
+ );
+}
diff --git a/perllib/FixMyStreet/Cobrand/BathNES.pm b/perllib/FixMyStreet/Cobrand/BathNES.pm
index 53d3b977e..877475fee 100644
--- a/perllib/FixMyStreet/Cobrand/BathNES.pm
+++ b/perllib/FixMyStreet/Cobrand/BathNES.pm
@@ -18,6 +18,12 @@ sub contact_email {
my $self = shift;
return join( '@', 'fixmystreet', 'bathnes.gov.uk' );
}
+
+sub update_email {
+ my $self = shift;
+ return join( '@', 'highways', 'bathnes.gov.uk' );
+}
+
sub map_type { 'BathNES' }
sub example_places {
diff --git a/templates/email/default/alert-update.html b/templates/email/default/alert-update.html
index c1a7562cd..24d1b9834 100644
--- a/templates/email/default/alert-update.html
+++ b/templates/email/default/alert-update.html
@@ -14,7 +14,9 @@ INCLUDE '_email_top.html';
[% start_padded_box %]
<h1 style="[% h1_style %]">New updates on <a href="[% problem_url %]">[% title %]</a></h1>
[%~ INCLUDE '_email_comment_list.html' %]
+ [% UNLESS hide_unsubscribe %]
<p style="[% p_style %]"><a href="[% unsubscribe_url %]">Unsubscribe from alerts about this report</a></p>
+ [% END %]
[% end_padded_box %]
</th>
[% WRAPPER '_email_sidebar.html' object = report %]
diff --git a/templates/email/default/alert-update.txt b/templates/email/default/alert-update.txt
index 2883fee5e..cfeba2e36 100644
--- a/templates/email/default/alert-update.txt
+++ b/templates/email/default/alert-update.txt
@@ -19,6 +19,7 @@ please do not reply to it.
[% signature %]
+[% IF NOT hide_unsubscribe %]
Unsubscribe?
We currently email you whenever someone leaves an update on the
@@ -26,3 +27,4 @@ We currently email you whenever someone leaves an update on the
If you no longer wish to receive an email whenever this report is updated,
please follow this link: [% unsubscribe_url %]
+[% END %]