diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 17 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 1 | ||||
-rwxr-xr-x | perllib/FixMyStreet/Script/UpdateAllReports.pm | 42 |
4 files changed, 40 insertions, 22 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 33404cb82..2cd34b7e2 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -1042,7 +1042,7 @@ sub report_edit_location : Private { $c->forward('/council/load_and_check_areas', []); $c->forward('/report/new/setup_categories_and_bodies'); my %allowed_bodies = map { $_ => 1 } @{$problem->bodies_str_ids}; - my @new_bodies = @{$c->stash->{bodies_to_list}}; + my @new_bodies = keys %{$c->stash->{bodies_to_list}}; my $bodies_match = grep { exists( $allowed_bodies{$_} ) } @new_bodies; $c->stash($safe_stash); return unless $bodies_match; diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 312268f65..8c6c1b244 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -695,9 +695,7 @@ sub setup_categories_and_bodies : Private { # put results onto stash for display $c->stash->{bodies} = \%bodies; $c->stash->{contacts} = \@contacts; - $c->stash->{bodies_to_list} = [ keys %bodies_to_list ]; - $c->stash->{bodies_to_list_names} = [ map { $_->name } values %bodies_to_list ]; - $c->stash->{bodies_to_list_urls} = [ map { $_->external_url } values %bodies_to_list ]; + $c->stash->{bodies_to_list} = \%bodies_to_list; $c->stash->{category_options} = \@category_options; $c->stash->{category_extras} = \%category_extras; $c->stash->{category_extras_hidden} = \%category_extras_hidden; @@ -920,6 +918,7 @@ sub process_report : Private { # set these straight from the params $report->category( _ $params{category} ) if $params{category}; + $c->cobrand->call_hook(report_new_munge_category => $report); $report->subcategory( $params{subcategory} ); my $areas = $c->stash->{all_areas_mapit}; @@ -948,7 +947,7 @@ sub process_report : Private { if ( $c->stash->{non_public_categories}->{ $report->category } ) { $report->non_public( 1 ); } - } elsif ( @{ $c->stash->{bodies_to_list} } ) { + } elsif ( %{ $c->stash->{bodies_to_list} } ) { # There was an area with categories, but we've not been given one. Bail. $c->stash->{field_errors}->{category} = _('Please choose a category'); @@ -967,6 +966,14 @@ sub process_report : Private { my $value = $c->get_param($form_name) || ''; $c->stash->{field_errors}->{$form_name} = _('This information is required') if $field->{required} && !$value; + if ($field->{validator}) { + eval { + $value = $field->{validator}->($value); + }; + if ($@) { + $c->stash->{field_errors}->{$form_name} = $@; + } + } $report->set_extra_metadata( $form_name => $value ); } @@ -1353,6 +1360,8 @@ sub save_user_and_report : Private { $c->log->info($report->user->id . ' exists, but is not logged in for this report'); } + $c->cobrand->call_hook(report_new_munge_before_insert => $report); + $report->update_or_insert; # tidy up diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 037458538..20381bb85 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -93,6 +93,7 @@ sub index : Path : Args(0) { } } else { my @bodies = $c->model('DB::Body')->active->translated->with_area_count->all_sorted; + @bodies = @{$c->cobrand->call_hook('reports_hook_restrict_bodies_list', \@bodies) || \@bodies }; $c->stash->{bodies} = \@bodies; } diff --git a/perllib/FixMyStreet/Script/UpdateAllReports.pm b/perllib/FixMyStreet/Script/UpdateAllReports.pm index d6f3eb64b..21d8d28a0 100755 --- a/perllib/FixMyStreet/Script/UpdateAllReports.pm +++ b/perllib/FixMyStreet/Script/UpdateAllReports.pm @@ -6,23 +6,24 @@ use warnings; use FixMyStreet; use FixMyStreet::Cobrand; use FixMyStreet::DB; +use CronFns; use List::MoreUtils qw(zip); use List::Util qw(sum); +my $site = CronFns::site(FixMyStreet->config('BASE_URL')); + my $fourweeks = 4*7*24*60*60; # Age problems from when they're confirmed, except on Zurich # where they appear as soon as they're created. my $age_column = 'confirmed'; -if ( FixMyStreet->config('BASE_URL') =~ /zurich|zueri/ ) { - $age_column = 'created'; -} +$age_column = 'created' if $site eq 'zurich'; my $dtf = FixMyStreet::DB->schema->storage->datetime_parser; -my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('default')->new; -FixMyStreet::DB->schema->cobrand($cobrand); +my $cobrand_cls = FixMyStreet::Cobrand->get_class_for_moniker($site)->new; +FixMyStreet::DB->schema->cobrand($cobrand_cls); sub generate { my $include_areas = shift; @@ -34,7 +35,7 @@ sub generate { }, { columns => [ - 'id', 'bodies_str', 'state', 'areas', 'cobrand', + 'id', 'bodies_str', 'state', 'areas', 'cobrand', 'category', { duration => { extract => "epoch from current_timestamp-lastupdate" } }, { age => { extract => "epoch from current_timestamp-$age_column" } }, ] @@ -43,13 +44,26 @@ sub generate { $problems = $problems->cursor; # Raw DB cursor for speed my ( %fixed, %open ); - my @cols = ( 'id', 'bodies_str', 'state', 'areas', 'cobrand', 'duration', 'age' ); + my %stats = ( + fixed => \%fixed, + open => \%open, + ); + my @cols = ( 'id', 'bodies_str', 'state', 'areas', 'cobrand', 'category', 'duration', 'age' ); while ( my @problem = $problems->next ) { my %problem = zip @cols, @problem; - my @bodies; - my @areas; + my @bodies = split( /,/, $problem{bodies_str} ); my $cobrand = $problem{cobrand}; + + if (my $type = $cobrand_cls->call_hook(dashboard_categorize_problem => \%problem)) { + foreach my $body ( @bodies ) { + $stats{$type}{$body}++; + $stats{$cobrand}{$type}{$body}++; + } + next; + } + my $duration_str = ( $problem{duration} > 2 * $fourweeks ) ? 'old' : 'new'; + my $type = ( $problem{duration} > 2 * $fourweeks ) ? 'unknown' : ($problem{age} > $fourweeks ? 'older' : 'new'); @@ -57,9 +71,6 @@ sub generate { FixMyStreet::DB::Result::Problem->fixed_states()->{$problem{state}} || FixMyStreet::DB::Result::Problem->closed_states()->{$problem{state}}; - # Add to bodies it was sent to - @bodies = split( /,/, $problem{bodies_str} ); - foreach my $body ( @bodies ) { if ( $problem_fixed ) { # Fixed problems are either old or new @@ -73,7 +84,7 @@ sub generate { } if ( $include_areas ) { - @areas = grep { $_ } split( /,/, $problem{areas} ); + my @areas = grep { $_ } split( /,/, $problem{areas} ); foreach my $area ( @areas ) { if ( $problem_fixed ) { $fixed{areas}{$area}{$duration_str}++; @@ -84,10 +95,7 @@ sub generate { } } - return { - fixed => \%fixed, - open => \%open, - }; + return \%stats; } sub end_period { |