diff options
Diffstat (limited to 'perllib/FixMyStreet/DB/ResultSet')
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/AlertType.pm | 18 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 51 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm | 2 |
3 files changed, 33 insertions, 38 deletions
diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm index 26d8f32a9..a0320ccc3 100644 --- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm +++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm @@ -65,7 +65,7 @@ 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} ); + my $hashref_restriction = $cobrand->site_restriction( $row->{cobrand_data} ); FixMyStreet::App->model('DB::AlertSent')->create( { alert_id => $row->{alert_id}, @@ -85,7 +85,7 @@ sub email_alerts ($) { $data{state_message} = _("This report is currently marked as open."); } - my $url = $cobrand->base_url_for_emails( $row->{alert_cobrand_data} ); + my $url = $cobrand->base_url( $row->{alert_cobrand_data} ); if ( $hashref_restriction && $hashref_restriction->{council} && $row->{council} ne $hashref_restriction->{council} ) { $url = mySociety::Config::get('BASE_URL'); } @@ -96,9 +96,7 @@ sub email_alerts ($) { $data{data} .= $row->{item_text} . "\n\n------\n\n"; # this is ward and council problems } else { - my $postcode = $cobrand->format_postcode( $row->{postcode} ); - $postcode = ", $postcode" if $postcode; - $data{data} .= $url . "/report/" . $row->{id} . " - $row->{title}$postcode\n\n"; + $data{data} .= $url . "/report/" . $row->{id} . " - $row->{title}\n\n"; if ( exists $row->{geocode} && $row->{geocode} && $ref =~ /ward|council/ ) { my $nearest_st = _get_address_from_gecode( $row->{geocode} ); $data{data} .= $nearest_st if $nearest_st; @@ -141,7 +139,7 @@ sub email_alerts ($) { my $longitude = $alert->parameter; my $latitude = $alert->parameter2; - my ($site_restriction, $site_id, $hashref_restriction) = $cobrand->site_restriction( $alert->cobrand_data ); + my $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 { @@ -164,13 +162,11 @@ sub email_alerts ($) { alert_id => $alert->id, parameter => $row->{id}, } ); - my $url = $cobrand->base_url_for_emails( $alert->cobrand_data ); + my $url = $cobrand->base_url( $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"; + $data{data} .= $url . "/report/" . $row->{id} . " - $row->{title}\n\n"; if ( exists $row->{geocode} && $row->{geocode} ) { my $nearest_st = _get_address_from_gecode( $row->{geocode} ); $data{data} .= $nearest_st if $nearest_st; @@ -203,7 +199,7 @@ sub _send_aggregated_alert_email(%) { email => $data{alert_email}, } } ); - $data{unsubscribe_url} = $cobrand->base_url_for_emails( $data{cobrand_data} ) . '/A/' . $token->token; + $data{unsubscribe_url} = $cobrand->base_url( $data{cobrand_data} ) . '/A/' . $token->token; my $template = FixMyStreet->path_to( "templates", "email", $cobrand->moniker, $data{lang}, "$data{template}.txt" diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index a7738becf..bac367b87 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -14,13 +14,11 @@ use mySociety::MaPit; use FixMyStreet::App; use FixMyStreet::SendReport; -my $site_restriction; my $site_key; sub set_restriction { - my ( $rs, $sql, $key, $restriction ) = @_; + my ( $rs, $key ) = @_; $site_key = $key; - $site_restriction = $restriction; } # Front page statistics @@ -252,13 +250,13 @@ sub send_reports { } # Template variables for the email - my $email_base_url = $cobrand->base_url_for_emails($row->cobrand_data); + my $email_base_url = $cobrand->base_url_for_report($row); my %h = map { $_ => $row->$_ } qw/id title detail name category latitude longitude used_map/; map { $h{$_} = $row->user->$_ } qw/email phone/; $h{confirmed} = DateTime::Format::Pg->format_datetime( $row->confirmed->truncate (to => 'second' ) ); $h{query} = $row->postcode; - $h{url} = $email_base_url . '/report/' . $row->id; + $h{url} = $email_base_url . $row->url; $h{phone_line} = $h{phone} ? _('Phone:') . " $h{phone}\n\n" : ''; if ($row->photo) { $h{has_photo} = _("This web page also contains a photo of the problem, provided by the user.") . "\n\n"; @@ -289,16 +287,14 @@ sub send_reports { } my %reporters = (); - my (@to, @recips, $template, $areas_info, $sender_count ); + my ( $sender_count ); if ($site eq 'emptyhomes') { my $council = $row->council; - $areas_info = mySociety::MaPit::call('areas', $council); - my $name = $areas_info->{$council}->{name}; + my $areas_info = mySociety::MaPit::call('areas', $council); my $sender = "FixMyStreet::SendReport::EmptyHomes"; $reporters{ $sender } = $sender->new() unless $reporters{$sender}; - $reporters{ $sender }->add_council( $council, $name ); - $template = Utils::read_file("$FindBin::Bin/../templates/email/emptyhomes/" . $row->lang . "/submit.txt"); + $reporters{ $sender }->add_council( $council, $areas_info->{$council} ); } else { @@ -306,7 +302,7 @@ sub send_reports { my @all_councils = split /,|\|/, $row->council; my ($councils, $missing) = $row->council =~ /^([\d,]+)(?:\|([\d,]+))?/; my @councils = split(/,/, $councils); - $areas_info = mySociety::MaPit::call('areas', \@all_councils); + my $areas_info = mySociety::MaPit::call('areas', \@all_councils); my @dear; foreach my $council (@councils) { @@ -326,17 +322,10 @@ sub send_reports { $reporters{ $sender }->skipped; } else { push @dear, $name; - $reporters{ $sender }->add_council( $council, $name ); + $reporters{ $sender }->add_council( $council, $areas_info->{$council} ); } } - $template = 'submit.txt'; - $template = 'submit-brent.txt' if $row->council eq 2488 || $row->council eq 2237; - my $template_path = FixMyStreet->path_to( "templates", "email", $cobrand->moniker, $template )->stringify; - $template_path = FixMyStreet->path_to( "templates", "email", "default", $template )->stringify - unless -e $template_path; - $template = Utils::read_file( $template_path ); - if ($h{category} eq _('Other')) { $h{category_footer} = _('this type of local problem'); $h{category_line} = ''; @@ -374,9 +363,10 @@ sub send_reports { # on a staging server send emails to ourselves rather than the councils my @testing_councils = split( '\|', mySociety::Config::get('TESTING_COUNCILS') ); unless ( grep { $row->council eq $_ } @testing_councils ) { - %reporters = ( - 'FixMyStreet::SendReport::Email' => $reporters{ 'FixMyStreet::SendReport::Email' } || FixMyStreet::SendReport::Email->new() - ); + %reporters = map { $_ => $reporters{$_} } grep { /FixMyStreet::SendReport::(Email|NI)/ } keys %reporters; + unless (%reporters) { + %reporters = ( 'FixMyStreet::SendReport::Email' => FixMyStreet::SendReport::Email->new() ); + } } } @@ -384,9 +374,18 @@ sub send_reports { my $result = -1; for my $sender ( keys %reporters ) { - $result *= $reporters{ $sender }->send( - $row, \%h, \@to, $template, \@recips, $nomail, $areas_info - ); + $result *= $reporters{ $sender }->send( $row, \%h ); + if ( $reporters{ $sender }->unconfirmed_counts) { + foreach my $e (keys %{ $reporters{ $sender }->unconfirmed_counts } ) { + foreach my $c (keys %{ $reporters{ $sender }->unconfirmed_counts->{$e} }) { + $notgot{$e}{$c} += $reporters{ $sender }->unconfirmed_counts->{$e}{$c}; + } + } + %note = ( + %note, + %{ $reporters{ $sender }->unconfirmed_notes } + ); + } } if ($result == mySociety::EmailUtil::EMAIL_SUCCESS) { @@ -409,7 +408,7 @@ sub send_reports { print "Council email addresses that need checking:\n" if keys %notgot; foreach my $e (keys %notgot) { foreach my $c (keys %{$notgot{$e}}) { - print $notgot{$e}{$c} . " problem, to $e category $c (" . $note{$e}{$c}. ")\n"; + print " " . $notgot{$e}{$c} . " problem, to $e category $c (" . $note{$e}{$c}. ")\n"; } } if (keys %sending_skipped_by_method) { diff --git a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm index 753eb2084..bbf0c9a9e 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm @@ -85,7 +85,7 @@ sub send_questionnaires_period { scope => 'questionnaire', data => $questionnaire->id, } ); - $h{url} = $cobrand->base_url_for_emails($row->cobrand_data) . '/Q/' . $token->token; + $h{url} = $cobrand->base_url($row->cobrand_data) . '/Q/' . $token->token; my $sender = $cobrand->contact_email; my $sender_name = _($cobrand->contact_name); |