aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
Diffstat (limited to 'perllib')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm27
-rw-r--r--perllib/FixMyStreet/App/Controller/Alert.pm3
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm3
-rw-r--r--perllib/FixMyStreet/App/Controller/Dashboard.pm152
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm30
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm34
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm37
-rw-r--r--perllib/FixMyStreet/App/Controller/Tokens.pm1
-rw-r--r--perllib/FixMyStreet/Cobrand.pm18
-rw-r--r--perllib/FixMyStreet/Cobrand/Bromley.pm77
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm11
-rw-r--r--perllib/FixMyStreet/Cobrand/FixMyStreet.pm41
-rw-r--r--perllib/FixMyStreet/Cobrand/UKCouncils.pm31
-rw-r--r--perllib/FixMyStreet/DB/Result/Comment.pm37
-rw-r--r--perllib/FixMyStreet/DB/Result/Open311conf.pm21
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm13
-rw-r--r--perllib/FixMyStreet/DB/Result/User.pm30
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm202
-rw-r--r--perllib/FixMyStreet/Geocode/Bing.pm12
-rw-r--r--perllib/FixMyStreet/Map/Bromley.pm22
-rw-r--r--perllib/FixMyStreet/Map/FMS.pm21
-rw-r--r--perllib/FixMyStreet/Map/OSM.pm10
-rw-r--r--perllib/FixMyStreet/SendReport.pm44
-rw-r--r--perllib/FixMyStreet/SendReport/Barnet.pm216
-rw-r--r--perllib/FixMyStreet/SendReport/EastHants.pm62
-rw-r--r--perllib/FixMyStreet/SendReport/Email.pm111
-rw-r--r--perllib/FixMyStreet/SendReport/EmptyHomes.pm51
-rw-r--r--perllib/FixMyStreet/SendReport/London.pm113
-rw-r--r--perllib/FixMyStreet/SendReport/Open311.pm120
-rw-r--r--perllib/Open311.pm237
-rw-r--r--perllib/Open311/GetServiceRequestUpdates.pm136
-rw-r--r--perllib/Open311/PopulateServiceList.pm37
32 files changed, 1877 insertions, 83 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 198acade6..998cb83a8 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -8,6 +8,8 @@ use POSIX qw(strftime strcoll);
use Digest::MD5 qw(md5_hex);
use mySociety::EmailUtil qw(is_valid_email);
+use FixMyStreet::SendReport;
+
=head1 NAME
FixMyStreet::App::Controller::Admin- Catalyst Controller
@@ -338,7 +340,7 @@ sub update_contacts : Private {
} elsif ( $posted eq 'open311' ) {
$c->forward('check_token');
- my %params = map { $_ => $c->req->param($_) } qw/open311_id endpoint jurisdiction api_key area_id/;
+ my %params = map { $_ => $c->req->param($_) || '' } qw/open311_id endpoint jurisdiction api_key area_id send_method send_comments suppress_alerts comment_user_id/;
if ( $params{open311_id} ) {
my $conf = $c->model('DB::Open311Conf')->find( { id => $params{open311_id} } );
@@ -346,6 +348,10 @@ sub update_contacts : Private {
$conf->endpoint( $params{endpoint} );
$conf->jurisdiction( $params{jurisdiction} );
$conf->api_key( $params{api_key} );
+ $conf->send_method( $params{send_method} );
+ $conf->send_comments( $params{send_comments} || 0);
+ $conf->suppress_alerts( $params{suppress_alerts} || 0);
+ $conf->comment_user_id( $params{comment_user_id} || undef );
$conf->update();
@@ -356,6 +362,10 @@ sub update_contacts : Private {
$conf->endpoint( $params{endpoint} );
$conf->jurisdiction( $params{jurisdiction} );
$conf->api_key( $params{api_key} );
+ $conf->send_method( $params{send_method} );
+ $conf->send_comments( $params{send_comments} || 0);
+ $conf->suppress_alerts( $params{suppress_alerts} || 0);
+ $conf->comment_user_id( $params{comment_user_id} || undef );
$conf->insert();
@@ -378,6 +388,9 @@ sub display_contacts : Private {
$c->stash->{contacts} = $contacts;
+ my @methods = map { $_ =~ s/FixMyStreet::SendReport:://; $_ } keys %{ FixMyStreet::SendReport->get_senders };
+ $c->stash->{send_methods} = \@methods;
+
my $open311 = $c->model('DB::Open311Conf')->search(
{ area_id => $area_id }
);
@@ -492,7 +505,7 @@ sub search_reports : Path('search_reports') {
'me.id' => $search_n,
'user.email' => { ilike => $like_search },
'me.name' => { ilike => $like_search },
- title => { ilike => $like_search },
+ 'me.title' => { ilike => $like_search },
detail => { ilike => $like_search },
council => { like => $like_search },
cobrand_data => { like => $like_search },
@@ -571,8 +584,7 @@ sub report_edit : Path('report_edit') : Args(1) {
}
)->first;
- $c->detach( '/page_error_404_not_found',
- [ _('The requested URL was not found on this server.') ] )
+ $c->detach( '/page_error_404_not_found' )
unless $problem;
$c->stash->{problem} = $problem;
@@ -734,8 +746,7 @@ sub update_edit : Path('update_edit') : Args(1) {
}
)->first;
- $c->detach( '/page_error_404_not_found',
- [ _('The requested URL was not found on this server.') ] )
+ $c->detach( '/page_error_404_not_found' )
unless $update;
$c->forward('get_token');
@@ -1068,7 +1079,7 @@ sub check_token : Private {
my ( $self, $c ) = @_;
if ( !$c->req->param('token') || $c->req->param('token' ) ne $c->stash->{token} ) {
- $c->detach( '/page_error_404_not_found', [ _('The requested URL was not found on this server.') ] );
+ $c->detach( '/page_error_404_not_found' );
}
return 1;
@@ -1238,7 +1249,7 @@ sub check_page_allowed : Private {
$page ||= 'summary';
if ( !grep { $_ eq $page } keys %{ $c->stash->{allowed_pages} } ) {
- $c->detach( '/page_error_404_not_found', [ _('The requested URL was not found on this server.') ] );
+ $c->detach( '/page_error_404_not_found' );
}
return 1;
diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm
index 2698c6ac0..c127b7460 100644
--- a/perllib/FixMyStreet/App/Controller/Alert.pm
+++ b/perllib/FixMyStreet/App/Controller/Alert.pm
@@ -470,6 +470,7 @@ sub add_recent_photos : Private {
{
$c->stash->{photos} = $c->cobrand->recent_photos(
+ 'alert',
$num_photos,
$c->stash->{latitude},
$c->stash->{longitude},
@@ -477,7 +478,7 @@ sub add_recent_photos : Private {
);
}
else {
- $c->stash->{photos} = $c->cobrand->recent_photos($num_photos);
+ $c->stash->{photos} = $c->cobrand->recent_photos('alert', $num_photos);
}
return 1;
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index e110cf8d7..6fbfad5dc 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -186,10 +186,11 @@ sub display_location : Private {
@pins = map {
# Here we might have a DB::Problem or a DB::Nearby, we always want the problem.
my $p = (ref $_ eq 'FixMyStreet::App::Model::DB::Nearby') ? $_->problem : $_;
+ my $colour = $c->cobrand->pin_colour( $p );
{
latitude => $p->latitude,
longitude => $p->longitude,
- colour => 'yellow', # $p->is_fixed ? 'green' : 'red',
+ colour => $colour,
id => $p->id,
title => $p->title,
}
diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm
new file mode 100644
index 000000000..0273e0eda
--- /dev/null
+++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm
@@ -0,0 +1,152 @@
+package FixMyStreet::App::Controller::Dashboard;
+use Moose;
+use namespace::autoclean;
+
+use DateTime;
+
+BEGIN { extends 'Catalyst::Controller'; }
+
+=head1 NAME
+
+FixMyStreet::App::Controller::Dashboard - Catalyst Controller
+
+=head1 DESCRIPTION
+
+Catalyst Controller.
+
+=head1 METHODS
+
+=cut
+
+=head2 check_page_allowed
+
+Checks if we can view this page, and if not redirect to 404.
+
+=cut
+
+sub check_page_allowed : Private {
+ my ( $self, $c ) = @_;
+
+ $c->detach( '/auth/redirect' ) unless $c->user_exists;
+
+ $c->detach( '/page_error_404_not_found' )
+ unless $c->user_exists && $c->user->from_council;
+
+ return $c->user->from_council;
+}
+
+=head2 index
+
+Show the dashboard table.
+
+=cut
+
+sub index : Path : Args(0) {
+ my ( $self, $c ) = @_;
+
+ my $council = $c->forward('check_page_allowed');
+
+ # Set up the data for the dropdowns
+
+ my $children = mySociety::MaPit::call('area/children', $council,
+ type => $mySociety::VotingArea::council_child_types,
+ );
+ $c->stash->{children} = $children;
+
+ # XXX Hmm, this is probably the best way to go
+ $c->stash->{all_councils} = { $council => { id => $council } };
+ $c->forward( '/report/new/setup_categories_and_councils' );
+
+ # See if we've had anything from the dropdowns
+
+ $c->stash->{ward} = $c->req->param('ward');
+ $c->stash->{category} = $c->req->param('category');
+ $c->stash->{q_state} = $c->req->param('state');
+
+ my %where = (
+ council => $council, # XXX This will break in a two tier council. Restriction needs looking at...
+ 'problem.state' => [ FixMyStreet::DB::Result::Problem->visible_states() ],
+ );
+ $where{areas} = { 'like', '%,' . $c->stash->{ward} . ',%' }
+ if $c->stash->{ward};
+ $where{category} = $c->stash->{category}
+ if $c->stash->{category};
+ if ( $c->stash->{q_state} eq 'fixed' ) {
+ $where{'problem.state'} = [ FixMyStreet::DB::Result::Problem->fixed_states() ];
+ } elsif ( $c->stash->{q_state} ) {
+ $where{'problem.state'} = $c->stash->{q_state}
+ }
+
+ my %counts;
+ my $t = DateTime->today;
+
+ $counts{wtd} = $c->forward( 'updates_search', [ {
+ %where,
+ 'me.confirmed' => { '>=', $t->subtract( days => $t->dow - 1 )
+ } } ] );
+
+ $counts{week} = $c->forward( 'updates_search', [ {
+ %where,
+ 'me.confirmed' => { '>=', DateTime->now->subtract( weeks => 1 )
+ } } ] );
+
+ $counts{weeks} = $c->forward( 'updates_search', [ {
+ %where,
+ 'me.confirmed' => { '>=', DateTime->now->subtract( weeks => 4 )
+ } } ] );
+
+ $counts{ytd} = $c->forward( 'updates_search', [ {
+ %where,
+ 'me.confirmed' => { '>=', DateTime->today->set( day => 1, month => 1 )
+ } } ] );
+
+ $c->stash->{problems} = \%counts;
+}
+
+sub updates_search : Private {
+ my ( $self, $c, $params ) = @_;
+
+ my $comments = $c->model('DB::Comment')->search(
+ $params,
+ {
+ group_by => [ 'problem_state' ],
+ select => [ 'problem_state', { count => 'me.id' } ],
+ as => [ qw/state state_count/ ],
+ join => 'problem'
+ }
+ );
+
+ my %counts =
+ map { ($_->state||'-') => $_->get_column('state_count') } $comments->all;
+ %counts =
+ map { $_ => $counts{$_} || 0 }
+ ('confirmed', 'investigating', 'in progress', 'closed', 'fixed - council',
+ 'fixed - user', 'fixed', 'unconfirmed', 'hidden',
+ 'partial', 'planned');
+
+ $counts{fixed_user} = $c->model('DB::Comment')->search(
+ { %$params, mark_fixed => 1 }, { join => 'problem' }
+ )->count;
+
+ $params->{state} = $params->{'problem.state'};
+ delete $params->{'problem.state'};
+ $counts{total} = $c->cobrand->problems->search( $params )->count;
+
+ return \%counts;
+}
+
+=head1 AUTHOR
+
+Matthew Somerville
+
+=head1 LICENSE
+
+Copyright (c) 2012 UK Citizens Online Democracy. All rights reserved.
+Licensed under the Affero GPL.
+
+=cut
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index afe180c29..cca625bd5 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -153,6 +153,36 @@ sub generate_map_tags : Private {
return 1;
}
+sub delete :Local :Args(1) {
+ my ( $self, $c, $id ) = @_;
+
+ $c->forward( 'load_problem_or_display_error', [ $id ] );
+ my $p = $c->stash->{problem};
+
+ my $uri = $c->uri_for( '/report', $id );
+
+ return $c->res->redirect($uri) unless $c->user_exists;
+
+ my $council = $c->user->obj->from_council;
+ return $c->res->redirect($uri) unless $council;
+
+ my %councils = map { $_ => 1 } @{$p->councils};
+ return $c->res->redirect($uri) unless $councils{$council};
+
+ $p->state('hidden');
+ $p->lastupdate( \'ms_current_timestamp()' );
+ $p->update;
+
+ $c->model('DB::AdminLog')->create( {
+ admin_user => $c->user->email,
+ object_type => 'problem',
+ action => 'state_change',
+ object_id => $id,
+ } );
+
+ return $c->res->redirect($uri);
+}
+
__PACKAGE__->meta->make_immutable;
1;
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 6d22a0556..4dac4d30f 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -126,12 +126,16 @@ sub report_form_ajax : Path('ajax') : Args(0) {
my $category = $c->render_fragment( 'report/new/category.html');
my $councils_text = $c->render_fragment( 'report/new/councils_text.html');
my $has_open311 = keys %{ $c->stash->{category_extras} };
+ my $extra_name_info = $c->stash->{extra_name_info}
+ ? $c->render_fragment('report/new/extra_name.html')
+ : '';
my $body = JSON->new->utf8(1)->encode(
{
councils_text => $councils_text,
category => $category,
has_open311 => $has_open311,
+ extra_name_info => $extra_name_info,
}
);
@@ -396,6 +400,13 @@ sub initialize_report : Private {
}
+ if ( $c->req->param('first_name') && $c->req->param('last_name') ) {
+ $c->stash->{first_name} = $c->req->param('first_name');
+ $c->stash->{last_name} = $c->req->param('last_name');
+
+ $c->req->param( 'name', sprintf( '%s %s', $c->req->param('first_name'), $c->req->param('last_name') ) );
+ }
+
# Capture whether the map was used
$report->used_map( $c->req->param('skipped') ? 0 : 1 );
@@ -544,7 +555,7 @@ sub setup_categories_and_councils : Private {
);
$category_label = _('Property type:');
- } elsif ($first_council->{type} eq 'LBO') {
+ } elsif ($first_council->{id} != 2482 && $first_council->{type} eq 'LBO') {
$area_ids_to_list{ $first_council->{id} } = 1;
my @local_categories;
@@ -557,7 +568,7 @@ sub setup_categories_and_councils : Private {
_('-- Pick a category --'),
@local_categories
);
- $category_label = _('Category:');
+ $category_label = _('Category');
} else {
@@ -587,7 +598,7 @@ sub setup_categories_and_councils : Private {
if (@category_options) {
@category_options =
( _('-- Pick a category --'), @category_options, _('Other') );
- $category_label = _('Category:');
+ $category_label = _('Category');
}
}
@@ -597,6 +608,7 @@ sub setup_categories_and_councils : Private {
$c->stash->{category_options} = \@category_options;
$c->stash->{category_extras} = \%category_extras;
$c->stash->{category_extras_json} = encode_json \%category_extras;
+ $c->stash->{extra_name_info} = $first_council->{id} == 2482 ? 1 : 0;
my @missing_details_councils =
grep { !$area_ids_to_list{$_} } #
@@ -639,9 +651,10 @@ sub process_user : Private {
# The user is already signed in
if ( $c->user_exists ) {
my $user = $c->user->obj;
- my %params = map { $_ => scalar $c->req->param($_) } ( 'name', 'phone' );
+ my %params = map { $_ => scalar $c->req->param($_) } ( 'name', 'phone', 'fms_extra_title' );
$user->name( Utils::trim_text( $params{name} ) ) if $params{name};
$user->phone( Utils::trim_text( $params{phone} ) );
+ $user->title( Utils::trim_text( $params{fms_extra_title} ) );
$report->user( $user );
$report->name( $user->name );
return 1;
@@ -649,7 +662,7 @@ sub process_user : Private {
# Extract all the params to a hash to make them easier to work with
my %params = map { $_ => scalar $c->req->param($_) }
- ( 'email', 'name', 'phone', 'password_register' );
+ ( 'email', 'name', 'phone', 'password_register', 'fms_extra_title' );
# cleanup the email address
my $email = $params{email} ? lc $params{email} : '';
@@ -677,6 +690,7 @@ sub process_user : Private {
$report->user->phone( Utils::trim_text( $params{phone} ) );
$report->user->password( Utils::trim_text( $params{password_register} ) )
if $params{password_register};
+ $report->user->title( Utils::trim_text( $params{fms_extra_title} ) );
$report->name( Utils::trim_text( $params{name} ) );
return 1;
@@ -748,7 +762,7 @@ sub process_report : Private {
}
$report->council( $first_council->{id} );
- } elsif ( $first_council->{type} eq 'LBO') {
+ } elsif ( $first_council->{id} != 2482 && $first_council->{type} eq 'LBO') {
unless ( Utils::london_categories()->{ $report->category } ) {
$c->stash->{field_errors}->{category} = _('Please choose a category');
@@ -800,6 +814,8 @@ sub process_report : Private {
};
}
+ $c->cobrand->process_extras( $c, \@contacts, \@extra );
+
if ( @extra ) {
$c->stash->{report_meta} = \@extra;
$report->extra( \@extra );
@@ -855,6 +871,7 @@ sub process_photo_upload : Private {
# check that the photo is a jpeg
my $ct = $upload->type;
unless ( $ct eq 'image/jpeg' || $ct eq 'image/pjpeg' ) {
+ $c->log->info('Bad photo tried to upload, type=' . $ct);
$c->stash->{photo_error} = _('Please upload a JPEG image only');
return;
}
@@ -931,6 +948,8 @@ sub check_for_errors : Private {
%{ $c->stash->{report}->check_for_errors },
);
+ # FIXME: need to check for required bromley fields here
+
# if they're got the login details wrong when signing in then
# we don't care about the name field even though it's validated
# by the user object
@@ -972,10 +991,12 @@ sub save_user_and_report : Private {
name => $report->user->name,
phone => $report->user->phone,
password => $report->user->password,
+ title => $report->user->title,
};
$report->user->name( undef );
$report->user->phone( undef );
$report->user->password( '', 1 );
+ $report->user->title( undef );
$report->user->insert();
$c->log->info($report->user->id . ' created for this report');
}
@@ -991,6 +1012,7 @@ sub save_user_and_report : Private {
name => $report->user->name,
phone => $report->user->phone,
password => $report->user->password,
+ title => $report->user->title,
};
$report->user->discard_changes();
$c->log->info($report->user->id . ' exists, but is not logged in for this report');
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index 15444f556..7542fbe96 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -104,13 +104,18 @@ sub process_user : Private {
my $user = $c->user->obj;
my $name = scalar $c->req->param('name');
$user->name( Utils::trim_text( $name ) ) if $name;
+ my $title = scalar $c->req->param('fms_extra_title');
+ if ( $title ) {
+ $c->log->debug( 'user exists and title is ' . $title );
+ $user->title( Utils::trim_text( $title ) );
+ }
$update->user( $user );
return 1;
}
# Extract all the params to a hash to make them easier to work with
my %params = map { $_ => scalar $c->req->param($_) }
- ( 'rznvy', 'name', 'password_register' );
+ ( 'rznvy', 'name', 'password_register', 'fms_extra_title' );
# cleanup the email address
my $email = $params{rznvy} ? lc $params{rznvy} : '';
@@ -136,6 +141,8 @@ sub process_user : Private {
if $params{name};
$update->user->password( Utils::trim_text( $params{password_register} ) )
if $params{password_register};
+ $update->user->title( Utils::trim_text( $params{fms_extra_title} ) )
+ if $params{fms_extra_title};
return 1;
}
@@ -153,6 +160,15 @@ want to move adding these elsewhere
sub process_update : Private {
my ( $self, $c ) = @_;
+ if ( $c->req->param('first_name' ) && $c->req->param('last_name' ) ) {
+ my $first_name = $c->req->param('first_name');
+ my $last_name = $c->req->param('last_name');
+ $c->req->param('name', sprintf( '%s %s', $first_name, $last_name ) );
+
+ $c->stash->{first_name} = $first_name;
+ $c->stash->{last_name} = $last_name;
+ }
+
my %params =
map { $_ => scalar $c->req->param($_) } ( 'update', 'name', 'fixed', 'state', 'reopen' );
@@ -185,6 +201,24 @@ sub process_update : Private {
$update->problem_state( $params{state} );
}
+ if ( $c->req->param('fms_extra_title') ) {
+ my %extras = ();
+ $extras{title} = $c->req->param('fms_extra_title');
+ $extras{email_alerts_required} = $c->req->param('add_alert');
+ $update->extra( \%extras );
+
+ $c->stash->{fms_extra_title} = $c->req->param('fms_extra_title');
+ }
+
+ if ( $c->stash->{ first_name } && $c->stash->{ last_name } ) {
+ my $extra = $update->extra || {};
+ $extra->{first_name} = $c->stash->{ first_name };
+ $extra->{last_name} = $c->stash->{ last_name };
+ $update->extra( $extra );
+ }
+
+ $c->log->debug( 'name is ' . $c->req->param('name') );
+
$c->stash->{update} = $update;
$c->stash->{add_alert} = $c->req->param('add_alert');
@@ -268,6 +302,7 @@ sub save_update : Private {
}
elsif ( $c->user && $c->user->id == $update->user->id ) {
# Logged in and same user, so can confirm update straight away
+ $c->log->debug( 'user exists' );
$update->user->update;
$update->confirm;
} else {
diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm
index b974f94e6..1434838f2 100644
--- a/perllib/FixMyStreet/App/Controller/Tokens.pm
+++ b/perllib/FixMyStreet/App/Controller/Tokens.pm
@@ -71,6 +71,7 @@ sub confirm_problem : Path('/P') {
$problem->user->name( $data->{name} ) if $data->{name};
$problem->user->phone( $data->{phone} ) if $data->{phone};
$problem->user->password( $data->{password}, 1 ) if $data->{password};
+ $problem->user->title( $data->{title} ) if $data->{title};
$problem->user->update;
}
$c->authenticate( { email => $problem->user->email }, 'no_password' );
diff --git a/perllib/FixMyStreet/Cobrand.pm b/perllib/FixMyStreet/Cobrand.pm
index 647261e32..b88f6facc 100644
--- a/perllib/FixMyStreet/Cobrand.pm
+++ b/perllib/FixMyStreet/Cobrand.pm
@@ -109,4 +109,22 @@ sub get_class_for_moniker {
return 'FixMyStreet::Cobrand::Default';
}
+=head2 exists
+
+ FixMyStreet::Cobrand->exists( $moniker );
+
+Given a moniker, returns true if that cobrand is available to us for use
+
+=cut
+
+sub exists {
+ my ( $class, $moniker ) = @_;
+
+ foreach my $avail ( $class->available_cobrand_classes ) {
+ return 1 if $moniker eq $avail->{moniker};
+ }
+
+ return 0;
+}
+
1;
diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm
index 75174b638..90e71a36e 100644
--- a/perllib/FixMyStreet/Cobrand/Bromley.pm
+++ b/perllib/FixMyStreet/Cobrand/Bromley.pm
@@ -17,10 +17,16 @@ sub path_to_web_templates {
];
}
+sub site_title {
+ my ($self) = @_;
+ return "London Borough of Bromley - Report a problem in Bromley\x{2019}s streets or parks";
+}
+
sub disambiguate_location {
my $self = shift;
return {
%{ $self->SUPER::disambiguate_location() },
+ town => 'Bromley',
centre => '51.366836,0.040623',
span => '0.154963,0.24347',
bounds => [ '51.289355,-0.081112', '51.444318,0.162358' ],
@@ -31,5 +37,76 @@ sub example_places {
return ( 'BR1 3UH', 'Glebe Rd, Bromley' );
}
+sub on_map_default_max_pin_age {
+ return '1 month';
+}
+
+sub recent_photos {
+ my ( $self, $area, $num, $lat, $lon, $dist ) = @_;
+ $num = 3 if $num > 3 && $area eq 'alert';
+ return $self->problems->recent_photos( $num, $lat, $lon, $dist );
+}
+
+sub pin_colour {
+ my ( $self, $p ) = @_;
+ #return 'green' if time() - $p->confirmed_local->epoch < 7 * 24 * 60 * 60;
+ return 'yellow';
+}
+
+# Copy of function from FixMyStreet.pm cobrand as it's not inherited currently
+sub generate_problem_banner {
+ my ( $self, $problem ) = @_;
+
+ my $banner = {};
+ if ( $problem->is_open && time() - $problem->lastupdate_local->epoch > 8 * 7 * 24 * 60 * 60 )
+ {
+ $banner->{id} = 'unknown';
+ $banner->{text} = _('Unknown');
+ }
+ if ($problem->is_fixed) {
+ $banner->{id} = 'fixed';
+ $banner->{text} = _('Fixed');
+ }
+ if ($problem->is_closed) {
+ $banner->{id} = 'closed';
+ $banner->{text} = _('Closed');
+ }
+
+ if ( grep { $problem->state eq $_ } ( 'investigating', 'in progress', 'planned' ) ) {
+ $banner->{id} = 'progress';
+ $banner->{text} = _('In progress');
+ }
+
+ return $banner;
+}
+
+sub process_extras {
+ my $self = shift;
+ my $ctx = shift;
+ my $contacts = shift;
+ my $extra = shift;
+
+ for my $field (qw/ fms_extra_title first_name last_name /) {
+ my $value = $ctx->request->param($field);
+
+ if ( !$value ) {
+ $ctx->stash->{field_errors}->{$field} =
+ _('This information is required');
+ }
+ push @$extra,
+ {
+ name => $field,
+ description => uc($field),
+ value => $value || '',
+ };
+ }
+
+ if ( $ctx->request->param('fms_extra_title') ) {
+ $ctx->stash->{fms_extra_title} =
+ $ctx->request->param('fms_extra_title');
+ $ctx->stash->{extra_name_info} = 1;
+ }
+}
+
1;
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index c45c36b0b..eb37b062a 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -173,6 +173,7 @@ EASTING and NORTHING.
sub recent_photos {
my $self = shift;
+ my $area = shift;
return $self->problems->recent_photos(@_);
}
@@ -740,6 +741,8 @@ sub council_rss_alert_options {
( $ward->{id_name} = $ward->{short_name} ) =~ tr/+/_/;
}
}
+ $council->{name} = 'London Borough of Bromley'
+ if $council->{name} eq 'Bromley Council';
push @options,
{
@@ -916,9 +919,17 @@ Get stats to display on the council reports page
sub get_report_stats { return 0; }
+sub get_council_sender { return 'Email' };
+
sub example_places {
return [ 'B2 4QA', 'Tib St, Manchester' ];
}
+sub process_extras {}
+
+sub pin_colour {
+ 'yellow';
+}
+
1;
diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
index 97b4c3c8b..774723420 100644
--- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
+++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
@@ -6,6 +6,21 @@ sub restriction {
return {};
}
+sub get_council_sender {
+ my ( $self, $area_id, $area_info ) = @_;
+
+ my $send_method;
+
+ my $council_config = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $area_id } )->first;
+ $send_method = $council_config->send_method if $council_config;
+
+ return $send_method if $send_method;
+
+ return 'London' if $area_info->{type} eq 'LBO';
+
+ return 'Email';
+}
+
sub generate_problem_banner {
my ( $self, $problem ) = @_;
@@ -32,5 +47,31 @@ sub generate_problem_banner {
return $banner;
}
+sub process_extras {
+ my $self = shift;
+ my $ctx = shift;
+ my $contacts = shift;
+ my $extra = shift;
+
+ if ( $contacts->[0]->area_id == 2482 ) {
+ for my $field ( qw/ fms_extra_title / ) {
+ my $value = $ctx->request->param( $field );
+
+ if ( !$value ) {
+ $ctx->stash->{field_errors}->{ $field } = _('This information is required');
+ }
+ push @$extra, {
+ name => $field,
+ description => uc( $field),
+ value => $value || '',
+ };
+ }
+
+ if ( $ctx->request->param('fms_extra_title') ) {
+ $ctx->stash->{fms_extra_title} = $ctx->request->param('fms_extra_title');
+ $ctx->stash->{extra_name_info} = 1;
+ }
+ }
+}
1;
diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm
index b40f13d9d..8a6954418 100644
--- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm
+++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm
@@ -7,6 +7,10 @@ use warnings;
use Carp;
use URI::Escape;
+sub is_council {
+ 1;
+}
+
sub site_restriction {
my $self = shift;
return ( "and council='" . $self->council_id . "'", $self->council_url, { council => sprintf('%d', $self->council_id) } );
@@ -56,9 +60,16 @@ sub council_check {
return 1;
}
my $url = 'http://www.fixmystreet.com/';
- $url .= 'alert' if $context eq 'alert';
+ if ($context eq 'alert') {
+ $url .= 'alert';
+ } else {
+ $url .= 'around';
+ }
$url .= '?pc=' . URI::Escape::uri_escape( $self->{c}->req->param('pc') )
if $self->{c}->req->param('pc');
+ $url .= '?latitude=' . URI::Escape::uri_escape( $self->{c}->req->param('latitude') )
+ . '&amp;longitude=' . URI::Escape::uri_escape( $self->{c}->req->param('longitude') )
+ if $self->{c}->req->param('latitude');
my $error_msg = "That location is not covered by " . $self->council_name . ".
Please visit <a href=\"$url\">the main FixMyStreet site</a>.";
return ( 0, $error_msg );
@@ -70,10 +81,24 @@ sub all_councils_report {
}
sub recent_photos {
- my ( $self, $num, $lat, $lon, $dist ) = @_;
+ my ( $self, $area, $num, $lat, $lon, $dist ) = @_;
$num = 2 if $num == 3;
return $self->problems->recent_photos( $num, $lat, $lon, $dist );
}
-1;
+sub get_council_sender {
+ my ( $self, $area_id, $area_info ) = @_;
+
+ my $send_method;
+
+ my $council_config = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $area_id } )->first;
+ $send_method = $council_config->send_method if $council_config;
+ return $send_method if $send_method;
+
+ return 'London' if $area_info->{type} eq 'LBO';
+
+ return 'Email';
+}
+
+1;
diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm
index 5b45c63a8..91695d7d0 100644
--- a/perllib/FixMyStreet/DB/Result/Comment.pm
+++ b/perllib/FixMyStreet/DB/Result/Comment.pm
@@ -54,6 +54,18 @@ __PACKAGE__->add_columns(
{ data_type => "boolean", default_value => \"false", is_nullable => 0 },
"problem_state",
{ data_type => "text", is_nullable => 1 },
+ "external_id",
+ { data_type => "text", is_nullable => 1 },
+ "extra",
+ { data_type => "text", is_nullable => 1 },
+ "send_fail_count",
+ { data_type => "integer", default_value => 0, is_nullable => 0 },
+ "send_fail_reason",
+ { data_type => "text", is_nullable => 1 },
+ "send_fail_timestamp",
+ { data_type => "timestamp", is_nullable => 1 },
+ "whensent",
+ { data_type => "timestamp", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to(
@@ -70,13 +82,34 @@ __PACKAGE__->belongs_to(
);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:E+96vo/AB0zz1jAEPj/OKw
+# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-26 15:44:18
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nvkElEgSU6XcLd9znSqhmQ
+
+__PACKAGE__->filter_column(
+ extra => {
+ filter_from_storage => sub {
+ my $self = shift;
+ my $ser = shift;
+ return undef unless defined $ser;
+ my $h = new IO::String($ser);
+ return RABX::wire_rd($h);
+ },
+ filter_to_storage => sub {
+ my $self = shift;
+ my $data = shift;
+ my $ser = '';
+ my $h = new IO::String($ser);
+ RABX::wire_wr( $data, $h );
+ return $ser;
+ },
+ }
+);
use DateTime::TimeZone;
use Image::Size;
use Moose;
use namespace::clean -except => [ 'meta' ];
+use RABX;
with 'FixMyStreet::Roles::Abuser';
diff --git a/perllib/FixMyStreet/DB/Result/Open311conf.pm b/perllib/FixMyStreet/DB/Result/Open311conf.pm
index 742a12ebd..c95b0c8f2 100644
--- a/perllib/FixMyStreet/DB/Result/Open311conf.pm
+++ b/perllib/FixMyStreet/DB/Result/Open311conf.pm
@@ -28,13 +28,30 @@ __PACKAGE__->add_columns(
{ data_type => "text", is_nullable => 1 },
"send_method",
{ data_type => "text", is_nullable => 1 },
+ "send_comments",
+ { data_type => "boolean", default_value => \"false", is_nullable => 0 },
+ "comment_user_id",
+ { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
+ "suppress_alerts",
+ { data_type => "boolean", default_value => \"false", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->add_unique_constraint("open311conf_area_id_key", ["area_id"]);
+__PACKAGE__->belongs_to(
+ "comment_user",
+ "FixMyStreet::DB::Result::User",
+ { id => "comment_user_id" },
+ {
+ is_deferrable => 1,
+ join_type => "LEFT",
+ on_delete => "CASCADE",
+ on_update => "CASCADE",
+ },
+);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ClYnPB2gsKapnfHuco5d/w
+# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-05-11 13:30:31
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ByJbRe/Y/9Z1WHdG8kaIHg
# You can replace this text with custom code or comments, and it will be preserved on regeneration
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 192e539bd..b8aea8697 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -85,7 +85,7 @@ __PACKAGE__->add_columns(
"geocode",
{ data_type => "bytea", is_nullable => 1 },
"send_fail_count",
- { data_type => "integer", default_value => 0, is_nullable => 0 },
+ { data_type => "integer", is_nullable => 1 },
"send_fail_reason",
{ data_type => "text", is_nullable => 1 },
"send_fail_timestamp",
@@ -704,6 +704,17 @@ sub update_from_open311_service_request {
return 1;
}
+sub update_send_failed {
+ my $self = shift;
+ my $msg = shift;
+
+ $self->update( {
+ send_fail_count => $self->send_fail_count + 1,
+ send_fail_timestamp => \'ms_current_timestamp()',
+ send_fail_reason => $msg
+ } );
+}
+
# we need the inline_constructor bit as we don't inherit from Moose
__PACKAGE__->meta->make_immutable( inline_constructor => 0 );
diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm
index e13d88b88..7f43d1a52 100644
--- a/perllib/FixMyStreet/DB/Result/User.pm
+++ b/perllib/FixMyStreet/DB/Result/User.pm
@@ -30,6 +30,8 @@ __PACKAGE__->add_columns(
{ data_type => "integer", is_nullable => 1 },
"flagged",
{ data_type => "boolean", default_value => \"false", is_nullable => 0 },
+ "title",
+ { data_type => "text", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->add_unique_constraint("users_email_key", ["email"]);
@@ -46,6 +48,12 @@ __PACKAGE__->has_many(
{ cascade_copy => 0, cascade_delete => 0 },
);
__PACKAGE__->has_many(
+ "open311confs",
+ "FixMyStreet::DB::Result::Open311conf",
+ { "foreign.comment_user_id" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+__PACKAGE__->has_many(
"problems",
"FixMyStreet::DB::Result::Problem",
{ "foreign.user_id" => "self.id" },
@@ -53,8 +61,8 @@ __PACKAGE__->has_many(
);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:tM1LUGrqDeQnF4BDgnYXGQ
+# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-05-01 16:20:29
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:LKi8u5IYnHW1+Mez64nvGg
__PACKAGE__->add_columns(
"password" => {
@@ -172,4 +180,22 @@ sub belongs_to_council {
return 0;
}
+=head2 split_name
+
+ $name = $user->split_name;
+ printf( 'Welcome %s %s', $name->{first}, $name->{last} );
+
+Returns a hashref with first and last keys with first name(s) and last name.
+NB: the spliting algorithm is extremely basic.
+
+=cut
+
+sub split_name {
+ my $self = shift;
+
+ my ($first, $last) = $self->name =~ /^(\S*)(?: (.*))?$/;
+
+ return { first => $first || '', last => $last || '' };
+}
+
1;
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index 3557e77c7..30ad41704 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -4,6 +4,16 @@ use base 'DBIx::Class::ResultSet';
use strict;
use warnings;
+use CronFns;
+
+use Utils;
+use mySociety::Config;
+use mySociety::EmailUtil;
+use mySociety::MaPit;
+
+use FixMyStreet::App;
+use FixMyStreet::SendReport;
+
my $site_restriction;
my $site_key;
@@ -209,4 +219,196 @@ sub categories_summary {
return \%categories;
}
+sub send_reports {
+ # Set up site, language etc.
+ my ($verbose, $nomail) = CronFns::options();
+ my $base_url = mySociety::Config::get('BASE_URL');
+ my $site = CronFns::site($base_url);
+
+ my $unsent = FixMyStreet::App->model("DB::Problem")->search( {
+ state => [ 'confirmed', 'fixed' ],
+ whensent => undef,
+ council => { '!=', undef },
+ } );
+ my (%notgot, %note);
+
+ my $send_report = FixMyStreet::SendReport->new();
+ my $senders = $send_report->get_senders;
+
+ while (my $row = $unsent->next) {
+
+ my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($row->cobrand)->new();
+
+ # Cobranded and non-cobranded messages can share a database. In this case, the conf file
+ # should specify a vhost to send the reports for each cobrand, so that they don't get sent
+ # more than once if there are multiple vhosts running off the same database. The email_host
+ # call checks if this is the host that sends mail for this cobrand.
+ next unless $cobrand->email_host();
+ $cobrand->set_lang_and_domain($row->lang, 1);
+ if ( $row->is_from_abuser ) {
+ $row->update( { state => 'hidden' } );
+ next;
+ }
+
+ # Template variables for the email
+ my $email_base_url = $cobrand->base_url_for_emails($row->cobrand_data);
+ my %h = map { $_ => $row->$_ } qw/id title detail name category latitude longitude used_map/;
+ map { $h{$_} = $row->user->$_ } qw/email phone/;
+ $h{confirmed} = DateTime::Format::Pg->format_datetime( $row->confirmed->truncate (to => 'second' ) );
+
+ $h{query} = $row->postcode;
+ $h{url} = $email_base_url . '/report/' . $row->id;
+ $h{phone_line} = $h{phone} ? _('Phone:') . " $h{phone}\n\n" : '';
+ if ($row->photo) {
+ $h{has_photo} = _("This web page also contains a photo of the problem, provided by the user.") . "\n\n";
+ $h{image_url} = $email_base_url . '/photo?id=' . $row->id;
+ } else {
+ $h{has_photo} = '';
+ $h{image_url} = '';
+ }
+ $h{fuzzy} = $row->used_map ? _('To view a map of the precise location of this issue')
+ : _('The user could not locate the problem on a map, but to see the area around the location they entered');
+ $h{closest_address} = '';
+
+ # If we are in the UK include eastings and northings, and nearest stuff
+ $h{easting_northing} = '';
+ if ( $cobrand->country eq 'GB' ) {
+
+ ( $h{easting}, $h{northing} ) = Utils::convert_latlon_to_en( $h{latitude}, $h{longitude} );
+
+ # email templates don't have conditionals so we need to farmat this here
+ $h{easting_northing} #
+ = "Easting: $h{easting}\n\n" #
+ . "Northing: $h{northing}\n\n";
+
+ }
+
+ if ( $row->used_map ) {
+ $h{closest_address} = $cobrand->find_closest( $h{latitude}, $h{longitude}, $row );
+ }
+
+ my %reporters = ();
+ my (@to, @recips, $template, $areas_info, $sender_count );
+ if ($site eq 'emptyhomes') {
+
+ my $council = $row->council;
+ $areas_info = mySociety::MaPit::call('areas', $council);
+ my $name = $areas_info->{$council}->{name};
+ my $sender = "FixMyStreet::SendReport::EmptyHomes";
+ $reporters{ $sender } = $sender->new() unless $reporters{$sender};
+ $reporters{ $sender }->add_council( $council, $name );
+ $template = Utils::read_file("$FindBin::Bin/../templates/email/emptyhomes/" . $row->lang . "/submit.txt");
+
+ } else {
+
+ # XXX Needs locks!
+ my @all_councils = split /,|\|/, $row->council;
+ my ($councils, $missing) = $row->council =~ /^([\d,]+)(?:\|([\d,]+))?/;
+ my @councils = split(/,/, $councils);
+ $areas_info = mySociety::MaPit::call('areas', \@all_councils);
+ my @dear;
+
+ foreach my $council (@councils) {
+ my $name = $areas_info->{$council}->{name};
+
+ my $sender = $cobrand->get_council_sender( $council, $areas_info->{$council} );
+ $sender = "FixMyStreet::SendReport::$sender";
+
+ if ( ! exists $senders->{ $sender } ) {
+ warn "No such sender [ $sender ] for council $name ( $council )";
+ next;
+ }
+ $reporters{ $sender } ||= $sender->new();
+
+ unless ( $reporters{ $sender }->should_skip( $row ) ) {
+ push @dear, $name;
+ $reporters{ $sender }->add_council( $council, $name );
+ }
+ }
+
+ $template = 'submit.txt';
+ $template = 'submit-brent.txt' if $row->council eq 2488 || $row->council eq 2237;
+ my $template_path = FixMyStreet->path_to( "templates", "email", $cobrand->moniker, $template )->stringify;
+ $template_path = FixMyStreet->path_to( "templates", "email", "default", $template )->stringify
+ unless -e $template_path;
+ $template = Utils::read_file( $template_path );
+
+ if ($h{category} eq _('Other')) {
+ $h{category_footer} = _('this type of local problem');
+ $h{category_line} = '';
+ } else {
+ $h{category_footer} = "'" . $h{category} . "'";
+ $h{category_line} = sprintf(_("Category: %s"), $h{category}) . "\n\n";
+ }
+
+ $h{councils_name} = join(_(' and '), @dear);
+ if ($h{category} eq _('Other')) {
+ $h{multiple} = @dear>1 ? "[ " . _("This email has been sent to both councils covering the location of the problem, as the user did not categorise it; please ignore it if you're not the correct council to deal with the issue, or let us know what category of problem this is so we can add it to our system.") . " ]\n\n"
+ : '';
+ } else {
+ $h{multiple} = @dear>1 ? "[ " . _("This email has been sent to several councils covering the location of the problem, as the category selected is provided for all of them; please ignore it if you're not the correct council to deal with the issue.") . " ]\n\n"
+ : '';
+ }
+ $h{missing} = '';
+ if ($missing) {
+ my $name = $areas_info->{$missing}->{name};
+ $h{missing} = '[ '
+ . sprintf(_('We realise this problem might be the responsibility of %s; however, we don\'t currently have any contact details for them. If you know of an appropriate contact address, please do get in touch.'), $name)
+ . " ]\n\n";
+ }
+
+ $sender_count = scalar @dear;
+ }
+
+ unless ( keys %reporters ) {
+ die 'Report not going anywhere for ID ' . $row->id . '!';
+ }
+
+ next unless $sender_count;
+
+ if (mySociety::Config::get('STAGING_SITE')) {
+ # on a staging server send emails to ourselves rather than the councils
+ my @testing_councils = split( '\|', mySociety::Config::get('TESTING_COUNCILS') );
+ unless ( grep { $row->council eq $_ } @testing_councils ) {
+ %reporters = (
+ 'FixMyStreet::SendReport::Email' => $reporters{ 'FixMyStreet::SendReport::Email' } || FixMyStreet::SendReport::Email->new()
+ );
+ }
+ }
+
+ # Multiply results together, so one success counts as a success.
+ my $result = -1;
+
+ for my $sender ( keys %reporters ) {
+ $result *= $reporters{ $sender }->send(
+ $row, \%h, \@to, $template, \@recips, $nomail, $areas_info
+ );
+ }
+
+ if ($result == mySociety::EmailUtil::EMAIL_SUCCESS) {
+ $row->update( {
+ whensent => \'ms_current_timestamp()',
+ lastupdate => \'ms_current_timestamp()',
+ } );
+ } else {
+ my @errors;
+ for my $sender ( keys %reporters ) {
+ unless ( $reporters{ $sender }->success ) {
+ push @errors, $reporters{ $sender }->error;
+ }
+ }
+ $row->update_send_failed( join( '|', @errors ) );
+ }
+ }
+
+ if ($verbose) {
+ print "Council email addresses that need checking:\n" if keys %notgot;
+ foreach my $e (keys %notgot) {
+ foreach my $c (keys %{$notgot{$e}}) {
+ print $notgot{$e}{$c} . " problem, to $e category $c (" . $note{$e}{$c}. ")\n";
+ }
+ }
+ }
+}
+
1;
diff --git a/perllib/FixMyStreet/Geocode/Bing.pm b/perllib/FixMyStreet/Geocode/Bing.pm
index a24f7c102..3bbb9dcdc 100644
--- a/perllib/FixMyStreet/Geocode/Bing.pm
+++ b/perllib/FixMyStreet/Geocode/Bing.pm
@@ -44,8 +44,6 @@ sub string {
if (!$js) {
return { error => _('Sorry, we could not parse that location. Please try again.') };
- } elsif ($js =~ /BT\d/ && $params->{bing_country} eq 'United Kingdom') {
- return { error => _("We do not currently cover Northern Ireland, I'm afraid.") };
}
$js = JSON->new->utf8->allow_nonref->decode($js);
@@ -54,11 +52,15 @@ sub string {
}
my $results = $js->{resourceSets}->[0]->{resources};
- my ( $error, @valid_locations, $latitude, $longitude );
+ my ( $error, @valid_locations, $latitude, $longitude, $ni );
foreach (@$results) {
my $address = $_->{name};
next unless $_->{address}->{countryRegion} eq $params->{bing_country};
+ if ($params->{bing_country} eq 'United Kingdom' && $_->{address}{adminDistrict} eq 'Northern Ireland') {
+ $ni = 1;
+ next;
+ }
# Getting duplicate, yet different, results from Bing sometimes
next if @valid_locations
@@ -80,6 +82,10 @@ sub string {
push (@valid_locations, $_);
}
+ if ($ni && !scalar @valid_locations) {
+ return { error => _("We do not currently cover Northern Ireland, I'm afraid.") };
+ }
+
return { latitude => $latitude, longitude => $longitude } if scalar @valid_locations == 1;
return { error => $error };
}
diff --git a/perllib/FixMyStreet/Map/Bromley.pm b/perllib/FixMyStreet/Map/Bromley.pm
new file mode 100644
index 000000000..836efed39
--- /dev/null
+++ b/perllib/FixMyStreet/Map/Bromley.pm
@@ -0,0 +1,22 @@
+#!/usr/bin/perl
+#
+# FixMyStreet:Map::Bromley
+# Bromley have slightly different tiles, with trees etc.
+#
+# Copyright (c) 2012 UK Citizens Online Democracy. All rights reserved.
+# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
+
+package FixMyStreet::Map::Bromley;
+use base 'FixMyStreet::Map::FMS';
+
+use strict;
+
+sub map_type {
+ return '"/tilma"';
+}
+
+sub map_tile_base {
+ "/tilma/%d/%d/%d.png";
+}
+
+1;
diff --git a/perllib/FixMyStreet/Map/FMS.pm b/perllib/FixMyStreet/Map/FMS.pm
index 24842c861..4d0af983b 100644
--- a/perllib/FixMyStreet/Map/FMS.pm
+++ b/perllib/FixMyStreet/Map/FMS.pm
@@ -37,23 +37,28 @@ sub get_quadkey {
return $key;
}
+sub map_tile_base {
+ "http://%stilma.mysociety.org/sv/%d/%d/%d.png";
+}
+
sub map_tiles {
my ($self, $x, $y, $z) = @_;
if ($z >= 16) {
+ my $tile_base = $self->map_tile_base;
return [
- "http://a.tilma.mysociety.org/sv/$z/" . ($x-1) . "/" . ($y-1) . ".png",
- "http://b.tilma.mysociety.org/sv/$z/$x/" . ($y-1) . ".png",
- "http://c.tilma.mysociety.org/sv/$z/" . ($x-1) . "/$y.png",
- "http://tilma.mysociety.org/sv/$z/$x/$y.png",
+ sprintf($tile_base, 'a.', $z, $x-1, $y-1),
+ sprintf($tile_base, 'b.', $z, $x, $y-1),
+ sprintf($tile_base, 'c.', $z, $x-1, $y),
+ sprintf($tile_base, '', $z, $x, $y),
];
} else {
my $url = "g=701";
$url .= "&productSet=mmOS" if $z > 10;
return [
- "http://ecn.t0.tiles.virtualearth.net/tiles/r" . get_quadkey($x-1, $y-1, $z) . ".png?$url",
- "http://ecn.t1.tiles.virtualearth.net/tiles/r" . get_quadkey($x, $y-1, $z) . ".png?$url",
- "http://ecn.t2.tiles.virtualearth.net/tiles/r" . get_quadkey($x-1, $y, $z) . ".png?$url",
- "http://ecn.t3.tiles.virtualearth.net/tiles/r" . get_quadkey($x, $y, $z) . ".png?$url",
+ "//ecn.t0.tiles.virtualearth.net/tiles/r" . get_quadkey($x-1, $y-1, $z) . ".png?$url",
+ "//ecn.t1.tiles.virtualearth.net/tiles/r" . get_quadkey($x, $y-1, $z) . ".png?$url",
+ "//ecn.t2.tiles.virtualearth.net/tiles/r" . get_quadkey($x-1, $y, $z) . ".png?$url",
+ "//ecn.t3.tiles.virtualearth.net/tiles/r" . get_quadkey($x, $y, $z) . ".png?$url",
];
}
}
diff --git a/perllib/FixMyStreet/Map/OSM.pm b/perllib/FixMyStreet/Map/OSM.pm
index 8ca5949d8..12c57a2ee 100644
--- a/perllib/FixMyStreet/Map/OSM.pm
+++ b/perllib/FixMyStreet/Map/OSM.pm
@@ -109,15 +109,9 @@ sub map_pins {
my @pins = map {
# Here we might have a DB::Problem or a DB::Nearby, we always want the problem.
my $p = (ref $_ eq 'FixMyStreet::App::Model::DB::Nearby') ? $_->problem : $_;
- #{
- # latitude => $p->latitude,
- # longitude => $p->longitude,
- # colour => $p->state eq 'fixed' ? 'green' : 'red',
- # id => $p->id,
- # title => $p->title,
- #}
+ my $colour = $c->cobrand->pin_colour( $p );
[ $p->latitude, $p->longitude,
- 'yellow', # $p->is_fixed ? 'green' : 'red',
+ $colour,
$p->id, $p->title
]
} @$around_map, @$nearby;
diff --git a/perllib/FixMyStreet/SendReport.pm b/perllib/FixMyStreet/SendReport.pm
new file mode 100644
index 000000000..426e8eefe
--- /dev/null
+++ b/perllib/FixMyStreet/SendReport.pm
@@ -0,0 +1,44 @@
+package FixMyStreet::SendReport;
+
+use Moose;
+
+use Module::Pluggable
+ sub_name => 'senders',
+ search_path => __PACKAGE__,
+ require => 1;
+
+has 'councils' => ( is => 'rw', isa => 'HashRef', default => sub { {} } );
+has 'to' => ( is => 'rw', isa => 'ArrayRef', default => sub { [] } );
+has 'success' => ( is => 'rw', isa => 'Bool', default => 0 );
+has 'error' => ( is => 'rw', isa => 'Str', default => '' );
+
+
+sub should_skip {
+ return 0;
+}
+
+sub get_senders {
+ my $self = shift;
+
+ my %senders = map { $_ => 1 } $self->senders;
+
+ return \%senders;
+}
+
+sub reset {
+ my $self = shift;
+
+ $self->councils( {} );
+ $self->to( [] );
+}
+
+sub add_council {
+ my $self = shift;
+ my $council = shift;
+ my $name = shift;
+
+ $self->councils->{ $council } = $name;
+}
+
+
+1;
diff --git a/perllib/FixMyStreet/SendReport/Barnet.pm b/perllib/FixMyStreet/SendReport/Barnet.pm
new file mode 100644
index 000000000..72c279282
--- /dev/null
+++ b/perllib/FixMyStreet/SendReport/Barnet.pm
@@ -0,0 +1,216 @@
+package FixMyStreet::SendReport::Barnet;
+
+use Moose;
+
+BEGIN { extends 'FixMyStreet::SendReport'; }
+
+use BarnetInterfaces::service::ZLBB_SERVICE_ORDER;
+use Utils;
+use mySociety::Config;
+use mySociety::Web qw(ent);
+
+# maximum number of webservice attempts to send before not trying any more (XXX may be better in config?)
+use constant SEND_FAIL_RETRIES_CUTOFF => 3;
+
+# specific council numbers
+use constant COUNCIL_ID_BARNET => 2489;
+
+use constant MAX_LINE_LENGTH => 132;
+
+sub should_skip {
+ my $self = shift;
+ my $problem = shift;
+
+ my $council_name = 'Barnet';
+ my $err_msg = "";
+
+ if ($problem->send_fail_count >= SEND_FAIL_RETRIES_CUTOFF) {
+ $council_name &&= " to $council_name";
+ $err_msg = "skipped: problem id=" . $problem->id . " send$council_name has failed "
+ . $problem->send_fail_count . " times, cutoff is " . SEND_FAIL_RETRIES_CUTOFF;
+
+ return 1;
+ }
+}
+
+# currently just blind copy of construct_easthants_message
+sub construct_message {
+ my %h = @_;
+ my $message = <<EOF;
+Subject: $h{title}
+
+Details: $h{detail}
+
+$h{fuzzy}, or to provide an update on the problem, please visit the following link:
+
+$h{url}
+
+$h{closest_address}
+EOF
+}
+
+
+sub send {
+ my ( $self, $problem, $h, $to, $template, $recips, $nomail ) = @_;
+
+ my %h = %$h;
+
+ $h{message} = construct_barnet_message(%h);
+
+ my $return = 1;
+ my $err_msg = "";
+
+ my $default_kbid = 14; # This is the default, "Street Scene"
+ my $kbid = sprintf( "%050d", Utils::barnet_categories()->{$h{category}} || $default_kbid);
+
+ my $geo_code = "$h{easting} $h{northing}";
+
+ my $interface = BarnetInterfaces::service::ZLBB_SERVICE_ORDER->new();
+
+ my ($nearest_postcode, $nearest_street);
+ for ($h{closest_address}) {
+ $nearest_postcode = sprintf("%-10s", $1) if /Nearest postcode [^:]+: ((\w{1,4}\s?\w+|\w+))/;
+ # use partial postcode or comma as delimiter, strip leading number (possible letter 221B) off too
+ # "99 Foo Street, London N11 1XX" becomes Foo Street
+ # "99 Foo Street N11 1XX" becomes Foo Street
+ $nearest_street = sprintf("%-30s", $1) if /Nearest road [^:]+: (?:\d+\w? )?(.*?)(\b[A-Z]+\d|,|$)/m;
+ }
+ my $postcode = $h{postcode} || $nearest_postcode; # use given postcode if available
+
+ # note: endpoint can be of form 'https://username:password@:url'
+ my $council_config = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => COUNCIL_ID_BARNET} )->first;
+ if ($council_config and $council_config->endpoint) {
+ $interface->set_proxy($council_config->endpoint);
+ # Barnet web service doesn't like namespaces in the elements so use a prefix
+ $interface->set_prefix('urn');
+ } else {
+ die "Barnet webservice FAIL: looks like you're missing some config data: no endpoint (URL) found for area_id=" . COUNCIL_ID_BARNET;
+ }
+
+ eval {
+ my $result = $interface->Z_CRM_SERVICE_ORDER_CREATE( {
+ ET_RETURN => { # ignored by server
+ item => {
+ TYPE => "", ID => "", NUMBER => "", MESSAGE => "", LOG_NO => "", LOG_MSG_NO => "",
+ MESSAGE_V1 => "", MESSAGE_V2 => "", MESSAGE_V3 => "", MESSAGE_V4 => "", PARAMETER => "",
+ ROW => "", FIELD => "", SYSTEM => "",
+ },
+ },
+ IT_PROBLEM_DESC => { # MyTypes::TABLE_OF_CRMT_SERVICE_REQUEST_TEXT
+ item => [ # MyTypes::CRMT_SERVICE_REQUEST_TEXT
+ map { { TEXT_LINE => $_ } } split_text_with_entities(ent(encode_utf8($h{message})), 132) # char132
+ ],
+ },
+ IV_CUST_EMAIL => truncate_string_with_entities(ent(encode_utf8($h{email})), 241), # char241
+ IV_CUST_NAME => truncate_string_with_entities(ent(encode_utf8($h{name})), 50), # char50
+ IV_KBID => $kbid, # char50
+ IV_PROBLEM_ID => $h{id}, # char35
+ IV_PROBLEM_LOC => { # MyTypes::BAPI_TTET_ADDRESS_COM
+ COUNTRY2 => 'GB', # char2
+ REGION => "", # char3
+ COUNTY => "", # char30
+ CITY => "", # char30
+ POSTALCODE => $postcode, # char10
+ STREET => $nearest_street, # char30
+ STREETNUMBER => "", # char5
+ GEOCODE => $geo_code, # char32
+ },
+ IV_PROBLEM_SUB => truncate_string_with_entities(ent(encode_utf8($h{title})), 40), # char40
+ },
+ );
+ if ($result) {
+ # currently not using this: get_EV_ORDER_GUID (maybe that's the customer number in the CRM)
+ if (my $barnet_id = $result->get_EV_ORDER_NO()) {
+ $problem->external_id( $barnet_id );
+ $problem->external_body( 'Barnet Borough Council' ); # better to use $problem->body()?
+ $problem->send_method_used('barnet');
+ $return = 0;
+ } else {
+ my @returned_items = split /<item[^>]*>/, $result->get_ET_RETURN;
+ my @messages = ();
+ foreach my $item (@returned_items) {
+ if ($item=~/<MESSAGE [^>]*>\s*(\S.*?)<\/MESSAGE>/) { # if there's a non-null MESSAGE in there, grab it
+ push @messages, $1; # best stab at extracting useful error message back from convoluted response
+ }
+ }
+ push @messages, "service returned no external id" unless @messages;
+ $err_msg = "Failed (problem id $h{id}): " . join(" \n ", @messages);
+ }
+ } else {
+ my %fault = (
+ 'code' => $result->get_faultcode(),
+ 'actor' => $result->get_faultactor(),
+ 'string' => $result->get_faultstring(),
+ 'detail' => $result->get_detail(), # possibly only contains debug info
+ );
+ $fault{$_}=~s/^\s*|\s*$//g foreach keys %fault;
+ $fault{actor}&&=" (actor: $fault{actor})";
+ $fault{'detail'} &&= "\n" . $fault{'detail'};
+ $err_msg = "Failed (problem id $h{id}): Fault $fault{code}$fault{actor}\n$fault{string}$fault{detail}";
+ }
+
+ };
+ print "$err_msg\n" if $err_msg;
+ if ($@) {
+ my $e = shift;
+ print "Caught an error: $@\n";
+ }
+ if ( $return ) {
+ $self->error( "Error sending to Barnet: $err_msg" );
+ }
+ $self->success( !$return );
+ return $return;
+}
+
+# for barnet webservice: max-length fields require truncate and split
+
+# truncate_string_with_entities
+# args: text to truncate
+# max number of chars
+# returns: string truncated
+# Note: must not partially truncate an entity (e.g., &amp;)
+sub truncate_string_with_entities {
+ my ($str, $max_len) = @_;
+ my $retVal = "";
+ foreach my $chunk (split /(\&(?:\#\d+|\w+);)/, $str) {
+ if ($chunk=~/^\&(\#\d+|\w+);$/){
+ my $next = $retVal.$chunk;
+ last if length $next > $max_len;
+ $retVal=$next
+ } else {
+ $retVal.=$chunk;
+ if (length $retVal > $max_len) {
+ $retVal = substr($retVal, 0, $max_len);
+ last
+ }
+ }
+ }
+ return $retVal
+}
+
+# split_text_with_entities into lines
+# args: text to be broken into lines
+# max length (option: uses constant MAX_LINE_LENGTH)
+# returns: array of lines
+# Must not to split an entity (e.g., &amp;)
+# Not worrying about hyphenating here, since a word is only ever split if
+# it's longer than the whole line, which is uncommon in genuine problem reports
+sub split_text_with_entities {
+ my ($text, $max_line_length) = @_;
+ $max_line_length ||= MAX_LINE_LENGTH;
+ my @lines;
+ foreach my $line (split "\n", $text) {
+ while (length $line > $max_line_length) {
+ if (! ($line =~ s/^(.{1,$max_line_length})\s// # break on a space
+ or $line =~ s/^(.{1,$max_line_length})(\&(\#\d+|\w+);)/$2/ # break before an entity
+ or $line =~ s/(.{$max_line_length})//)) { # break the word ruthlessly
+ $line =~ s/(.*)//; # otherwise gobble whole line (which is now shorter than max length)
+ }
+ push @lines, $1;
+ }
+ push @lines, $line;
+ }
+ return @lines;
+}
+
+1;
diff --git a/perllib/FixMyStreet/SendReport/EastHants.pm b/perllib/FixMyStreet/SendReport/EastHants.pm
new file mode 100644
index 000000000..681a9d4c4
--- /dev/null
+++ b/perllib/FixMyStreet/SendReport/EastHants.pm
@@ -0,0 +1,62 @@
+package FixMyStreet::SendReport::EastHants;
+
+use Moose;
+
+BEGIN { extends 'FixMyStreet::SendReport'; }
+
+# export just what we need as error if we use :try
+use Error qw(try otherwise);
+use Encode;
+use mySociety::Web qw(ent);
+use EastHantsWSDL;
+
+sub construct_message {
+ my %h = @_;
+ my $message = '';
+ $message .= "[ This report was also sent to the district council covering the location of the problem, as the user did not categorise it; please ignore if you're not the correct council to deal with the issue. ]\n\n"
+ if $h{multiple};
+ $message .= <<EOF;
+Subject: $h{title}
+
+Details: $h{detail}
+
+$h{fuzzy}, or to provide an update on the problem, please visit the following link:
+
+$h{url}
+
+$h{closest_address}
+EOF
+ return $message;
+}
+
+sub send {
+ return if mySociety::Config::get('STAGING_SITE');
+
+ my ( $self, $row, $h, $to, $template, $recips, $nomail ) = @_;
+
+ # FIXME: should not recreate this each time
+ my $eh_service;
+
+ $h->{category} = 'Customer Services' if $h->{category} eq 'Other';
+ $h->{message} = construct_message( %$h );
+ my $return = 1;
+ $eh_service ||= EastHantsWSDL->on_fault(sub { my($soap, $res) = @_; die ref $res ? $res->faultstring : $soap->transport->status, "\n"; });
+ try {
+ # ServiceName, RemoteCreatedBy, Salutation, FirstName, Name, Email, Telephone, HouseNoName, Street, Town, County, Country, Postcode, Comments, FurtherInfo, ImageURL
+ my $message = ent(encode_utf8($h->{message}));
+ my $name = ent(encode_utf8($h->{name}));
+ my $result = $eh_service->INPUTFEEDBACK(
+ $h->{category}, 'FixMyStreet', '', '', $name, $h->{email}, $h->{phone},
+ '', '', '', '', '', '', $message, 'Yes', $h->{image_url}
+ );
+ $return = 0 if $result eq 'Report received';
+ } otherwise {
+ my $e = shift;
+ print "Caught an error: $e\n";
+ $self->error( "Error sending to East Hants: $e" );
+ };
+ $self->success( !$return );
+ return $return;
+}
+
+1;
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm
new file mode 100644
index 000000000..239bee715
--- /dev/null
+++ b/perllib/FixMyStreet/SendReport/Email.pm
@@ -0,0 +1,111 @@
+package FixMyStreet::SendReport::Email;
+
+use Moose;
+
+BEGIN { extends 'FixMyStreet::SendReport'; }
+
+use mySociety::EmailUtil;
+
+sub build_recipient_list {
+ my $self = shift;
+ my $row = shift;
+ my %recips;
+
+ my $all_confirmed = 1;
+ foreach my $council ( keys %{ $self->councils } ) {
+ my $contact = FixMyStreet::App->model("DB::Contact")->find( {
+ deleted => 0,
+ area_id => $council,
+ category => $row->category
+ } );
+
+ my ($council_email, $confirmed, $note) = ( $contact->email, $contact->confirmed, $contact->note );
+
+ $council_email = essex_contact($row->latitude, $row->longitude) if $council == 2225;
+ $council_email = oxfordshire_contact($row->latitude, $row->longitude) if $council == 2237 && $council_email eq 'SPECIAL';
+
+ unless ($confirmed) {
+ $all_confirmed = 0;
+ #$note = 'Council ' . $row->council . ' deleted'
+ #unless $note;
+ $council_email = 'N/A' unless $council_email;
+ #$notgot{$council_email}{$row->category}++;
+ #$note{$council_email}{$row->category} = $note;
+ }
+
+ push @{ $self->to }, [ $council_email, $self->councils->{ $council } ];
+ $recips{$council_email} = 1;
+ }
+
+ return () unless $all_confirmed;
+ return keys %recips;
+}
+
+sub send {
+ my $self = shift;
+ my ( $row, $h, $to, $template, $recips, $nomail, $areas_info ) = @_;
+
+ my @recips;
+
+ @recips = $self->build_recipient_list( $row, $areas_info );
+
+ # on a staging server send emails to ourselves rather than the councils
+ if (mySociety::Config::get('STAGING_SITE')) {
+ @recips = ( mySociety::Config::get('CONTACT_EMAIL') );
+ }
+
+ return unless @recips;
+
+ my $result = FixMyStreet::App->send_email_cron(
+ {
+ _template_ => $template,
+ _parameters_ => $h,
+ To => $self->to,
+ From => [ $row->user->email, $row->name ],
+ },
+ mySociety::Config::get('CONTACT_EMAIL'),
+ \@recips,
+ $nomail
+ );
+
+ if ( $result == mySociety::EmailUtil::EMAIL_SUCCESS ) {
+ $self->success(1);
+ } else {
+ $self->error( 'Failed to send email' );
+ }
+
+ return $result;
+}
+
+# Essex has different contact addresses depending upon the district
+# Might be easier if we start storing in the db all areas covered by a point
+# Will do for now :)
+sub essex_contact {
+ my $district = _get_district_for_contact(@_);
+ my $email;
+ $email = 'eastarea' if $district == 2315 || $district == 2312;
+ $email = 'midarea' if $district == 2317 || $district == 2314 || $district == 2316;
+ $email = 'southarea' if $district == 2319 || $district == 2320 || $district == 2310;
+ $email = 'westarea' if $district == 2309 || $district == 2311 || $district == 2318 || $district == 2313;
+ die "Returned district $district which is not in Essex!" unless $email;
+ return "highways.$email\@essexcc.gov.uk";
+}
+
+# Oxfordshire has different contact addresses depending upon the district
+sub oxfordshire_contact {
+ my $district = _get_district_for_contact(@_);
+ my $email;
+ $email = 'northernarea' if $district == 2419 || $district == 2420 || $district == 2421;
+ $email = 'southernarea' if $district == 2417 || $district == 2418;
+ die "Returned district $district which is not in Oxfordshire!" unless $email;
+ return "$email\@oxfordshire.gov.uk";
+}
+
+sub _get_district_for_contact {
+ my ( $lat, $lon ) = @_;
+ my $district =
+ mySociety::MaPit::call( 'point', "4326/$lon,$lat", type => 'DIS' );
+ ($district) = keys %$district;
+ return $district;
+}
+1;
diff --git a/perllib/FixMyStreet/SendReport/EmptyHomes.pm b/perllib/FixMyStreet/SendReport/EmptyHomes.pm
new file mode 100644
index 000000000..9453b4ca5
--- /dev/null
+++ b/perllib/FixMyStreet/SendReport/EmptyHomes.pm
@@ -0,0 +1,51 @@
+package FixMyStreet::SendReport::EmptyHomes;
+
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'FixMyStreet::SendReport::Email'; }
+
+sub build_recipient_list {
+ my $self = shift;
+ my $row = shift;
+ my $areas_info = shift;
+ my %recips;
+
+ my $all_confirmed = 1;
+ foreach my $council ( keys %{ $self->councils } ) {
+ my $contact = FixMyStreet::App->model("DB::Contact")->find( {
+ deleted => 0,
+ area_id => $council,
+ category => 'Empty property',
+ } );
+
+ my ($council_email, $confirmed, $note) = ( $contact->email, $contact->confirmed, $contact->note );
+
+ $council_email = essex_contact($row->latitude, $row->longitude) if $council == 2225;
+ $council_email = oxfordshire_contact($row->latitude, $row->longitude) if $council == 2237 && $council_email eq 'SPECIAL';
+
+ unless ($confirmed) {
+ $all_confirmed = 0;
+ #$note = 'Council ' . $row->council . ' deleted'
+ #unless $note;
+ $council_email = 'N/A' unless $council_email;
+ #$notgot{$council_email}{$row->category}++;
+ #$note{$council_email}{$row->category} = $note;
+ }
+
+ push @{ $self->to }, [ $council_email, $self->councils->{ $council } ];
+ $recips{$council_email} = 1;
+
+ my $country = $areas_info->{$council}->{country};
+ if ($country eq 'W') {
+ $recips{ 'shelter@' . mySociety::Config::get('EMAIL_DOMAIN') } = 1;
+ } else {
+ $recips{ 'eha@' . mySociety::Config::get('EMAIL_DOMAIN') } = 1;
+ }
+ }
+
+ return () unless $all_confirmed;
+ return keys %recips;
+}
+
+1;
diff --git a/perllib/FixMyStreet/SendReport/London.pm b/perllib/FixMyStreet/SendReport/London.pm
new file mode 100644
index 000000000..58ecb2375
--- /dev/null
+++ b/perllib/FixMyStreet/SendReport/London.pm
@@ -0,0 +1,113 @@
+package FixMyStreet::SendReport::London;
+
+use Moose;
+
+BEGIN { extends 'FixMyStreet::SendReport'; }
+
+use Digest::MD5;
+use LWP::UserAgent;
+use LWP::Simple;
+
+use Utils;
+
+sub construct_message {
+ my %h = @_;
+ return <<EOF,
+A user of FixMyStreet has submitted the following report of a local
+problem that they believe might require your attention.
+
+Subject: $h{title}
+
+Details: $h{detail}
+
+$h{fuzzy}, or to provide an update on the problem, please visit the
+following link:
+
+$h{url}
+
+$h{closest_address}
+Yours,
+The FixMyStreet team
+EOF
+}
+
+sub send {
+ return if mySociety::Config::get('STAGING_SITE');
+ my ( $self, $row, $h, $to, $template, $recips, $nomail ) = @_;
+
+ $h->{message} = construct_message( %$h );
+ my $phone = $h->{phone};
+ my $mobile = '';
+ if ($phone && $phone =~ /^\s*07/) {
+ $mobile = $phone;
+ $phone = '';
+ }
+ my ($first, $last) = $h->{name} =~ /^(\S*)(?: (.*))?$/;
+ my %params = (
+ Key => mySociety::Config::get('LONDON_REPORTIT_KEY'),
+ Signature => Digest::MD5::md5_hex( $h->{confirmed} . mySociety::Config::get('LONDON_REPORTIT_SECRET') ),
+ Type => Utils::london_categories()->{$h->{category}},
+ RequestDate => $h->{confirmed},
+ RequestMethod => 'Web',
+ ExternalId => $h->{url},
+ 'Customer.Title' => '',
+ 'Customer.FirstName' => $first,
+ 'Customer.Surname' => $last,
+ 'Customer.Email' => $h->{email},
+ 'Customer.Phone' => $phone,
+ 'Customer.Mobile' => $mobile,
+ 'ProblemDescription' => $h->{message},
+ );
+ if ($h->{used_map}) {
+ $params{'Location.Latitude'} = $h->{latitude};
+ $params{'Location.Longitude'} = $h->{longitude};
+ } elsif (mySociety::PostcodeUtil::is_valid_postcode($h->{query})) {
+ # Didn't use map, and entered postcode, so use that.
+ $params{'Location.Postcode'} = $h->{query};
+ } else {
+ # Otherwise, lat/lon is all we have, even if it's wrong.
+ $params{'Location.Latitude'} = $h->{latitude};
+ $params{'Location.Longitude'} = $h->{longitude};
+ }
+ if ($h->{has_photo}) {
+ $params{'Document1.Name'} = 'Photograph';
+ $params{'Document1.MimeType'} = 'image/jpeg';
+ $params{'Document1.URL'} = $h->{image_url};
+ $params{'Document1.URLPublic'} = 'true';
+ }
+ my $browser = LWP::UserAgent->new;
+ my $response = $browser->post( mySociety::Config::get('LONDON_REPORTIT_URL'), \%params );
+ my $out = $response->content;
+ if ($response->code ne 200) {
+ print "Failed to post $h->{id} to London API, response was " . $response->code . " $out\n";
+ $self->error( "Failed to post $h->{id} to London API, response was " . $response->code . " $out" );
+ return 1;
+ }
+ my ($id) = $out =~ /<caseid>(.*?)<\/caseid>/;
+ my ($org) = $out =~ /<organisation>(.*?)<\/organisation>/;
+ my ($team) = $out =~ /<team>(.*?)<\/team>/;
+
+ $org = london_lookup($org);
+ $row->external_id( $id );
+ $row->external_body( $org );
+ $row->external_team( $team );
+ $self->success(1);
+ return 0;
+}
+
+sub london_lookup {
+ my $org = shift || '';
+ my $str = "Unknown ($org)";
+ open(FP, "$FindBin::Bin/../data/dft.csv");
+ while (<FP>) {
+ /^(.*?),(.*)/;
+ if ($org eq $1) {
+ $str = $2;
+ last;
+ }
+ }
+ close FP;
+ return $str;
+}
+
+1;
diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm
new file mode 100644
index 000000000..fe99e3043
--- /dev/null
+++ b/perllib/FixMyStreet/SendReport/Open311.pm
@@ -0,0 +1,120 @@
+package FixMyStreet::SendReport::Open311;
+
+use Moose;
+use namespace::autoclean;
+
+BEGIN { extends 'FixMyStreet::SendReport'; }
+
+use FixMyStreet::App;
+use mySociety::Config;
+use DateTime::Format::W3CDTF;
+use Open311;
+
+sub should_skip {
+ my $self = shift;
+ my $row = shift;
+
+ if ( $row->send_fail_count > 0 ) {
+ if ( bromley_retry_timeout($row) ) {
+ return 1;
+ }
+ }
+}
+
+sub send {
+ my $self = shift;
+ my ( $row, $h, $to, $template, $recips, $nomail ) = @_;
+
+ my $result = -1;
+
+ foreach my $council ( keys %{ $self->councils } ) {
+ my $conf = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $council, endpoint => { '!=', '' } } )->first;
+
+ my $always_send_latlong = 1;
+
+ my $basic_desc = 0;
+
+ # Extra bromley fields
+ if ( $row->council =~ /2482/ ) {
+
+ my $extra = $row->extra;
+ push @$extra, { name => 'northing', value => $h->{northing} };
+ push @$extra, { name => 'easting', value => $h->{easting} };
+ push @$extra, { name => 'report_url', value => $h->{url} };
+ push @$extra, { name => 'service_request_id_ext', value => $row->id };
+ push @$extra, { name => 'report_title', value => $row->title };
+ push @$extra, { name => 'public_anonymity_required', value => $row->anonymous ? 'TRUE' : 'FALSE' };
+ push @$extra, { name => 'email_alerts_requested', value => 'FALSE' }; # always false as can never request them
+ push @$extra, { name => 'requested_datetime', value => DateTime::Format::W3CDTF->format_datetime($row->confirmed_local->set_nanosecond(0)) };
+ push @$extra, { name => 'email', value => $row->user->email };
+ $row->extra( $extra );
+
+ $always_send_latlong = 0;
+
+ $basic_desc = 1;
+ }
+
+ # FIXME: we've already looked this up before
+ my $contact = FixMyStreet::App->model("DB::Contact")->find( {
+ deleted => 0,
+ area_id => $conf->area_id,
+ category => $row->category
+ } );
+
+ my $open311 = Open311->new(
+ jurisdiction => $conf->jurisdiction,
+ endpoint => $conf->endpoint,
+ api_key => $conf->api_key,
+ always_send_latlong => $always_send_latlong,
+ basic_description => $basic_desc,
+ );
+
+ # non standard west berks end points
+ if ( $row->council =~ /2619/ ) {
+ $open311->endpoints( { services => 'Services', requests => 'Requests' } );
+ }
+
+ # required to get round issues with CRM constraints
+ if ( $row->council =~ /2218/ ) {
+ $row->user->name( $row->user->id . ' ' . $row->user->name );
+ }
+
+ my $resp = $open311->send_service_request( $row, $h, $contact->email );
+
+ # make sure we don't save user changes from above
+ if ( $row->council =~ /2218/ || $row->council =~ /2482/ ) {
+ $row->discard_changes();
+ }
+
+ if ( $resp ) {
+ $row->external_id( $resp );
+ $result *= 0;
+ $self->success( 1 );
+ } else {
+ $result *= 1;
+ # temporary fix to resolve some issues with west berks
+ if ( $row->council =~ /2619/ ) {
+ $result *= 0;
+ }
+ }
+ }
+
+ $self->error( 'Failed to send over Open311' ) unless $self->success;
+
+ return $result;
+}
+
+sub bromley_retry_timeout {
+ my $row = shift;
+
+ my $tz = DateTime::TimeZone->new( name => 'local' );
+ my $now = DateTime->now( time_zone => $tz );
+ my $diff = $now - $row->send_fail_timestamp;
+ if ( $diff->in_units( 'minutes' ) < 30 ) {
+ return 1;
+ }
+
+ return 0;
+}
+
+1;
diff --git a/perllib/Open311.pm b/perllib/Open311.pm
index e26e3e4c6..b380409cf 100644
--- a/perllib/Open311.pm
+++ b/perllib/Open311.pm
@@ -5,6 +5,7 @@ use Moose;
use XML::Simple;
use LWP::Simple;
use LWP::UserAgent;
+use DateTime::Format::W3CDTF;
use HTTP::Request::Common qw(POST);
has jurisdiction => ( is => 'ro', isa => 'Str' );;
@@ -12,10 +13,22 @@ has api_key => ( is => 'ro', isa => 'Str' );
has endpoint => ( is => 'ro', isa => 'Str' );
has test_mode => ( is => 'ro', isa => 'Bool' );
has test_uri_used => ( is => 'rw', 'isa' => 'Str' );
+has test_req_used => ( is => 'rw' );
has test_get_returns => ( is => 'rw' );
-has endpoints => ( is => 'rw', default => sub { { services => 'services.xml', requests => 'requests.xml' } } );
+has endpoints => ( is => 'rw', default => sub { { services => 'services.xml', requests => 'requests.xml', service_request_updates => 'update.xml', update => 'update.xml' } } );
has debug => ( is => 'ro', isa => 'Bool', default => 0 );
has debug_details => ( is => 'rw', 'isa' => 'Str', default => '' );
+has success => ( is => 'rw', 'isa' => 'Bool', default => 0 );
+has error => ( is => 'rw', 'isa' => 'Str', default => '' );
+has always_send_latlong => ( is => 'ro', isa => 'Bool', default => 1 );
+has basic_description => ( is => 'ro', isa => 'Bool', default => 0 );
+
+before [
+ qw/get_service_list get_service_meta_info get_service_requests get_service_request_updates
+ send_service_request post_service_request_update/
+ ] => sub {
+ shift->debug_details('');
+ };
sub get_service_list {
my $self = shift;
@@ -39,22 +52,49 @@ sub send_service_request {
my $extra = shift;
my $service_code = shift;
- my $description = <<EOT;
-title: @{[$problem->title()]}
+ my $params = $self->_populate_service_request_params(
+ $problem, $extra, $service_code
+ );
-detail: @{[$problem->detail()]}
+ my $response = $self->_post( $self->endpoints->{requests}, $params );
-url: $extra->{url}
+ if ( $response ) {
+ my $obj = $self->_get_xml_object( $response );
-Submitted via FixMyStreet
-EOT
-;
+ if ( $obj ) {
+ if ( $obj->{ request }->{ service_request_id } ) {
+ return $obj->{ request }->{ service_request_id };
+ } else {
+ my $token = $obj->{ request }->{ token };
+ if ( $token ) {
+ return $self->get_service_request_id_from_token( $token );
+ }
+ }
+ }
+
+ warn sprintf( "Failed to submit problem %s over Open311, response\n: %s\n%s", $problem->id, $response, $self->debug_details );
+ return 0;
+ }
+}
+
+sub _populate_service_request_params {
+ my $self = shift;
+ my $problem = shift;
+ my $extra = shift;
+ my $service_code = shift;
+
+ my $description;
+ if ( $self->basic_description ) {
+ $description = $problem->detail;
+ } else {
+ $description = $self->_generate_service_request_description(
+ $problem, $extra
+ );
+ }
my ( $firstname, $lastname ) = ( $problem->user->name =~ /(\w+)\s+(.+)/ );
my $params = {
- lat => $problem->latitude,
- long => $problem->longitude,
email => $problem->user->email,
description => $description,
service_code => $service_code,
@@ -62,6 +102,13 @@ EOT
last_name => $lastname || '',
};
+ if ( $problem->used_map || $self->always_send_latlong ) {
+ $params->{lat} = $problem->latitude;
+ $params->{long} = $problem->longitude;
+ } else {
+ $params->{address} = $problem->postcode;
+ }
+
if ( $problem->user->phone ) {
$params->{ phone } = $problem->user->phone;
}
@@ -74,30 +121,37 @@ EOT
my $extras = $problem->extra;
for my $attr ( @$extras ) {
- my $name = sprintf( 'attribute[%s]', $attr->{name} );
+ my $attr_name = $attr->{name};
+ if ( $attr_name eq 'first_name' || $attr_name eq 'last_name' ) {
+ $params->{$attr_name} = $attr->{value} if $attr->{value};
+ next if $attr_name eq 'first_name';
+ }
+ $attr_name =~ s/fms_extra_//;
+ my $name = sprintf( 'attribute[%s]', $attr_name );
$params->{ $name } = $attr->{value};
}
}
- my $response = $self->_post( $self->endpoints->{requests}, $params );
+ return $params;
+}
- if ( $response ) {
- my $obj = $self->_get_xml_object( $response );
+sub _generate_service_request_description {
+ my $self = shift;
+ my $problem = shift;
+ my $extra = shift;
- if ( $obj ) {
- if ( $obj->{ request }->{ service_request_id } ) {
- return $obj->{ request }->{ service_request_id };
- } else {
- my $token = $obj->{ request }->{ token };
- if ( $token ) {
- return $self->get_service_request_id_from_token( $token );
- }
- }
- }
+ my $description = <<EOT;
+title: @{[$problem->title()]}
- warn sprintf( "Failed to submit problem %s over Open311, response\n: %s\n%s", $problem->id, $response, $self->debug_details );
- return 0;
- }
+detail: @{[$problem->detail()]}
+
+url: $extra->{url}
+
+Submitted via FixMyStreet
+EOT
+;
+
+ return $description;
}
sub get_service_requests {
@@ -129,6 +183,100 @@ sub get_service_request_id_from_token {
}
}
+sub get_service_request_updates {
+ my $self = shift;
+ my $start_date = shift;
+ my $end_date = shift;
+
+ my $params = {
+ api_key => $self->api_key,
+ jurisdiction => $self->jurisdiction,
+ };
+
+ if ( $start_date || $end_date ) {
+ return 0 unless $start_date && $end_date;
+
+ $params->{start_date} = $start_date;
+ $params->{end_date} = $end_date;
+ }
+
+ my $xml = $self->_get( $self->endpoints->{service_request_updates}, $params || undef );
+ my $service_requests = $self->_get_xml_object( $xml );
+ my $requests;
+ if ( ref $service_requests->{request_update } eq 'ARRAY' ) {
+ $requests = $service_requests->{request_update};
+ }
+ else {
+ $requests = [ $service_requests->{request_update} ];
+ }
+
+ return $requests;
+}
+
+sub post_service_request_update {
+ my $self = shift;
+ my $comment = shift;
+
+ my $params = $self->_populate_service_request_update_params( $comment );
+
+ my $response = $self->_post( $self->endpoints->{update}, $params );
+
+ if ( $response ) {
+ my $obj = $self->_get_xml_object( $response );
+
+ if ( $obj ) {
+ if ( $obj->{ request_update }->{ update_id } ) {
+ my $update_id = $obj->{request_update}->{update_id};
+
+ # if there's nothing in the update_id element we get a HASHREF back
+ unless ( ref $update_id ) {
+ return $obj->{ request_update }->{ update_id };
+ }
+ } else {
+ my $token = $obj->{ request_update }->{ token };
+ if ( $token ) {
+ return $self->get_service_request_id_from_token( $token );
+ }
+ }
+ }
+
+ warn sprintf( "Failed to submit comment %s over Open311, response - %s\n%s\n", $comment->id, $response, $self->debug_details );
+ return 0;
+ }
+}
+
+sub _populate_service_request_update_params {
+ my $self = shift;
+ my $comment = shift;
+
+ my $name = $comment->name || $comment->user->name;
+ my ( $firstname, $lastname ) = ( $name =~ /(\w+)\s+(.+)/ );
+
+ my $params = {
+ update_id_ext => $comment->id,
+ updated_datetime => DateTime::Format::W3CDTF->format_datetime($comment->confirmed_local->set_nanosecond(0)),
+ service_request_id => $comment->problem->external_id,
+ service_request_id_ext => $comment->problem->id,
+ status => $comment->problem->is_open ? 'OPEN' : 'CLOSED',
+ email => $comment->user->email,
+ description => $comment->text,
+ public_anonymity_required => $comment->anonymous ? 'TRUE' : 'FALSE',
+ last_name => $lastname,
+ first_name => $firstname,
+ };
+
+ if ( $comment->extra ) {
+ $params->{'email_alerts_requested'}
+ = $comment->extra->{email_alerts_requested} ? 'TRUE' : 'FALSE';
+ $params->{'title'} = $comment->extra->{title};
+
+ $params->{first_name} = $comment->extra->{first_name} if $comment->extra->{first_name};
+ $params->{last_name} = $comment->extra->{last_name} if $comment->extra->{last_name};
+ }
+
+ return $params;
+}
+
sub _get {
my $self = shift;
my $path = shift;
@@ -144,10 +292,25 @@ sub _get {
my $content;
if ( $self->test_mode ) {
+ $self->success(1);
$content = $self->test_get_returns->{ $path };
$self->test_uri_used( $uri->as_string );
} else {
- $content = get( $uri->as_string );
+ my $ua = LWP::UserAgent->new;
+
+ my $req = HTTP::Request->new(
+ GET => $uri->as_string
+ );
+
+ my $res = $ua->request( $req );
+
+ if ( $res->is_success ) {
+ $content = $res->decoded_content;
+ $self->success(1);
+ } else {
+ $self->success(0);
+ $self->error( $res->status_line );
+ }
}
return $content;
@@ -171,17 +334,27 @@ sub _post {
$self->debug_details( $self->debug_details . "\nrequest:" . $req->as_string );
my $ua = LWP::UserAgent->new();
- my $res = $ua->request( $req );
+ my $res;
+
+ if ( $self->test_mode ) {
+ $res = $self->test_get_returns->{ $path };
+ $self->test_req_used( $req );
+ } else {
+ $res = $ua->request( $req );
+ }
if ( $res->is_success ) {
+ $self->success(1);
return $res->decoded_content;
} else {
- warn sprintf(
- "request failed: %s\nerror: %s\n%s",
+ $self->success(0);
+ $self->error( sprintf(
+ "request failed: %s\nerror: %s\n%s\n",
$res->status_line,
$self->_process_error( $res->decoded_content ),
$self->debug_details
- );
+ ) );
+ warn $self->error;
return 0;
}
}
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm
new file mode 100644
index 000000000..b5577ff6c
--- /dev/null
+++ b/perllib/Open311/GetServiceRequestUpdates.pm
@@ -0,0 +1,136 @@
+package Open311::GetServiceRequestUpdates;
+
+use Moose;
+use Open311;
+use FixMyStreet::App;
+use DateTime::Format::W3CDTF;
+
+has council_list => ( is => 'ro' );
+has system_user => ( is => 'rw' );
+has start_date => ( is => 'ro', default => undef );
+has end_date => ( is => 'ro', default => undef );
+has suppress_alerts => ( is => 'rw', default => 0 );
+
+sub fetch {
+ my $self = shift;
+
+ my $councils = FixMyStreet::App->model('DB::Open311Conf')->search(
+ {
+ send_method => 'Open311',
+ send_comments => 1,
+ comment_user_id => { '!=', undef },
+ endpoint => { '!=', '' },
+ }
+ );
+
+ while ( my $council = $councils->next ) {
+
+ my $o = Open311->new(
+ endpoint => $council->endpoint,
+ api_key => $council->api_key,
+ jurisdiction => $council->jurisdiction,
+ );
+
+ $self->suppress_alerts( $council->suppress_alerts );
+ $self->system_user( $council->comment_user );
+ $self->update_comments( $o, { areaid => $council->area_id }, );
+ }
+}
+
+sub update_comments {
+ my ( $self, $open311, $council_details ) = @_;
+
+ my @args = ();
+
+ if ( $self->start_date || $self->end_date ) {
+ return 0 unless $self->start_date && $self->end_date;
+
+ push @args, $self->start_date;
+ push @args, $self->end_date;
+ }
+
+ my $requests = $open311->get_service_request_updates( @args );
+
+ unless ( $open311->success ) {
+ warn "Failed to fetch ServiceRequest Updates: " . $open311->error;
+ return 0;
+ }
+
+ for my $request (@$requests) {
+ my $request_id = $request->{service_request_id};
+
+ # If there's no request id then we can't work out
+ # what problem it belongs to so just skip
+ next unless $request_id;
+
+ my $problem =
+ FixMyStreet::App->model('DB::Problem')
+ ->search( {
+ external_id => $request_id,
+ council => { like => '%' . $council_details->{areaid} . '%' },
+ } );
+
+ if (my $p = $problem->first) {
+ my $c = $p->comments->search( { external_id => $request->{update_id} } );
+
+ if ( !$c->first ) {
+ my $comment_time = DateTime::Format::W3CDTF->parse_datetime( $request->{updated_datetime} );
+
+ my $comment = FixMyStreet::App->model('DB::Comment')->new(
+ {
+ problem => $p,
+ user => $self->system_user,
+ external_id => $request->{update_id},
+ text => $request->{description},
+ mark_fixed => 0,
+ mark_open => 0,
+ anonymous => 0,
+ name => $self->system_user->name,
+ confirmed => $comment_time,
+ created => $comment_time,
+ state => 'confirmed',
+ }
+ );
+
+ # if the comment is older than the last update
+ # do not change the status of the problem as it's
+ # tricky to determine the right thing to do.
+ if ( $comment->created_local > $p->lastupdate_local ) {
+ if ( $p->is_open and lc($request->{status}) eq 'closed' ) {
+ $p->state( 'fixed - council' );
+ $p->lastupdate( $comment->created );
+ $p->update;
+
+ $comment->mark_fixed( 1 );
+ } elsif ( ( $p->is_closed || $p->is_fixed ) and lc($request->{status}) eq 'open' ) {
+ $p->state( 'confirmed' );
+ $p->lastupdate( $comment->created );
+ $p->update;
+
+ $comment->mark_open( 1 );
+ }
+ }
+
+ $comment->insert();
+
+ if ( $self->suppress_alerts ) {
+ my $alert = FixMyStreet::App->model('DB::Alert')->find( {
+ alert_type => 'new_updates',
+ parameter => $p->id,
+ confirmed => 1,
+ user_id => $p->user->id,
+ } );
+
+ my $alerts_sent = FixMyStreet::App->model('DB::AlertSent')->find_or_create( {
+ alert_id => $alert->id,
+ parameter => $comment->id,
+ } );
+ }
+ }
+ }
+ }
+
+ return 1;
+}
+
+1;
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm
index cfec9005d..59148be7b 100644
--- a/perllib/Open311/PopulateServiceList.pm
+++ b/perllib/Open311/PopulateServiceList.pm
@@ -8,6 +8,7 @@ use Open311;
has council_list => ( is => 'ro' );
has found_contacts => ( is => 'rw', default => sub { [] } );
+has verbose => ( is => 'ro', default => 0 );
has _current_council => ( is => 'rw' );
has _current_open311 => ( is => 'rw' );
@@ -81,7 +82,7 @@ sub process_service {
$self->_current_service->{description} :
$self->_current_service->{service_name};
- print $self->_current_service->{service_code} . ': ' . $category . "\n";
+ print $self->_current_service->{service_code} . ': ' . $category . "\n" if $self->verbose;
my $contacts = FixMyStreet::App->model( 'DB::Contact')->search(
{
area_id => $self->_current_council->area_id,
@@ -121,7 +122,7 @@ sub _handle_existing_contact {
my $service_name = $self->_normalize_service_name;
- print $self->_current_council->area_id . " already has a contact for service code " . $self->_current_service->{service_code} . "\n";
+ print $self->_current_council->area_id . " already has a contact for service code " . $self->_current_service->{service_code} . "\n" if $self->verbose;
if ( $contact->deleted || $service_name ne $contact->category || $self->_current_service->{service_code} ne $contact->email ) {
eval {
@@ -179,16 +180,22 @@ sub _create_contact {
if ( $contact ) {
push @{ $self->found_contacts }, $self->_current_service->{service_code};
- print "created contact for service code " . $self->_current_service->{service_code} . " for council @{[$self->_current_council->area_id]}\n";
+ print "created contact for service code " . $self->_current_service->{service_code} . " for council @{[$self->_current_council->area_id]}\n" if $self->verbose;
}
}
-sub _add_contact_to_meta {
+sub _add_meta_to_contact {
my ( $self, $contact ) = @_;
- print "Fetching meta data for $self->_current_service->{service_code}\n";
+ print "Fetching meta data for $self->_current_service->{service_code}\n" if $self->verbose;
my $meta_data = $self->_current_open311->get_service_meta_info( $self->_current_service->{service_code} );
+ if ( ref $meta_data->{ attributes }->{ attribute } eq 'HASH' ) {
+ $meta_data->{ attributes }->{ attribute } = [
+ $meta_data->{ attributes }->{ attribute }
+ ];
+ }
+
# turn the data into something a bit more friendly to use
my @meta =
# remove trailing colon as we add this when we display so we don't want 2
@@ -197,6 +204,26 @@ sub _add_contact_to_meta {
sort { $a->{order} <=> $b->{order} }
@{ $meta_data->{attributes}->{attribute} };
+ # we add these later on from bromley so don't list them here
+ # as we don't want to display them
+ if ( $self->_current_council->area_id == 2482 ) {
+ my %ignore = map { $_ => 1 } qw/
+ service_request_id_ext
+ requested_datetime
+ report_url
+ title
+ last_name
+ email
+ easting
+ northing
+ report_title
+ public_anonymity_required
+ email_alerts_requested
+ /;
+
+ @meta = grep { ! $ignore{ $_->{ code } } } @meta;
+ }
+
$contact->extra( \@meta );
$contact->update;
}