diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 24 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bromley.pm | 39 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Buckinghamshire.pm | 52 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Warwickshire.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/Script/ArchiveOldEnquiries.pm | 44 |
5 files changed, 130 insertions, 37 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index a23a9046f..e6c4fe50d 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -1069,26 +1069,12 @@ sub set_report_extras : Private { my ($self, $c, $contacts, $param_prefix) = @_; $param_prefix ||= ""; - my @extra; - foreach my $contact (@$contacts) { - my $metas = $contact->get_metadata_for_input; - foreach my $field ( @$metas ) { - if ( lc( $field->{required} ) eq 'true' && !$c->cobrand->category_extra_hidden($field)) { - unless ( $c->get_param($param_prefix . $field->{code}) ) { - $c->stash->{field_errors}->{ $field->{code} } = _('This information is required'); - } - } - push @extra, { - name => $field->{code}, - description => $field->{description}, - value => $c->get_param($param_prefix . $field->{code}) || '', - }; - } - } + my @metalist = map { [ $_->get_metadata_for_input, $param_prefix ] } @$contacts; + push @metalist, map { [ $_->get_extra_fields, "extra[" . $_->id . "]" ] } @{$c->stash->{report_extra_fields}}; - foreach my $extra_fields (@{ $c->stash->{report_extra_fields} }) { - my $metas = $extra_fields->get_extra_fields; - $param_prefix = "extra[" . $extra_fields->id . "]"; + my @extra; + foreach my $item (@metalist) { + my ($metas, $param_prefix) = @$item; foreach my $field ( @$metas ) { if ( lc( $field->{required} ) eq 'true' && !$c->cobrand->category_extra_hidden($field)) { unless ( $c->get_param($param_prefix . $field->{code}) ) { diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm index 11c685c91..386e1a269 100644 --- a/perllib/FixMyStreet/Cobrand/Bromley.pm +++ b/perllib/FixMyStreet/Cobrand/Bromley.pm @@ -196,5 +196,44 @@ sub open311_pre_send { } } +sub open311_contact_meta_override { + my ($self, $service, $contact, $meta) = @_; + + $contact->set_extra_metadata( id_field => 'service_request_id_ext'); + + # Lights we want to store feature ID, PROW on all categories. + push @$meta, { + code => 'prow_reference', + datatype => 'string', + description => 'Right of way reference', + order => 101, + required => 'false', + variable => 'true', + automated => 'hidden_field', + }; + push @$meta, { + code => 'feature_id', + datatype => 'string', + description => 'Feature ID', + order => 100, + required => 'false', + variable => 'true', + automated => 'hidden_field', + } if $service->{service_code} eq 'SLRS'; + + my @override = qw( + requested_datetime + report_url + title + last_name + email + report_title + public_anonymity_required + email_alerts_requested + ); + my %ignore = map { $_ => 1 } @override; + @$meta = grep { !$ignore{$_->{code}} } @$meta; +} + 1; diff --git a/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm b/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm index c8432c4d7..75564fddd 100644 --- a/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm +++ b/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm @@ -109,6 +109,58 @@ sub open311_config_updates { $params->{mark_reopen} = 1; } +sub open311_contact_meta_override { + my ($self, $service, $contact, $meta) = @_; + + push @$meta, { + code => 'road-placement', + datatype => 'singlevaluelist', + description => 'Is the fly-tip located on', + order => 100, + required => 'true', + variable => 'true', + values => [ + { key => 'road', name => 'The road' }, + { key => 'off-road', name => 'Off the road/on a verge' }, + ], + } if $service->{service_name} eq 'Flytipping'; +} + +sub process_open311_extras { + my ($self, $c, $body, $extra) = @_; + + $self->flytipping_body_fix( + $c->stash->{report}, + $c->get_param('road-placement'), + $c->stash->{field_errors}, + ); +} + +sub flytipping_body_fix { + my ($self, $report, $road_placement, $errors) = @_; + + return unless $report->category eq 'Flytipping'; + + if ($report->bodies_str =~ /,/) { + # Sent to both councils in the area + my @bodies = values %{$report->bodies}; + my $county = (grep { $_->name =~ /^Buckinghamshire/ } @bodies)[0]; + my $district = (grep { $_->name !~ /^Buckinghamshire/ } @bodies)[0]; + # Decide which to send to based upon the answer to the extra question: + if ($road_placement eq 'road') { + $report->bodies_str($county->id); + } elsif ($road_placement eq 'off-road') { + $report->bodies_str($district->id); + } + } else { + # If the report is only being sent to the district, we do + # not care about the road question, if it is missing + if (!$report->to_body_named('Buckinghamshire')) { + delete $errors->{'road-placement'}; + } + } +} + sub filter_report_description { my ($self, $description) = @_; diff --git a/perllib/FixMyStreet/Cobrand/Warwickshire.pm b/perllib/FixMyStreet/Cobrand/Warwickshire.pm index 73f66f3da..c301450bc 100644 --- a/perllib/FixMyStreet/Cobrand/Warwickshire.pm +++ b/perllib/FixMyStreet/Cobrand/Warwickshire.pm @@ -34,4 +34,12 @@ sub contact_name { 'Warwickshire County Council (do not reply)'; } sub send_questionnaires { 0 } +sub open311_contact_meta_override { + my ($self, $service, $contact, $meta) = @_; + + $contact->set_extra_metadata( id_field => 'external_id'); + + @$meta = grep { $_->{code} ne 'closest_address' } @$meta; +} + 1; diff --git a/perllib/FixMyStreet/Script/ArchiveOldEnquiries.pm b/perllib/FixMyStreet/Script/ArchiveOldEnquiries.pm index 03bc511a0..dd44b9651 100644 --- a/perllib/FixMyStreet/Script/ArchiveOldEnquiries.pm +++ b/perllib/FixMyStreet/Script/ArchiveOldEnquiries.pm @@ -1,11 +1,8 @@ package FixMyStreet::Script::ArchiveOldEnquiries; -use strict; +use v5.14; use warnings; -require 5.8.0; -use FixMyStreet; -use FixMyStreet::App; use FixMyStreet::DB; use FixMyStreet::Cobrand; use FixMyStreet::Map; @@ -17,17 +14,17 @@ my $opts = { }; sub query { - return { - bodies_str => { 'LIKE', "%".$opts->{body}."%"}, - -and => [ + my $rs = shift; + return $rs->to_body($opts->{body})->search({ + -and => [ lastupdate => { '<', $opts->{email_cutoff} }, lastupdate => { '>', $opts->{closure_cutoff} }, ], - state => [ FixMyStreet::DB::Result::Problem->open_states() ], - }; + state => [ FixMyStreet::DB::Result::Problem->open_states() ], + }); } -sub archive { +sub update_options { my $params = shift; if ( $params ) { $opts = { @@ -35,13 +32,19 @@ sub archive { %$params, }; } +} + +sub archive { + my $params = shift; + update_options($params); unless ( $opts->{commit} ) { printf "Doing a dry run; emails won't be sent and reports won't be closed.\n"; printf "Re-run with --commit to actually archive reports.\n\n"; } - my @user_ids = FixMyStreet::DB->resultset('Problem')->search(query(), + my $rs = FixMyStreet::DB->resultset('Problem'); + my @user_ids = query($rs)->search(undef, { distinct => 1, columns => ['user_id'], @@ -55,7 +58,7 @@ sub archive { }); my $user_count = $users->count; - my $problem_count = FixMyStreet::DB->resultset('Problem')->search(query(), + my $problem_count = query($rs)->search(undef, { columns => ['id'], rows => $opts->{limit}, @@ -71,8 +74,7 @@ sub archive { } } - my $problems_to_close = FixMyStreet::DB->resultset('Problem')->search({ - bodies_str => { 'LIKE', "%".$opts->{body}."%"}, + my $problems_to_close = $rs->to_body($opts->{body})->search({ lastupdate => { '<', $opts->{closure_cutoff} }, state => [ FixMyStreet::DB::Result::Problem->open_states() ], }, { @@ -87,7 +89,8 @@ sub archive { sub send_email_and_close { my ($user) = @_; - my $problems = $user->problems->search(query(), { + my $problems = $user->problems; + $problems = query($problems)->search(undef, { order_by => { -desc => 'confirmed' }, }); @@ -135,22 +138,27 @@ sub close_problems { return unless $opts->{commit}; my $problems = shift; + my $extra = { auto_closed_by_script => 1 }; + $extra->{is_superuser} = 1 if !$opts->{user_name}; + while (my $problem = $problems->next) { my $timestamp = \'current_timestamp'; my $comment = $problem->add_to_comments( { - text => '', + text => $opts->{closure_text} || '', created => $timestamp, confirmed => $timestamp, user_id => $opts->{user}, - name => _('an administrator'), + name => $opts->{user_name} || _('an administrator'), mark_fixed => 0, anonymous => 0, state => 'confirmed', problem_state => 'closed', - extra => { is_superuser => 1 }, + extra => $extra, } ); $problem->update({ state => 'closed', send_questionnaire => 0 }); + next if $opts->{retain_alerts}; + # Stop any alerts being sent out about this closure. my @alerts = FixMyStreet::DB->resultset('Alert')->search( { alert_type => 'new_updates', |