aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
Diffstat (limited to 'perllib')
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm23
-rw-r--r--perllib/FixMyStreet/DB/Result/User.pm21
2 files changed, 29 insertions, 15 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index 4c2d92d5e..6e94547f3 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -548,24 +548,17 @@ sub signup_for_alerts : Private {
my ( $self, $c ) = @_;
my $update = $c->stash->{update};
+ my $user = $update->user;
+ my $problem_id = $update->problem_id;
+
if ( $c->stash->{add_alert} ) {
my $options = {
- user => $update->user,
- alert_type => 'new_updates',
- parameter => $update->problem_id,
+ cobrand => $update->cobrand,
+ cobrand_data => $update->cobrand_data,
+ lang => $update->lang,
};
- my $alert = $c->model('DB::Alert')->find($options);
- unless ($alert) {
- $alert = $c->model('DB::Alert')->create({
- %$options,
- cobrand => $update->cobrand,
- cobrand_data => $update->cobrand_data,
- lang => $update->lang,
- });
- }
- $alert->confirm();
-
- } elsif ( my $alert = $update->user->alert_for_problem($update->problem_id) ) {
+ $user->create_alert($problem_id, $options);
+ } elsif ( my $alert = $user->alert_for_problem($problem_id) ) {
$alert->disable();
}
diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm
index cf6de9a76..8385d2eea 100644
--- a/perllib/FixMyStreet/DB/Result/User.pm
+++ b/perllib/FixMyStreet/DB/Result/User.pm
@@ -204,6 +204,27 @@ sub alert_for_problem {
} );
}
+=head2 create_alert
+
+Sign a user up to receive alerts on a given problem
+
+=cut
+
+sub create_alert {
+ my ( $self, $id, $options ) = @_;
+ my $alert = $self->alert_for_problem($id);
+
+ unless ( $alert ) {
+ $alert = $self->alerts->create({
+ %$options,
+ alert_type => 'new_updates',
+ parameter => $id,
+ });
+ }
+
+ $alert->confirm();
+}
+
sub body {
my $self = shift;
return '' unless $self->from_body;