diff options
Diffstat (limited to 'perllib/FixMyStreet/DB')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/AdminLog.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Alert.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/AlertSent.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Comment.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/ModerationOriginalData.pm | 9 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 13 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Token.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/AlertType.pm | 9 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Comment.pm | 17 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Contact.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Nearby.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 36 |
12 files changed, 74 insertions, 45 deletions
diff --git a/perllib/FixMyStreet/DB/Result/AdminLog.pm b/perllib/FixMyStreet/DB/Result/AdminLog.pm index d26eba7f5..fcf909692 100644 --- a/perllib/FixMyStreet/DB/Result/AdminLog.pm +++ b/perllib/FixMyStreet/DB/Result/AdminLog.pm @@ -31,6 +31,7 @@ __PACKAGE__->add_columns( data_type => "timestamp", default_value => \"current_timestamp", is_nullable => 0, + original => { default_value => \"now()" }, }, "user_id", { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, @@ -51,7 +52,7 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07035 @ 2014-07-31 15:58:54 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:okGiaKaVYaTrlz0LCV01vA +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2015-08-13 16:33:38 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:RCi1FEwb9T2MZ2X+QOTTUA 1; diff --git a/perllib/FixMyStreet/DB/Result/Alert.pm b/perllib/FixMyStreet/DB/Result/Alert.pm index 21010064b..35cce8368 100644 --- a/perllib/FixMyStreet/DB/Result/Alert.pm +++ b/perllib/FixMyStreet/DB/Result/Alert.pm @@ -39,6 +39,7 @@ __PACKAGE__->add_columns( data_type => "timestamp", default_value => \"current_timestamp", is_nullable => 0, + original => { default_value => \"now()" }, }, "whendisabled", { data_type => "timestamp", is_nullable => 1 }, @@ -64,8 +65,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-09-10 17:11:54 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:d9yIFiTGtbtFaULXZNKstQ +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2015-08-13 16:33:38 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:5RNyB430T8PqtFlmGV/MUg # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/perllib/FixMyStreet/DB/Result/AlertSent.pm b/perllib/FixMyStreet/DB/Result/AlertSent.pm index 154f8b42e..83043a33b 100644 --- a/perllib/FixMyStreet/DB/Result/AlertSent.pm +++ b/perllib/FixMyStreet/DB/Result/AlertSent.pm @@ -20,6 +20,7 @@ __PACKAGE__->add_columns( data_type => "timestamp", default_value => \"current_timestamp", is_nullable => 0, + original => { default_value => \"now()" }, }, ); __PACKAGE__->belongs_to( @@ -30,8 +31,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07035 @ 2013-09-10 17:11:54 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:COwsprqRSNZS1IxJrPYgMQ +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2015-08-13 16:33:38 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/+Vodu8VJxJ0EY9P3Qjjjw # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index 0c1072a78..0caaa8968 100644 --- a/perllib/FixMyStreet/DB/Result/Comment.pm +++ b/perllib/FixMyStreet/DB/Result/Comment.pm @@ -33,6 +33,7 @@ __PACKAGE__->add_columns( data_type => "timestamp", default_value => \"current_timestamp", is_nullable => 0, + original => { default_value => \"now()" }, }, "confirmed", { data_type => "timestamp", is_nullable => 1 }, @@ -88,8 +89,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07035 @ 2014-07-31 15:59:43 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:08AtJ6CZFyUe7qKMF50MHg +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2015-08-13 16:33:38 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ZR+YNA1Jej3s+8mr52iq6Q # __PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn"); diff --git a/perllib/FixMyStreet/DB/Result/ModerationOriginalData.pm b/perllib/FixMyStreet/DB/Result/ModerationOriginalData.pm index 13ecf82cd..d7240cd5d 100644 --- a/perllib/FixMyStreet/DB/Result/ModerationOriginalData.pm +++ b/perllib/FixMyStreet/DB/Result/ModerationOriginalData.pm @@ -35,6 +35,7 @@ __PACKAGE__->add_columns( data_type => "timestamp", default_value => \"current_timestamp", is_nullable => 0, + original => { default_value => \"now()" }, }, ); __PACKAGE__->set_primary_key("id"); @@ -46,7 +47,7 @@ __PACKAGE__->belongs_to( { is_deferrable => 0, join_type => "LEFT", - on_delete => "NO ACTION", + on_delete => "CASCADE,", on_update => "NO ACTION", }, ); @@ -54,12 +55,12 @@ __PACKAGE__->belongs_to( "problem", "FixMyStreet::DB::Result::Problem", { id => "problem_id" }, - { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, + { is_deferrable => 0, on_delete => "CASCADE,", on_update => "NO ACTION" }, ); -# Created by DBIx::Class::Schema::Loader v0.07035 @ 2014-07-31 15:59:43 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:yR1Vi7cJQrX67dFwAcJW6w +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2015-08-13 16:33:38 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:DBtGjCJykDtLnGtkj638eA # 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 caf748f1e..88794ee52 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -55,6 +55,7 @@ __PACKAGE__->add_columns( data_type => "timestamp", default_value => \"current_timestamp", is_nullable => 0, + original => { default_value => \"now()" }, }, "confirmed", { data_type => "timestamp", is_nullable => 1 }, @@ -73,6 +74,7 @@ __PACKAGE__->add_columns( data_type => "timestamp", default_value => \"current_timestamp", is_nullable => 0, + original => { default_value => \"now()" }, }, "whensent", { data_type => "timestamp", is_nullable => 1 }, @@ -102,6 +104,8 @@ __PACKAGE__->add_columns( { data_type => "integer", default_value => 0, is_nullable => 1 }, "subcategory", { data_type => "text", is_nullable => 1 }, + "bodies_missing", + { data_type => "text", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->has_many( @@ -130,8 +134,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07035 @ 2014-07-31 15:57:02 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:EvD4sS1mdJJyI1muZ4TrCw +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2015-08-13 16:33:38 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Go+T9oFRfwQ1Ag89qPpF/g # Add fake relationship to stored procedure table __PACKAGE__->has_one( @@ -400,7 +404,7 @@ sub check_for_errors { $errors{bodies} = _('No council selected') unless $self->bodies_str - && $self->bodies_str =~ m/^(?:-1|[\d,]+(?:\|[\d,]+)?)$/; + && $self->bodies_str =~ m/^(?:-1|[\d,]+)$/; if ( !$self->name || $self->name !~ m/\S/ ) { $errors{name} = _('Please enter your name'); @@ -448,8 +452,7 @@ sub confirm { sub bodies_str_ids { my $self = shift; return unless $self->bodies_str; - (my $bodies = $self->bodies_str) =~ s/\|.*$//; - my @bodies = split( /,/, $bodies ); + my @bodies = split( /,/, $self->bodies_str ); return \@bodies; } diff --git a/perllib/FixMyStreet/DB/Result/Token.pm b/perllib/FixMyStreet/DB/Result/Token.pm index 90715bdd9..a60e23839 100644 --- a/perllib/FixMyStreet/DB/Result/Token.pm +++ b/perllib/FixMyStreet/DB/Result/Token.pm @@ -22,13 +22,14 @@ __PACKAGE__->add_columns( data_type => "timestamp", default_value => \"current_timestamp", is_nullable => 0, + original => { default_value => \"now()" }, }, ); __PACKAGE__->set_primary_key("scope", "token"); -# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:+LLZ8P5GXqPetuGyrra2vw +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2015-08-13 16:33:38 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:HkvzOY5STjOdXN64hxg5NA use mySociety::AuthToken; diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm index d2264139a..dde30b59c 100644 --- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm +++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm @@ -70,8 +70,6 @@ sub email_alerts ($) { # this is for the new_updates alerts next if $row->{non_public} and $row->{user_id} != $row->{alert_user_id}; - my $hashref_restriction = $cobrand->site_restriction( $row->{cobrand_data} ); - FixMyStreet::App->model('DB::AlertSent')->create( { alert_id => $row->{alert_id}, parameter => $row->{item_id}, @@ -90,8 +88,9 @@ sub email_alerts ($) { $data{state_message} = _("This report is currently marked as open."); } + my $hashref_restriction = $cobrand->body_restriction; my $url = $cobrand->base_url( $row->{alert_cobrand_data} ); - if ( $hashref_restriction && $hashref_restriction->{bodies_str} && $row->{bodies_str} ne $hashref_restriction->{bodies_str} ) { + if ( $hashref_restriction && $row->{bodies_str} ne $hashref_restriction ) { $url = mySociety::Config::get('BASE_URL'); } # this is currently only for new_updates @@ -172,7 +171,7 @@ sub email_alerts ($) { my $longitude = $alert->parameter; my $latitude = $alert->parameter2; - my $hashref_restriction = $cobrand->site_restriction( $alert->cobrand_data ); + my $hashref_restriction = $cobrand->body_restriction; my $d = mySociety::Gaze::get_radius_containing_population($latitude, $longitude, 200000); # Convert integer to GB locale string (with a ".") $d = mySociety::Locale::in_gb_locale { @@ -197,7 +196,7 @@ sub email_alerts ($) { parameter => $row->{id}, } ); my $url = $cobrand->base_url( $alert->cobrand_data ); - if ( $hashref_restriction && $hashref_restriction->{bodies_str} && $row->{bodies_str} ne $hashref_restriction->{bodies_str} ) { + if ( $hashref_restriction && $row->{bodies_str} ne $hashref_restriction ) { $url = mySociety::Config::get('BASE_URL'); } $data{data} .= $url . "/report/" . $row->{id} . " - $row->{title}\n\n"; diff --git a/perllib/FixMyStreet/DB/ResultSet/Comment.pm b/perllib/FixMyStreet/DB/ResultSet/Comment.pm index abdc46868..270501efc 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Comment.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Comment.pm @@ -4,19 +4,24 @@ use base 'DBIx::Class::ResultSet'; use strict; use warnings; +sub to_body { + my ($rs, $body_restriction) = @_; + return FixMyStreet::DB::ResultSet::Problem::to_body($rs, $body_restriction); +} + + sub timeline { - my ( $rs, $restriction ) = @_; + my ( $rs, $body_restriction ) = @_; my $prefetch = FixMyStreet::App->model('DB')->schema->storage->sql_maker->quote_char ? [ qw/user/ ] : []; - return $rs->search( + return $rs->to_body($body_restriction)->search( { state => 'confirmed', created => { '>=', \"current_timestamp-'7 days'::interval" }, - %{ $restriction }, }, { prefetch => $prefetch, @@ -25,10 +30,10 @@ sub timeline { } sub summary_count { - my ( $rs, $restriction ) = @_; + my ( $rs, $body_restriction ) = @_; - return $rs->search( - $restriction, + return $rs->to_body($body_restriction)->search( + undef, { group_by => ['me.state'], select => [ 'me.state', { count => 'me.id' } ], diff --git a/perllib/FixMyStreet/DB/ResultSet/Contact.pm b/perllib/FixMyStreet/DB/ResultSet/Contact.pm index 6fa6a03a0..f402b5461 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Contact.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Contact.pm @@ -4,6 +4,8 @@ use base 'DBIx::Class::ResultSet'; use strict; use warnings; +sub me { join('.', shift->current_source_alias, shift || q{}) } + =head2 not_deleted $rs = $rs->not_deleted(); @@ -14,7 +16,7 @@ Filter down to not deleted contacts - which have C<deleted> set to false; sub not_deleted { my $rs = shift; - return $rs->search( { deleted => 0 } ); + return $rs->search( { $rs->me('deleted') => 0 } ); } sub summary_count { diff --git a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm index 670673ab3..a6b00ef7b 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm @@ -19,12 +19,10 @@ sub nearby { if $interval; $params->{id} = { -not_in => $ids } if $ids; - $params = { - %{ $c->cobrand->problems_clause }, - %$params - } if $c->cobrand->problems_clause; $params->{category} = $category if $category; + $rs = FixMyStreet::DB::ResultSet::Problem::to_body($rs, $c->cobrand->body_restriction); + my $attrs = { prefetch => 'problem', bind => [ $mid_lat, $mid_lon, $dist ], diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 0aa7c8b3a..8f0d23080 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -20,6 +20,18 @@ sub set_restriction { $site_key = $key; } +sub to_body { + my ($rs, $bodies) = @_; + return $rs unless $bodies; + unless (ref $bodies eq 'ARRAY') { + $bodies = [ map { ref $_ ? $_->id : $_ } $bodies ]; + } + $rs = $rs->search( + \[ "regexp_split_to_array(bodies_str, ',') && ?", [ {} => $bodies ] ] + ); + return $rs; +} + # Front page statistics sub recent_fixed { @@ -236,7 +248,7 @@ sub send_reports { my $states = [ 'confirmed', 'fixed' ]; $states = [ 'unconfirmed', 'confirmed', 'in progress', 'planned', 'closed' ] if $site eq 'zurich'; - my $unsent = FixMyStreet::App->model("DB::Problem")->search( { + my $unsent = $rs->search( { state => $states, whensent => undef, bodies_str => { '!=', undef }, @@ -320,15 +332,19 @@ sub send_reports { $cobrand->process_additional_metadata_for_email($row, \%h); } - # XXX Needs locks! - # XXX Only copes with at most one missing body - my ($bodies, $missing) = $row->bodies_str =~ /^([\d,]+)(?:\|(\d+))?/; - my @bodies = split(/,/, $bodies); - $bodies = FixMyStreet::App->model("DB::Body")->search( - { id => \@bodies }, + my $bodies = FixMyStreet::App->model("DB::Body")->search( + { id => $row->bodies_str_ids }, { order_by => 'name' }, ); - $missing = FixMyStreet::App->model("DB::Body")->find($missing) if $missing; + + my $missing; + if ($row->bodies_missing) { + my @missing = FixMyStreet::App->model("DB::Body")->search( + { id => [ split /,/, $row->bodies_missing ] }, + { order_by => 'name' } + )->get_column('name')->all; + $missing = join(' / ', @missing) if @missing; + } my @dear; my %reporters = (); @@ -400,7 +416,7 @@ sub send_reports { $h{missing} = ''; if ($missing) { $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.'), $missing->name) + . 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.'), $missing) . " ]\n\n"; } @@ -468,7 +484,7 @@ sub send_reports { } } my $sending_errors = ''; - my $unsent = FixMyStreet::App->model("DB::Problem")->search( { + my $unsent = $rs->search( { state => [ 'confirmed', 'fixed' ], whensent => undef, bodies_str => { '!=', undef }, |