diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-10-13 17:49:04 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-10-13 17:49:04 +0100 |
commit | 8ab9812e6cd5f686f7ab4d9a9859e8be4456ccd0 (patch) | |
tree | 5bf1a9d25d2707a70c023a8aa53cf01cbe2f8d71 /perllib/FixMyStreet/DB/Result/User.pm | |
parent | 9fc69a31cda118948e3714bc7f4fff9d0a3ca84e (diff) | |
parent | b86c2142d2f82fb503807feae0a8df4b8af39571 (diff) |
Merge branch 'issues/forcouncils/86-show-shortlist-reports'
Diffstat (limited to 'perllib/FixMyStreet/DB/Result/User.pm')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index 8d42d5926..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 { |