diff options
Diffstat (limited to 'perllib/FixMyStreet/Script/Inactive.pm')
-rw-r--r-- | perllib/FixMyStreet/Script/Inactive.pm | 40 |
1 files changed, 24 insertions, 16 deletions
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); |