From ef3a3a789e8f91b62dc562ff69781dc0daa80871 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 13 Aug 2015 12:21:20 +0100 Subject: Remove ms_current_timestamp() override function. This override is not used anywhere, it dates from a very old long-gone test script, and causes issues with database query planning. --- perllib/FixMyStreet/App/Controller/Admin.pm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 6145a6eb0..44b898743 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -359,7 +359,7 @@ sub update_contacts : Private { $contact->deleted( $c->get_param('deleted') ? 1 : 0 ); $contact->non_public( $c->get_param('non_public') ? 1 : 0 ); $contact->note( $c->get_param('note') ); - $contact->whenedited( \'ms_current_timestamp()' ); + $contact->whenedited( \'current_timestamp' ); $contact->editor( $editor ); $contact->endpoint( $c->get_param('endpoint') ); $contact->jurisdiction( $c->get_param('jurisdiction') ); @@ -395,7 +395,7 @@ sub update_contacts : Private { $contacts->update( { confirmed => 1, - whenedited => \'ms_current_timestamp()', + whenedited => \'current_timestamp', note => 'Confirmed', editor => $editor, } @@ -707,7 +707,7 @@ sub report_edit : Path('report_edit') : Args(1) { } elsif ( $c->get_param('mark_sent') ) { $c->forward('check_token'); - $problem->whensent(\'ms_current_timestamp()'); + $problem->whensent(\'current_timestamp'); $problem->update(); $c->stash->{status_message} = '

' . _('That problem has been marked as sent.') . '

'; $c->forward( 'log_edit', [ $id, 'problem', 'marked sent' ] ); @@ -787,14 +787,14 @@ sub report_edit : Path('report_edit') : Args(1) { } if ( $problem->is_visible() and $old_state eq 'unconfirmed' ) { - $problem->confirmed( \'ms_current_timestamp()' ); + $problem->confirmed( \'current_timestamp' ); } if ($done) { $problem->discard_changes; } else { - $problem->lastupdate( \'ms_current_timestamp()' ) if $edited || $new_state ne $old_state; + $problem->lastupdate( \'current_timestamp' ) if $edited || $new_state ne $old_state; $problem->update; if ( $new_state ne $old_state ) { @@ -943,10 +943,10 @@ sub update_edit : Path('update_edit') : Args(1) { } if ( $new_state eq 'confirmed' and $old_state eq 'unconfirmed' ) { - $update->confirmed( \'ms_current_timestamp()' ); + $update->confirmed( \'current_timestamp' ); if ( $update->problem_state && $update->created > $update->problem->lastupdate ) { $update->problem->state( $update->problem_state ); - $update->problem->lastupdate( \'ms_current_timestamp()' ); + $update->problem->lastupdate( \'current_timestamp' ); $update->problem->update; } } -- cgit v1.2.3 From f5d6ec933c9fd4d57f9b56fec27f7c746a0706b9 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Mon, 17 Aug 2015 19:21:45 +0100 Subject: Use ResultSet/cobrand->problems where appropriate. Fixes #893. --- perllib/FixMyStreet/App/Controller/Admin.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 44b898743..0134dad5d 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -1064,7 +1064,7 @@ sub user_edit : Path('user_edit') : Args(1) { sub flagged : Path('flagged') : Args(0) { my ( $self, $c ) = @_; - my $problems = $c->model('DB::Problem')->search( { flagged => 1 } ); + my $problems = $c->cobrand->problems->search( { flagged => 1 } ); # pass in as array ref as using same template as search_reports # which has to use an array ref for sql quoting reasons @@ -1154,7 +1154,7 @@ sub stats : Path('stats') : Args(0) { ); } - my $p = $c->model('DB::Problem')->search( + my $p = $c->cobrand->problems->search( { -AND => [ $field => { '>=', $start_date}, -- cgit v1.2.3 From 5c79337ad423cd7fc3cada9b7830d90726387987 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Mon, 17 Aug 2015 17:12:26 +0100 Subject: Simplify/consolidate body restriction db code. Make dashboard work properly in two-tier councils, showing reports sent to both. Create an index on the array of the bodies_str column to speed up performance, and use that throughout the code replacing all LIKE scans. This also enables a simplifying tidy of the restriction code. --- perllib/FixMyStreet/App/Controller/Admin.pm | 33 ++++++++--------------------- 1 file changed, 9 insertions(+), 24 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 0134dad5d..f9ea383f8 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -70,8 +70,6 @@ sub index : Path : Args(0) { return $c->cobrand->admin(); } - my $site_restriction = $c->cobrand->site_restriction(); - my $problems = $c->cobrand->problems->summary_count; my %prob_counts = @@ -85,7 +83,7 @@ sub index : Path : Args(0) { for ( FixMyStreet::DB::Result::Problem->visible_states() ); $c->stash->{total_problems_users} = $c->cobrand->problems->unique_users; - my $comments = $c->model('DB::Comment')->summary_count( $site_restriction ); + my $comments = $c->model('DB::Comment')->summary_count( $c->cobrand->body_restriction ); my %comment_counts = map { $_->state => $_->get_column('state_count') } $comments->all; @@ -150,7 +148,6 @@ sub config_page : Path( 'config' ) : Args(0) { sub timeline : Path( 'timeline' ) : Args(0) { my ($self, $c) = @_; - my $site_restriction = $c->cobrand->site_restriction(); my %time; $c->model('DB')->schema->storage->sql_maker->quote_char( '"' ); @@ -171,7 +168,7 @@ sub timeline : Path( 'timeline' ) : Args(0) { push @{$time{$_->whenanswered->epoch}}, { type => 'quesAnswered', date => $_->whenanswered, obj => $_ } if $_->whenanswered; } - my $updates = $c->model('DB::Comment')->timeline( $site_restriction ); + my $updates = $c->model('DB::Comment')->timeline( $c->cobrand->body_restriction ); foreach ($updates->all) { push @{$time{$_->created->epoch}}, { type => 'update', date => $_->created, obj => $_} ; @@ -538,8 +535,6 @@ sub reports : Path('reports') { if (my $search = $c->get_param('search')) { $c->stash->{searched} = $search; - my $site_restriction = $c->cobrand->site_restriction; - my $search_n = 0; $search_n = int($search) if $search =~ /^\d+$/; @@ -616,9 +611,10 @@ sub reports : Path('reports') { } if (@$query) { - my $updates = $c->model('DB::Comment')->search( + my $updates = $c->model('DB::Comment') + ->to_body($c->cobrand->body_restriction) + ->search( { - %{ $site_restriction }, -or => $query, }, { @@ -650,8 +646,6 @@ sub reports : Path('reports') { sub report_edit : Path('report_edit') : Args(1) { my ( $self, $c, $id ) = @_; - my $site_restriction = $c->cobrand->site_restriction; - my $problem = $c->cobrand->problems->search( { id => $id } )->first; $c->detach( '/page_error_404_not_found' ) @@ -874,13 +868,9 @@ sub users: Path('users') : Args(0) { sub update_edit : Path('update_edit') : Args(1) { my ( $self, $c, $id ) = @_; - my $site_restriction = $c->cobrand->site_restriction; - my $update = $c->model('DB::Comment')->search( - { - id => $id, - %{$site_restriction}, - } - )->first; + my $update = $c->model('DB::Comment') + ->to_body($c->cobrand->body_restriction) + ->search({ id => $id })->first; $c->detach( '/page_error_404_not_found' ) unless $update; @@ -1121,9 +1111,6 @@ sub stats : Path('stats') : Args(0) { my $bymonth = $c->get_param('bymonth'); $c->stash->{bymonth} = $bymonth; - my ( %body, %dates ); - $body{bodies_str} = { like => $c->get_param('body') } - if $c->get_param('body'); $c->stash->{selected_body} = $c->get_param('body'); @@ -1154,14 +1141,12 @@ sub stats : Path('stats') : Args(0) { ); } - my $p = $c->cobrand->problems->search( + my $p = $c->cobrand->problems->to_body($c->get_param('body'))->search( { -AND => [ $field => { '>=', $start_date}, $field => { '<=', $end_date + $one_day }, ], - %body, - %dates, }, \%select, ); -- cgit v1.2.3 From a78bb3fc98dd1851e371c78d9743125d02baf04e Mon Sep 17 00:00:00 2001 From: Hakim Cassimally Date: Tue, 27 Jan 2015 18:32:02 +0000 Subject: Add support for multiple photos per report. For Zurich, see mysociety/FixMyStreet-Commercial#664. This commit includes a new PhotoSet class (NB: called Model:: though not really a model), should handle binary data (e.g. old style photos in database), fileids (40-char hash), and Catalyst::Upload objects. --- perllib/FixMyStreet/App/Controller/Admin.pm | 59 ++++++++++------------------- 1 file changed, 20 insertions(+), 39 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index f9ea383f8..d7bca05a7 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -10,6 +10,7 @@ use Digest::SHA qw(sha1_hex); use mySociety::EmailUtil qw(is_valid_email); use if !$ENV{TRAVIS}, 'Image::Magick'; use DateTime::Format::Strptime; +use List::Util 'first'; use FixMyStreet::SendReport; @@ -672,8 +673,8 @@ sub report_edit : Path('report_edit') : Args(1) { ); } - if ( $c->get_param('rotate_photo') ) { - $c->forward('rotate_photo'); + if (my $rotate_photo_param = $self->_get_rotate_photo_param($c)) { + $self->rotate_photo($c, @$rotate_photo_param); return 1; } @@ -1370,36 +1371,28 @@ Rotate a photo 90 degrees left or right =cut +# returns index of photo to rotate, if any +sub _get_rotate_photo_param { + my ($self, $c) = @_; + my $params = $c->req->parameters; + my $key = first { /^rotate_photo/ } $c->req->param or return; + my ($index) = $key =~ /(\d+)$/; + my $direction = $c->req->param($key); + return [ $index || 0, $key, $direction ]; +} + sub rotate_photo : Private { - my ( $self, $c ) =@_; + my ( $self, $c, $index, $key, $direction ) = @_; - my $direction = $c->get_param('rotate_photo'); return unless $direction eq _('Rotate Left') or $direction eq _('Rotate Right'); - my $photo = $c->stash->{problem}->photo; - my $file; - - # If photo field contains a hash - if ( length($photo) == 40 ) { - $file = file( $c->config->{UPLOAD_DIR}, "$photo.jpeg" ); - $photo = $file->slurp; - } - - $photo = _rotate_image( $photo, $direction eq _('Rotate Left') ? -90 : 90 ); - return unless $photo; + my $problem = $c->stash->{problem}; + my $fileid = $problem->get_photoset($c)->rotate_image( + $index, + $direction eq _('Rotate Left') ? -90 : 90 + ) or return; - # Write out to new location - my $fileid = sha1_hex($photo); - $file = file( $c->config->{UPLOAD_DIR}, "$fileid.jpeg" ); - - my $fh = $file->open('w'); - print $fh $photo; - close $fh; - - unlink glob FixMyStreet->path_to( 'web', 'photo', $c->stash->{problem}->id . '.*' ); - - $c->stash->{problem}->photo( $fileid ); - $c->stash->{problem}->update(); + $problem->update({ photo => $fileid }); return 1; } @@ -1449,18 +1442,6 @@ sub trim { return $e; } -sub _rotate_image { - my ($photo, $direction) = @_; - my $image = Image::Magick->new; - $image->BlobToImage($photo); - my $err = $image->Rotate($direction); - return 0 if $err; - my @blobs = $image->ImageToBlob(); - undef $image; - return $blobs[0]; -} - - =head1 AUTHOR Struan Donald -- cgit v1.2.3 From e9961ee495ab87cbe67cf37e53edbae0794541d2 Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Thu, 5 Feb 2015 15:09:49 +0000 Subject: [Zurich] 'photo required' functionality - Save 'photo_required' value in Contact->extra from admin edit form - Enforce per-category photo requirement on new reports A new step has been added to the photo upload process that ensures a photo is present if any of the categories chosen for the report require it. If the photo is missing an error is displayed to the user in the same manner as if the photo upload was invalid. - Add test of mandatory photo categories --- perllib/FixMyStreet/App/Controller/Admin.pm | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index d7bca05a7..7ead7db16 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -364,6 +364,14 @@ sub update_contacts : Private { $contact->api_key( $c->get_param('api_key') ); $contact->send_method( $c->get_param('send_method') ); + # Set the photo_required flag in extra to the appropriate value + if ( $c->req->param('photo_required') ) { + $contact->set_extra_metadata_if_undefined( photo_required => 1 ); + } + else { + $contact->unset_extra_metadata( 'photo_required' ); + } + if ( %errors ) { $c->stash->{updated} = _('Please correct the errors below'); $c->stash->{contact} = $contact; -- cgit v1.2.3 From 735536dc5e269f2094d122e49f2c648928db4acb Mon Sep 17 00:00:00 2001 From: Hakim Cassimally Date: Thu, 19 Feb 2015 16:41:22 +0000 Subject: [Zurich] Response templates for report admin. This provides a ResponseTemplate model that an admin/staff user can choose from when responding to problems. For mysociety/FixMyStreet-Commercial#671. --- perllib/FixMyStreet/App/Controller/Admin.pm | 79 +++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 7ead7db16..be705110b 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -819,6 +819,85 @@ sub report_edit : Path('report_edit') : Args(1) { return 1; } +sub templates : Path('templates') : Args(0) { + my ( $self, $c ) = @_; + + $c->detach( '/page_error_404_not_found' ) + unless $c->cobrand->moniker eq 'zurich'; + + my $user = $c->user; + + $self->templates_for_body($c, $user->from_body ); +} + +sub templates_view : Path('templates') : Args(1) { + my ($self, $c, $body_id) = @_; + + $c->detach( '/page_error_404_not_found' ) + unless $c->cobrand->moniker eq 'zurich'; + + # e.g. for admin + + my $body = $c->model('DB::Body')->find($body_id) + or $c->detach( '/page_error_404_not_found' ); + + $self->templates_for_body($c, $body); +} + +sub template_edit : Path('templates') : Args(2) { + my ( $self, $c, $body_id, $template_id ) = @_; + + $c->detach( '/page_error_404_not_found' ) + unless $c->cobrand->moniker eq 'zurich'; + + my $body = $c->model('DB::Body')->find($body_id) + or $c->detach( '/page_error_404_not_found' ); + $c->stash->{body} = $body; + + my $template; + if ($template_id eq 'new') { + $template = $body->response_templates->new({}); + } + else { + $template = $body->response_templates->find( $template_id ) + or $c->detach( '/page_error_404_not_found' ); + } + + if ($c->req->method eq 'POST') { + if ($c->req->param('delete_template') eq _("Delete template")) { + $template->delete; + } else { + $template->title( $c->req->param('title') ); + $template->text ( $c->req->param('text') ); + $template->update_or_insert; + } + + $c->res->redirect( $c->uri_for( 'templates', $body->id ) ); + } + + $c->stash->{response_template} = $template; + + $c->stash->{template} = 'admin/template_edit.html'; +} + + +sub templates_for_body { + my ( $self, $c, $body ) = @_; + + $c->stash->{body} = $body; + + my @templates = $body->response_templates->search( + undef, + { + order_by => 'title' + } + ); + + $c->stash->{response_templates} = \@templates; + + $c->stash->{template} = 'admin/templates.html'; +} + sub users: Path('users') : Args(0) { my ( $self, $c ) = @_; -- cgit v1.2.3 From 657177eba893c29d6d3f9e4b9f4f24ede5b78bc4 Mon Sep 17 00:00:00 2001 From: Hakim Cassimally Date: Mon, 2 Feb 2015 15:33:42 +0000 Subject: Add "time spent" admin logging. Mechanism is general, but current implementation only used for Zurich. - Zurich: Record time_spent field mysociety/FixMyStreet-Commercial#676 - template changes (including jQuery spinner) - backend changes to save data are made: - in log_edit, if supplied - and time on category change (and arbitrary actions) - Add update_admin_log to all paths for DM, ensuring that it gets called, while resetting the `time_spent` parameter, to make sure that there is never a duplicate record created. - Also quell warning about using DateTime values in query. - Also add (seemingly unrelated) parens to stop misparsing of OK line in questionnaire test now that DT::Format::Pg is used in Zurich cobrand See mysociety/FixMyStreet-Commercial#676 --- perllib/FixMyStreet/App/Controller/Admin.pm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index be705110b..5ebeffc11 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -1339,13 +1339,24 @@ Adds an entry into the admin_log table using the current user. =cut sub log_edit : Private { - my ( $self, $c, $id, $object_type, $action ) = @_; + my ( $self, $c, $id, $object_type, $action, $time_spent ) = @_; + + $time_spent //= 0; + $time_spent = 0 if $time_spent < 0; + + my $user_object = do { + my $auth_user = $c->user; + $auth_user ? $auth_user->get_object : undef; + }; + $c->model('DB::AdminLog')->create( { admin_user => $c->forward('get_user'), + $user_object ? ( user => $user_object ) : (), # as (rel => undef) doesn't work object_type => $object_type, action => $action, object_id => $id, + time_spent => $time_spent, } )->insert(); } -- cgit v1.2.3 From 91da8077bad2de594297c13c507cc5001c036531 Mon Sep 17 00:00:00 2001 From: Hakim Cassimally Date: Tue, 21 Apr 2015 14:18:17 +0000 Subject: [Zurich] Tweaks to redirect See mysociety/FixMyStreet-Commercial#690 I understand redirection to summary page was introduced at ZWN's request, to make it easy to process reports and then quickly move onto the next one. However, during testing now, Tobias has mentioned this is a) slowing things down and b) confusing because it's not obvious that the report has been saved. I've tried to address (b) by adding the "Aktualisiert!" message when you are redirected. Also, for (a) I've removed the redirection from a few cases, and disabled it for superuser. If need be, I can remove redirection from more (or all) cases. Fix Official answer/Reply to user - hide label for status update on state change - correct wording on button for closure (single wording) - correct wording on label for user reply (either "Official answer" or "Reply to user" as appropriate) - Make sure the official response texts are shown for edit/static as appropriate, and test. - javascript improvements - honour public status update for Extern/Wunsch too - don't show public message for Wunsch - Ignore all other fields when rotating photos. (See mysociety/FixMyStreet-Commercial#718) --- perllib/FixMyStreet/App/Controller/Admin.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 5ebeffc11..677aa66d7 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -683,7 +683,15 @@ sub report_edit : Path('report_edit') : Args(1) { if (my $rotate_photo_param = $self->_get_rotate_photo_param($c)) { $self->rotate_photo($c, @$rotate_photo_param); - return 1; + if ( $c->cobrand->moniker eq 'zurich' ) { + # Clicking the photo rotation buttons should do nothing + # except for rotating the photo, so return the user + # to the report screen now. + $c->res->redirect( $c->uri_for( 'report_edit', $problem->id ) ); + return; + } else { + return 1; + } } if ( $c->cobrand->moniker eq 'zurich' ) { -- cgit v1.2.3 From 319b49f0206fda26d7cf0fdc71eed6c4195594ae Mon Sep 17 00:00:00 2001 From: Zarino Zappia Date: Wed, 25 Mar 2015 16:31:55 +0000 Subject: [Zurich] Add maps to Zurich admin report print view - Includes a small map at the top of the first page and a second full-width map on a separate page. - upgrades tiles to the new 512px ones already used by JS as implemented in https://github.com/mysociety/FixMyStreet-Commercial/issues/668 - Uses jQuery to clone a copy of the "noscript" map elsewhere into the DOM, because the original is too far from where we need it. - extracts maps/openlayers.html to call maps/noscript_map.html - specialises the Zurich version to allow a richer structure to be returned, including arbitrary sized map - Map::Zurich now returns nearly arbitrary sized map tiles - second larger map is prepared (only for admin/report_edit) See mysociety/FixMyStreet-Commercial#677 --- perllib/FixMyStreet/App/Controller/Admin.pm | 1 + 1 file changed, 1 insertion(+) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 677aa66d7..ae64bd42d 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -678,6 +678,7 @@ sub report_edit : Path('report_edit') : Args(1) { type => 'big', } ] : [], + print_report => 1, ); } -- cgit v1.2.3 From ffc03ca3330a43a98a3728df6f3d56c7fc1837d1 Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Tue, 29 Sep 2015 15:08:32 +0100 Subject: [Zurich] Use FMS::App->get_param() instead of req->param --- perllib/FixMyStreet/App/Controller/Admin.pm | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index ae64bd42d..39d6ff72f 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -365,7 +365,7 @@ sub update_contacts : Private { $contact->send_method( $c->get_param('send_method') ); # Set the photo_required flag in extra to the appropriate value - if ( $c->req->param('photo_required') ) { + if ( $c->get_param('photo_required') ) { $contact->set_extra_metadata_if_undefined( photo_required => 1 ); } else { @@ -873,11 +873,11 @@ sub template_edit : Path('templates') : Args(2) { } if ($c->req->method eq 'POST') { - if ($c->req->param('delete_template') eq _("Delete template")) { + if ($c->get_param('delete_template') eq _("Delete template")) { $template->delete; } else { - $template->title( $c->req->param('title') ); - $template->text ( $c->req->param('text') ); + $template->title( $c->get_param('title') ); + $template->text ( $c->get_param('text') ); $template->update_or_insert; } @@ -1481,10 +1481,9 @@ Rotate a photo 90 degrees left or right # returns index of photo to rotate, if any sub _get_rotate_photo_param { my ($self, $c) = @_; - my $params = $c->req->parameters; - my $key = first { /^rotate_photo/ } $c->req->param or return; + my $key = first { /^rotate_photo/ } keys %{ $c->req->params } or return; my ($index) = $key =~ /(\d+)$/; - my $direction = $c->req->param($key); + my $direction = $c->get_param($key); return [ $index || 0, $key, $direction ]; } -- cgit v1.2.3 From 591c90a2ac4ea419a062bf19fffb0831d06786df Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 9 Oct 2015 15:29:05 +0100 Subject: Speed up admin front page. * Don't show a categories summary unless asked via a link * Don't needlessly join in questionnaire/update summaries * Switch count(distinct()) to a subselect as it turns out select count(*) from (select distinct(user_id) from problem) temp; is a lot quicker than select count(distinct(user_id)) from problem; --- perllib/FixMyStreet/App/Controller/Admin.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 39d6ff72f..a61032988 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -129,7 +129,9 @@ sub index : Path : Args(0) { : _('n/a'); $c->stash->{questionnaires} = \%questionnaire_counts; - $c->stash->{categories} = $c->cobrand->problems->categories_summary(); + if ($c->get_param('show_categories')) { + $c->stash->{categories} = $c->cobrand->problems->categories_summary(); + } $c->stash->{total_bodies} = $c->model('DB::Body')->count(); -- cgit v1.2.3