diff options
Diffstat (limited to 'perllib/FixMyStreet/DB/ResultSet')
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Nearby.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 12 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/State.pm | 11 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/User.pm | 35 |
4 files changed, 51 insertions, 11 deletions
diff --git a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm index 8b8951007..6e5e0220f 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm @@ -10,7 +10,7 @@ sub to_body { } sub nearby { - my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $interval, $categories, $states ) = @_; + my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $categories, $states ) = @_; unless ( $states ) { $states = FixMyStreet::DB::Result::Problem->visible_states(); @@ -20,8 +20,6 @@ sub nearby { non_public => 0, state => [ keys %$states ], }; - $params->{'current_timestamp-lastupdate'} = { '<', \"'$interval'::interval" } - if $interval; $params->{id} = { -not_in => $ids } if $ids; $params->{category} = $categories if $categories && @$categories; diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index f1ed50721..ae45351c4 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -140,11 +140,11 @@ sub _recent { # Problems around a location sub around_map { - my ( $rs, $limit, %p) = @_; + my ( $rs, $c, %p) = @_; my $attr = { order_by => $p{order}, }; - $attr->{rows} = $limit if $limit; + $attr->{rows} = $c->cobrand->reports_per_page; unless ( $p{states} ) { $p{states} = FixMyStreet::DB::Result::Problem->visible_states(); @@ -156,12 +156,12 @@ sub around_map { latitude => { '>=', $p{min_lat}, '<', $p{max_lat} }, longitude => { '>=', $p{min_lon}, '<', $p{max_lon} }, }; - $q->{'current_timestamp - lastupdate'} = { '<', \"'$p{interval}'::interval" } - if $p{interval}; $q->{category} = $p{categories} if $p{categories} && @{$p{categories}}; - my @problems = mySociety::Locale::in_gb_locale { $rs->search( $q, $attr )->include_comment_counts->all }; - return \@problems; + my $problems = mySociety::Locale::in_gb_locale { + $rs->search( $q, $attr )->include_comment_counts->page($p{page}); + }; + return $problems; } # Admin functions diff --git a/perllib/FixMyStreet/DB/ResultSet/State.pm b/perllib/FixMyStreet/DB/ResultSet/State.pm index ac13ec2a4..3e6169aeb 100644 --- a/perllib/FixMyStreet/DB/ResultSet/State.pm +++ b/perllib/FixMyStreet/DB/ResultSet/State.pm @@ -24,7 +24,10 @@ sub states { my $rs = shift; my $states = Memcached::get('states'); - if ($states) { + # If tests are run in parallel, the cached state in Memcached could be + # corrupted by multiple tests changing it at the same time + # uncoverable branch true + if ($states && !FixMyStreet->test_mode) { # Need to reattach schema $states->[0]->result_source->schema( $rs->result_source->schema ) if $states->[0]; return $states; @@ -55,7 +58,7 @@ sub fixed { [ $_[0]->_filter(sub { $_->type eq 'fixed' }) ] } # This function can be used to return that label's display name. sub display { - my ($rs, $label, $single_fixed) = @_; + my ($rs, $label, $single_fixed, $cobrand) = @_; my $unchanging = { unconfirmed => _("Unconfirmed"), hidden => _("Hidden"), @@ -69,6 +72,10 @@ sub display { }; $label = 'fixed' if $single_fixed && $label =~ /^fixed - (council|user)$/; return $unchanging->{$label} if $unchanging->{$label}; + if ($cobrand && $label eq 'not responsible') { + return 'third party responsibility' if $cobrand eq 'bromley'; + return _("not the council's responsibility"); + } my ($state) = $rs->_filter(sub { $_->label eq $label }); return $label unless $state; $state->name($translate_now->{$label}) if $translate_now->{$label}; diff --git a/perllib/FixMyStreet/DB/ResultSet/User.pm b/perllib/FixMyStreet/DB/ResultSet/User.pm index 7e657a936..9a8a50559 100644 --- a/perllib/FixMyStreet/DB/ResultSet/User.pm +++ b/perllib/FixMyStreet/DB/ResultSet/User.pm @@ -4,5 +4,40 @@ use base 'DBIx::Class::ResultSet'; use strict; use warnings; +use Moo; + +# The database has a partial unique index on email (when email_verified is +# true), and phone (when phone_verified is true). In the code, we can only +# say these are fully unique indices, which they aren't, as there could be +# multiple identical unverified phone numbers. +# +# We assume that any and all calls to find (also called using find_or_new, +# find_or_create, or update_or_new/create) are to look up verified entries +# only (it would make no sense to find() a non-unique entry). Therefore we +# help the code along by specifying the most appropriate key to use, given +# the data provided, and setting the appropriate verified boolean. + +around find => sub { + my ($orig, $self) = (shift, shift); + # If there's already a key, assume caller knows what they're doing + if (ref $_[0] eq 'HASH' && !$_[1]->{key}) { + if ($_[0]->{id}) { + $_[1]->{key} = 'primary'; + } elsif (exists $_[0]->{email} && exists $_[0]->{phone}) { + # If there's both email and phone, caller must also have specified + # a verified boolean so that we know what we're looking for + if (!$_[0]->{email_verified} && !$_[0]->{phone_verified}) { + die "Cannot perform a User find() with both email and phone and no verified"; + } + } elsif (exists $_[0]->{email}) { + $_[0]->{email_verified} = 1; + $_[1]->{key} = 'users_email_verified_key'; + } elsif (exists $_[0]->{phone}) { + $_[0]->{phone_verified} = 1; + $_[1]->{key} = 'users_phone_verified_key'; + } + } + $self->$orig(@_); +}; 1; |