aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
authorHakim Cassimally <hakim@mysociety.org>2014-07-11 13:57:02 +0000
committerHakim Cassimally <hakim@mysociety.org>2014-08-14 09:44:36 +0000
commitf16060fa322a4230a5b16a1e8c5b122307f29bee (patch)
treefb20f19916dd741cbc484528c9ecc619034cef6f /perllib
parent8d97bff0663729b2abea6f7a38a547515cb23f9a (diff)
refactor repeat code into get_email_template
Diffstat (limited to 'perllib')
-rw-r--r--perllib/FixMyStreet.pm17
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/AlertType.pm9
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm8
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm7
-rw-r--r--perllib/FixMyStreet/SendReport/Email.pm8
5 files changed, 22 insertions, 27 deletions
diff --git a/perllib/FixMyStreet.pm b/perllib/FixMyStreet.pm
index 34c7bfe21..f3b72c4d0 100644
--- a/perllib/FixMyStreet.pm
+++ b/perllib/FixMyStreet.pm
@@ -200,4 +200,21 @@ sub configure_mysociety_dbhandle {
}
+=head2 get_email_template
+
+=cut
+
+sub get_email_template {
+ # TODO further refactor this by just using Template path
+ my ($class, $cobrand, $lang, $template) = @_;
+
+ my $template_path = FixMyStreet->path_to( "templates", "email", $cobrand, $lang, $template )->stringify;
+ $template_path = FixMyStreet->path_to( "templates", "email", $cobrand, $template )->stringify
+ unless -e $template_path;
+ $template_path = FixMyStreet->path_to( "templates", "email", "default", $template )->stringify
+ unless -e $template_path;
+ $template = Utils::read_file( $template_path );
+ return $template;
+}
+
1;
diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
index 984e698e0..5bed95811 100644
--- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
@@ -251,14 +251,7 @@ sub _send_aggregated_alert_email(%) {
} );
$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"
- )->stringify;
- $template = FixMyStreet->path_to( "templates", "email", $cobrand->moniker, "$data{template}.txt" )->stringify
- unless -e $template;
- $template = FixMyStreet->path_to( "templates", "email", "default", "$data{template}.txt" )->stringify
- unless -e $template;
- $template = Utils::read_file($template);
+ my $template = FixMyStreet->get_email_template($cobrand->moniker, $data{lang}, "$data{template}.txt");
my $sender = FixMyStreet->config('DO_NOT_REPLY_EMAIL');
my $result = FixMyStreet::App->send_email_cron(
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index 2f4bc6363..5d70bf47d 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -495,13 +495,7 @@ sub _send_report_sent_email {
my $nomail = shift;
my $cobrand = shift;
- my $template = 'confirm_report_sent.txt';
- my $template_path = FixMyStreet->path_to( "templates", "email", $row->cobrand, $row->lang, $template )->stringify;
- $template_path = FixMyStreet->path_to( "templates", "email", $row->cobrand, $template )->stringify
- unless -e $template_path;
- $template_path = FixMyStreet->path_to( "templates", "email", "default", $template )->stringify
- unless -e $template_path;
- $template = Utils::read_file( $template_path );
+ my $template = FixMyStreet->get_email_template($row->cobrand, $row->lang, 'confirm_report_sent.txt');
my $result = FixMyStreet::App->send_email_cron(
{
diff --git a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
index 64ba8ec6a..b7af9e60e 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
@@ -63,12 +63,7 @@ sub send_questionnaires_period {
($template = $period) =~ s/ //;
$template = Utils::read_file( FixMyStreet->path_to( "templates/email/emptyhomes/" . $row->lang . "/questionnaire-$template.txt" )->stringify );
} else {
- $template = FixMyStreet->path_to( "templates", "email", $cobrand->moniker, $row->lang, "questionnaire.txt" )->stringify;
- $template = FixMyStreet->path_to( "templates", "email", $cobrand->moniker, "questionnaire.txt" )->stringify
- unless -e $template;
- $template = FixMyStreet->path_to( "templates", "email", "default", "questionnaire.txt" )->stringify
- unless -e $template;
- $template = Utils::read_file( $template );
+ $template = FixMyStreet->get_email_template($cobrand->moniker, $row->lang, 'questionnaire.txt');
}
my %h = map { $_ => $row->$_ } qw/name title detail category/;
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm
index d71700020..2eb6bc279 100644
--- a/perllib/FixMyStreet/SendReport/Email.pm
+++ b/perllib/FixMyStreet/SendReport/Email.pm
@@ -62,12 +62,8 @@ sub get_template {
my $template = 'submit.txt';
$template = 'submit-brent.txt' if $row->bodies_str eq 2488 || $row->bodies_str eq 2237;
- my $template_path = FixMyStreet->path_to( "templates", "email", $row->cobrand, $row->lang, $template )->stringify;
- $template_path = FixMyStreet->path_to( "templates", "email", $row->cobrand, $template )->stringify
- unless -e $template_path;
- $template_path = FixMyStreet->path_to( "templates", "email", "default", $template )->stringify
- unless -e $template_path;
- $template = Utils::read_file( $template_path );
+
+ $template = FixMyStreet->get_email_template($row->cobrand, $row->lang, $template);
return $template;
}