diff options
-rw-r--r-- | perllib/FixMyStreet/Cobrand/TfL.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/Script/Inactive.pm | 1 | ||||
-rw-r--r-- | t/script/inactive.t | 29 |
3 files changed, 40 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/Cobrand/TfL.pm b/perllib/FixMyStreet/Cobrand/TfL.pm index eedbc41b5..cc4b4f345 100644 --- a/perllib/FixMyStreet/Cobrand/TfL.pm +++ b/perllib/FixMyStreet/Cobrand/TfL.pm @@ -127,6 +127,16 @@ sub problems_sql_restriction { return $q; } +sub inactive_reports_filter { + my ($self, $time, $rs) = @_; + if ($time < 7*12) { + $rs = $rs->search({ extra => { like => '%safety_critical,T5:value,T2:no%' } }); + } else { + $rs = $rs->search({ extra => { like => '%safety_critical,T5:value,T3:yes%' } }); + } + return $rs; +} + sub password_expiry { return if FixMyStreet->test_mode; # uncoverable statement diff --git a/perllib/FixMyStreet/Script/Inactive.pm b/perllib/FixMyStreet/Script/Inactive.pm index 54cbaa7ad..e09417648 100644 --- a/perllib/FixMyStreet/Script/Inactive.pm +++ b/perllib/FixMyStreet/Script/Inactive.pm @@ -95,6 +95,7 @@ sub _relevant_reports { }); if ($self->cobrand) { $problems = $problems->search({ cobrand => $self->cobrand->moniker }); + $problems = $self->cobrand->call_hook(inactive_reports_filter => $time, $problems) || $problems; } return $problems; } diff --git a/t/script/inactive.t b/t/script/inactive.t index 26eab33e1..5ef4073dd 100644 --- a/t/script/inactive.t +++ b/t/script/inactive.t @@ -109,4 +109,33 @@ subtest 'Anonymization of inactive users' => sub { is $user->email, 'removed-' . $user->id . '@example.org', 'User has been anonymized'; }; +subtest 'Test TfL deletion of safety critical reports' => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => 'tfl' + }, sub { + for (my $y = 2; $y <= 10; $y+=2) { + # 2 years, not safety; 4 years safety, 6 years not safety, 8 years safety, 10 years not safety + my $t = DateTime->now->subtract(years => $y); + my ($problem) = $mech->create_problems_for_body(1, 2237, 'Title', { + dt => $t, + lastupdate => "$t", + state => 'fixed - user', + cobrand => 'tfl', + }); + $problem->update_extra_field({ name => 'safety_critical', value => $y % 4 ? 'no' : 'yes' }); + $problem->update; + } + + my $in = FixMyStreet::Script::Inactive->new( cobrand => 'tfl', delete => 36 ); + $in->reports; + my $count = FixMyStreet::DB->resultset("Problem")->search({ cobrand => 'tfl' })->count; + is $count, 3, 'Three reports left, one too recent, two safety critical'; + + $in = FixMyStreet::Script::Inactive->new( cobrand => 'tfl', delete => 84 ); + $in->reports; + $count = FixMyStreet::DB->resultset("Problem")->search({ cobrand => 'tfl' })->count; + is $count, 2, 'Two reports left, two too recent'; + } +}; + done_testing; |