aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2020-01-08 16:16:18 +0000
committerMatthew Somerville <matthew@mysociety.org>2020-01-09 17:31:45 +0000
commit73a6134c4bb8c29e2755cf7241524dc0538a4a6a (patch)
treeb1b8cc7188a46ebc8b54b5fb510f04511c865135
parenta47cdf03631855fd83866b932161eaa8ccf0c8b5 (diff)
[Inactive] Add option to only act on one cobrand.
-rwxr-xr-xbin/process-inactive-reports5
-rw-r--r--perllib/FixMyStreet/Script/Inactive.pm40
-rw-r--r--t/script/inactive.t25
3 files changed, 49 insertions, 21 deletions
diff --git a/bin/process-inactive-reports b/bin/process-inactive-reports
index c79b401a3..f1e9af2eb 100755
--- a/bin/process-inactive-reports
+++ b/bin/process-inactive-reports
@@ -15,7 +15,7 @@ use FixMyStreet::Script::Inactive;
use Pod::Usage;
my %h;
-GetOptions(\%h, 'anonymize=i', 'close=i', 'delete=i', 'verbose|v', 'help|h', 'dry-run|n');
+GetOptions(\%h, 'anonymize=i', 'close=i', 'delete=i', 'cobrand=s', 'verbose|v', 'help|h', 'dry-run|n');
pod2usage(0) if $h{help};
pod2usage(1) unless $h{anonymize} || $h{close} || $h{delete};
@@ -29,12 +29,13 @@ process-inactive-reports - deal with anonymizing inactive non-open reports
=head1 SYNOPSIS
-process-inactive-reports [--anonymize N] [--close N] [--delete N]
+process-inactive-reports [--anonymize N] [--close N] [--delete N] [--cobrand COBRAND]
Options:
--anonymize Anonymize non-open reports (and related) inactive longer than this time (months)
--close Close comments on non-open reports inactive longer than this time (months)
--delete Delete non-open reports inactive longer than this time (months)
+ --cobrand Only act upon reports made on this cobrand
--dry-run Don't actually anonymize anything or send any emails
--verbose Output as to which reports are being affected
--help This help message
diff --git a/perllib/FixMyStreet/Script/Inactive.pm b/perllib/FixMyStreet/Script/Inactive.pm
index bfe746a68..54cbaa7ad 100644
--- a/perllib/FixMyStreet/Script/Inactive.pm
+++ b/perllib/FixMyStreet/Script/Inactive.pm
@@ -17,13 +17,18 @@ has email => ( is => 'ro' );
has verbose => ( is => 'ro' );
has dry_run => ( is => 'ro' );
+has cobrand => (
+ is => 'ro',
+ coerce => sub { FixMyStreet::Cobrand->get_class_for_moniker($_[0])->new },
+);
+
sub BUILDARGS {
my ($cls, %args) = @_;
$args{dry_run} = delete $args{'dry-run'};
return \%args;
}
-has cobrand => (
+has base_cobrand => (
is => 'lazy',
default => sub {
my $base_url = FixMyStreet->config('BASE_URL');
@@ -68,6 +73,7 @@ sub close_updates {
state => [ FixMyStreet::DB::Result::Problem->closed_states(), FixMyStreet::DB::Result::Problem->fixed_states() ],
extra => [ undef, { -not_like => '%closed_updates%' } ],
});
+ $problems = $problems->search({ cobrand => $self->cobrand->moniker }) if $self->cobrand;
while (my $problem = $problems->next) {
say "Closing updates on problem #" . $problem->id if $self->verbose;
@@ -77,18 +83,27 @@ sub close_updates {
}
}
-sub anonymize_reports {
- my $self = shift;
-
- # Need to look though them all each time, in case any new updates/alerts
+sub _relevant_reports {
+ my ($self, $time) = @_;
my $problems = FixMyStreet::DB->resultset("Problem")->search({
- lastupdate => { '<', interval($self->anonymize) },
+ lastupdate => { '<', interval($time) },
state => [
FixMyStreet::DB::Result::Problem->closed_states(),
FixMyStreet::DB::Result::Problem->fixed_states(),
FixMyStreet::DB::Result::Problem->hidden_states(),
],
});
+ if ($self->cobrand) {
+ $problems = $problems->search({ cobrand => $self->cobrand->moniker });
+ }
+ return $problems;
+}
+
+sub anonymize_reports {
+ my $self = shift;
+
+ # Need to look though them all each time, in case any new updates/alerts
+ my $problems = $self->_relevant_reports($self->anonymize);
while (my $problem = $problems->next) {
say "Anonymizing problem #" . $problem->id if $self->verbose;
@@ -124,14 +139,7 @@ sub anonymize_reports {
sub delete_reports {
my $self = shift;
- my $problems = FixMyStreet::DB->resultset("Problem")->search({
- lastupdate => { '<', interval($self->delete) },
- state => [
- FixMyStreet::DB::Result::Problem->closed_states(),
- FixMyStreet::DB::Result::Problem->fixed_states(),
- FixMyStreet::DB::Result::Problem->hidden_states(),
- ],
- });
+ my $problems = $self->_relevant_reports($self->delete);
while (my $problem = $problems->next) {
say "Deleting associated data of problem #" . $problem->id if $self->verbose;
@@ -180,10 +188,10 @@ sub email_inactive_users {
email_from => $self->email,
anonymize_from => $self->anonymize,
user => $user,
- url => $self->cobrand->base_url_with_lang . '/my',
+ url => $self->base_cobrand->base_url_with_lang . '/my',
},
{ To => [ $user->email, $user->name ] },
- undef, 0, $self->cobrand,
+ undef, 0, $self->base_cobrand,
);
$user->set_extra_metadata('inactive_email_sent', 1);
diff --git a/t/script/inactive.t b/t/script/inactive.t
index 582059cbf..26eab33e1 100644
--- a/t/script/inactive.t
+++ b/t/script/inactive.t
@@ -23,6 +23,7 @@ for (my $m = 1; $m <= 12; $m++) {
dt => $t,
lastupdate => "$t",
state => $m % 2 ? 'fixed - user' : 'confirmed',
+ cobrand => $m % 3 ? 'default' : 'bromley',
});
}
@@ -51,12 +52,30 @@ subtest 'Anonymization of inactive fixed/closed reports' => sub {
is $comment->user->email, 'removed-automatically@example.org', 'Comment user anonymized';
};
+subtest 'Test operating on one cobrand only' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'bromley'
+ }, sub {
+ my $in = FixMyStreet::Script::Inactive->new( cobrand => 'bromley', close => 1 );
+ $in->reports;
+ # Reports not a multiple of 2 are fixed, reports a multiple of 3 are bromley
+ $problems[2]->discard_changes;
+ is $problems[2]->get_extra_metadata('closed_updates'), 1, 'Closed to updates';
+ $problems[4]->discard_changes;
+ is $problems[4]->get_extra_metadata('closed_updates'), undef, 'Not closed to updates';
+ $problems[6]->discard_changes;
+ is $problems[6]->get_extra_metadata('closed_updates'), undef, 'Not closed to updates';
+ $problems[8]->discard_changes;
+ is $problems[8]->get_extra_metadata('closed_updates'), 1, 'Closed to updates';
+ };
+};
+
subtest 'Closing updates on inactive fixed/closed reports' => sub {
my $in = FixMyStreet::Script::Inactive->new( close => 1 );
$in->reports;
- $problems[2]->discard_changes;
- is $problems[2]->get_extra_metadata('closed_updates'), 1, 'Closed to updates';
- $mech->get_ok("/report/" . $problems[2]->id);
+ $problems[4]->discard_changes;
+ is $problems[4]->get_extra_metadata('closed_updates'), 1, 'Closed to updates';
+ $mech->get_ok("/report/" . $problems[4]->id);
$mech->content_contains('now closed to updates');
};