aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB/Result/User.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2016-10-06 14:10:23 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2016-10-11 16:17:32 +0100
commit662b96c2539ec4f61d7ae84b07bb8cebdae02741 (patch)
tree1519e4a912fdc839a0246020d9651ba3561ad026 /perllib/FixMyStreet/DB/Result/User.pm
parente1038dac8f5ba0fe2f20781468b3cbe763b7ed68 (diff)
Adding report to shortlist removes from others.
Diffstat (limited to 'perllib/FixMyStreet/DB/Result/User.pm')
-rw-r--r--perllib/FixMyStreet/DB/Result/User.pm15
1 files changed, 10 insertions, 5 deletions
diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm
index 7aa7a3272..7ec49b074 100644
--- a/perllib/FixMyStreet/DB/Result/User.pm
+++ b/perllib/FixMyStreet/DB/Result/User.pm
@@ -351,11 +351,18 @@ sub adopt {
# Planned reports / shortlist
-# Override the default auto-created function as we only want one live entry per user
+# Override the default auto-created function as we only want one live entry so
+# we need to delete it anywhere else and return an existing one if present.
around add_to_planned_reports => sub {
my ( $orig, $self ) = ( shift, shift );
my ( $report_col ) = @_;
- my $existing = $self->user_planned_reports->search_rs({ report_id => $report_col->id, removed => undef })->first;
+
+ $self->result_source->schema->resultset("UserPlannedReport")
+ ->active
+ ->for_report($report_col->id)
+ ->search_rs({ user_id => { '!=', $self->id } })
+ ->remove();
+ my $existing = $self->user_planned_reports->active->for_report($report_col->id)->first;
return $existing if $existing;
return $self->$orig(@_);
};
@@ -363,9 +370,7 @@ around add_to_planned_reports => sub {
# Override the default auto-created function as we don't want to ever delete anything
around remove_from_planned_reports => sub {
my ($orig, $self, $report) = @_;
- $self->user_planned_reports
- ->search_rs({ report_id => $report->id, removed => undef })
- ->update({ removed => \'current_timestamp' });
+ $self->user_planned_reports->active->for_report($report->id)->remove();
};
sub active_planned_reports {