diff options
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/AlertType.pm | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm index 32654e534..26d8f32a9 100644 --- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm +++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm @@ -65,6 +65,8 @@ sub email_alerts ($) { # call checks if this is the host that sends mail for this cobrand. next unless $cobrand->email_host; + my ( $sql_restriction, $name_restictions, $hashref_restriction ) = $cobrand->site_restriction( $row->{cobrand_data} ); + FixMyStreet::App->model('DB::AlertSent')->create( { alert_id => $row->{alert_id}, parameter => $row->{item_id}, @@ -84,6 +86,9 @@ sub email_alerts ($) { } my $url = $cobrand->base_url_for_emails( $row->{alert_cobrand_data} ); + if ( $hashref_restriction && $hashref_restriction->{council} && $row->{council} ne $hashref_restriction->{council} ) { + $url = mySociety::Config::get('BASE_URL'); + } # this is currently only for new_updates if ($row->{item_text}) { $data{problem_url} = $url . "/report/" . $row->{id}; @@ -136,8 +141,7 @@ sub email_alerts ($) { my $longitude = $alert->parameter; my $latitude = $alert->parameter2; - my $url = $cobrand->base_url_for_emails( $alert->cobrand_data ); - my ($site_restriction, $site_id) = $cobrand->site_restriction( $alert->cobrand_data ); + my ($site_restriction, $site_id, $hashref_restriction) = $cobrand->site_restriction( $alert->cobrand_data ); 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 { @@ -145,14 +149,13 @@ sub email_alerts ($) { }; my $states = "'" . join( "', '", FixMyStreet::DB::Result::Problem::visible_states() ) . "'"; my %data = ( template => $template, data => '', alert_id => $alert->id, alert_email => $alert->user->email, lang => $alert->lang, cobrand => $alert->cobrand, cobrand_data => $alert->cobrand_data ); - my $q = "select problem.id, problem.postcode, problem.geocode, problem.title from problem_find_nearby(?, ?, ?) as nearby, problem, users + my $q = "select problem.id, problem.council, problem.postcode, problem.geocode, problem.title from problem_find_nearby(?, ?, ?) as nearby, problem, users where nearby.problem_id = problem.id and problem.user_id = users.id and problem.state in ($states) and problem.confirmed >= ? and problem.confirmed >= ms_current_timestamp() - '7 days'::interval and (select whenqueued from alert_sent where alert_sent.alert_id = ? and alert_sent.parameter::integer = problem.id) is null and users.email <> ? - $site_restriction order by confirmed desc"; $q = dbh()->prepare($q); $q->execute($latitude, $longitude, $d, $alert->whensubscribed, $alert->id, $alert->user->email); @@ -161,6 +164,10 @@ sub email_alerts ($) { alert_id => $alert->id, parameter => $row->{id}, } ); + my $url = $cobrand->base_url_for_emails( $alert->cobrand_data ); + if ( $hashref_restriction && $hashref_restriction->{council} && $row->{council} ne $hashref_restriction->{council} ) { + $url = mySociety::Config::get('BASE_URL'); + } my $postcode = $cobrand->format_postcode( $row->{postcode} ); $postcode = ", $postcode" if $postcode; $data{data} .= $url . "/report/" . $row->{id} . " - $row->{title}$postcode\n\n"; |