aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2018-05-11 19:57:49 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2018-05-23 18:55:10 +0100
commiteb58ad65f8b25be9dc4321ca5914ad1d89f8bf3a (patch)
treeff99b2e34567c149a9ecd17c800781c8e40ebb6c /perllib
parentdf731c5a0ffccc434550ca4dd2ecace5287848fa (diff)
Script to scrub old non-open reports.
Diffstat (limited to 'perllib')
-rw-r--r--perllib/FixMyStreet/Script/Inactive.pm57
1 files changed, 57 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/Script/Inactive.pm b/perllib/FixMyStreet/Script/Inactive.pm
index 766135e12..3c6be9901 100644
--- a/perllib/FixMyStreet/Script/Inactive.pm
+++ b/perllib/FixMyStreet/Script/Inactive.pm
@@ -32,6 +32,15 @@ has cobrand => (
},
);
+has anonymous_user => (
+ is => 'lazy',
+ default => sub {
+ FixMyStreet::DB->resultset("User")->find_or_create({
+ email => 'removed-automatically@' . FixMyStreet->config('EMAIL_DOMAIN'),
+ });
+ }
+);
+
sub users {
my $self = shift;
@@ -40,6 +49,54 @@ sub users {
$self->email_inactive_users if $self->email;
}
+sub reports {
+ my $self = shift;
+
+ say "DRY RUN" if $self->dry_run;
+
+ # Need to look though them all each time, in case any new updates/alerts
+ my $problems = FixMyStreet::DB->resultset("Problem")->search({
+ lastupdate => { '<', interval($self->anonymize) },
+ state => [
+ FixMyStreet::DB::Result::Problem->closed_states(),
+ FixMyStreet::DB::Result::Problem->fixed_states(),
+ FixMyStreet::DB::Result::Problem->hidden_states(),
+ ],
+ });
+
+ while (my $problem = $problems->next) {
+ say "Anonymizing problem #" . $problem->id if $self->verbose;
+ next if $self->dry_run;
+
+ # Remove personal data from the report
+ $problem->update({
+ user => $self->anonymous_user,
+ name => '',
+ anonymous => 1,
+ send_questionnaire => 0,
+ }) if $problem->user != $self->anonymous_user;
+
+ # Remove personal data from the report's updates
+ $problem->comments->search({
+ user_id => { '!=' => $self->anonymous_user->id },
+ })->update({
+ user_id => $self->anonymous_user->id,
+ name => '',
+ anonymous => 1,
+ });
+
+ # Remove alerts - could just delete, but of interest how many there were, perhaps?
+ FixMyStreet::DB->resultset('Alert')->search({
+ user_id => { '!=' => $self->anonymous_user->id },
+ alert_type => 'new_updates',
+ parameter => $problem->id,
+ })->update({
+ user_id => $self->anonymous_user->id,
+ whendisabled => \'current_timestamp',
+ });
+ }
+}
+
sub anonymize_users {
my $self = shift;