From 1f83e1aec0128a2cc52d220e5eae2c2b2fad5122 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 2 May 2017 10:33:36 +0100 Subject: Tidy up find_closest* functions. Allow find_closest to be called multiple times with only one lookup, and to return just its data, not a compiled string. --- perllib/FixMyStreet/Script/Alerts.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'perllib/FixMyStreet/Script/Alerts.pm') diff --git a/perllib/FixMyStreet/Script/Alerts.pm b/perllib/FixMyStreet/Script/Alerts.pm index 1a760a0c1..56550563e 100644 --- a/perllib/FixMyStreet/Script/Alerts.pm +++ b/perllib/FixMyStreet/Script/Alerts.pm @@ -143,7 +143,7 @@ sub send() { # this is ward and council problems } else { if ( exists $row->{geocode} && $row->{geocode} && $ref =~ /ward|council/ ) { - my $nearest_st = _get_address_from_gecode( $row->{geocode} ); + my $nearest_st = _get_address_from_geocode( $row->{geocode} ); $row->{nearest} = $nearest_st; } @@ -236,7 +236,7 @@ sub send() { parameter => $row->{id}, } ); if ( exists $row->{geocode} && $row->{geocode} ) { - my $nearest_st = _get_address_from_gecode( $row->{geocode} ); + my $nearest_st = _get_address_from_geocode( $row->{geocode} ); $row->{nearest} = $nearest_st; } my $dt = $parser->parse_timestamp( $row->{confirmed} ); @@ -304,7 +304,7 @@ sub _send_aggregated_alert_email(%) { } } -sub _get_address_from_gecode { +sub _get_address_from_geocode { my $geocode = shift; return '' unless defined $geocode; -- cgit v1.2.3 From a5f311e5147621f285cf31647ce675c502095882 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Sat, 10 Jun 2017 10:40:52 +0100 Subject: Remove final use of old DBHandle. --- perllib/FixMyStreet/Script/Alerts.pm | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'perllib/FixMyStreet/Script/Alerts.pm') diff --git a/perllib/FixMyStreet/Script/Alerts.pm b/perllib/FixMyStreet/Script/Alerts.pm index 56550563e..ef1bdb08b 100644 --- a/perllib/FixMyStreet/Script/Alerts.pm +++ b/perllib/FixMyStreet/Script/Alerts.pm @@ -6,7 +6,6 @@ use warnings; use DateTime::Format::Pg; use IO::String; -use mySociety::DBHandle qw(dbh); use FixMyStreet::Gaze; use mySociety::Locale; use mySociety::MaPit; @@ -18,8 +17,6 @@ use FixMyStreet::Email; use FixMyStreet::Map; use FixMyStreet::App::Model::PhotoSet; -FixMyStreet->configure_mysociety_dbhandle; - my $parser = DateTime::Format::Pg->new(); # Child must have confirmed, id, email, state(!) columns @@ -65,7 +62,7 @@ sub send() { $query =~ s/\?/alert.parameter/ if ($query =~ /\?/); $query =~ s/\?/alert.parameter2/ if ($query =~ /\?/); - $query = dbh()->prepare($query); + $query = FixMyStreet::DB->storage->dbh->prepare($query); $query->execute(); my $last_alert_id; my %data = ( template => $alert_type->template, data => [], schema => $schema ); @@ -228,7 +225,7 @@ sub send() { and (select whenqueued from alert_sent where alert_sent.alert_id = ? and alert_sent.parameter::integer = problem.id) is null and users.email <> ? order by confirmed desc"; - $q = dbh()->prepare($q); + $q = FixMyStreet::DB->storage->dbh->prepare($q); $q->execute($latitude, $longitude, $d, $alert->whensubscribed, $alert->id, $alert->user->email); while (my $row = $q->fetchrow_hashref) { $schema->resultset('AlertSent')->create( { -- cgit v1.2.3 From e00c75d7f19bc45879c254ea77dce32df825f3a7 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 13 Jul 2017 09:51:00 +0100 Subject: Move FixMyStreet::DB to FixMyStreet::DB::Schema. Store a schema object on FixMyStreet::DB instead. --- perllib/FixMyStreet/Script/Alerts.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/Script/Alerts.pm') diff --git a/perllib/FixMyStreet/Script/Alerts.pm b/perllib/FixMyStreet/Script/Alerts.pm index ef1bdb08b..aefe13318 100644 --- a/perllib/FixMyStreet/Script/Alerts.pm +++ b/perllib/FixMyStreet/Script/Alerts.pm @@ -62,7 +62,7 @@ sub send() { $query =~ s/\?/alert.parameter/ if ($query =~ /\?/); $query =~ s/\?/alert.parameter2/ if ($query =~ /\?/); - $query = FixMyStreet::DB->storage->dbh->prepare($query); + $query = FixMyStreet::DB->schema->storage->dbh->prepare($query); $query->execute(); my $last_alert_id; my %data = ( template => $alert_type->template, data => [], schema => $schema ); @@ -225,7 +225,7 @@ sub send() { and (select whenqueued from alert_sent where alert_sent.alert_id = ? and alert_sent.parameter::integer = problem.id) is null and users.email <> ? order by confirmed desc"; - $q = FixMyStreet::DB->storage->dbh->prepare($q); + $q = FixMyStreet::DB->schema->storage->dbh->prepare($q); $q->execute($latitude, $longitude, $d, $alert->whensubscribed, $alert->id, $alert->user->email); while (my $row = $q->fetchrow_hashref) { $schema->resultset('AlertSent')->create( { -- cgit v1.2.3 From 22dd06a50f24df15f782e0e4a327b0d0685e793d Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Tue, 22 Aug 2017 17:29:35 +0100 Subject: Fix missing URLs in alert emails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a staff user changed a problem’s state and an empty update was generated, it was possible for alert emails to be sent with missing URLs because the empty string in the update text was falsy and Alert.pm took the wrong path. This fixes the problem by changing the test to defined() and includes a regression test. --- perllib/FixMyStreet/Script/Alerts.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/Script/Alerts.pm') diff --git a/perllib/FixMyStreet/Script/Alerts.pm b/perllib/FixMyStreet/Script/Alerts.pm index aefe13318..c001cc311 100644 --- a/perllib/FixMyStreet/Script/Alerts.pm +++ b/perllib/FixMyStreet/Script/Alerts.pm @@ -102,7 +102,7 @@ sub send() { my $url = $cobrand->base_url_for_report($row); # this is currently only for new_updates - if ($row->{item_text}) { + if (defined($row->{item_text})) { if ( $cobrand->moniker ne 'zurich' && $row->{alert_user_id} == $row->{user_id} ) { # This is an alert to the same user who made the report - make this a login link # Don't bother with Zurich which has no accounts -- cgit v1.2.3