diff options
author | Daniel Friesel <derf@finalrewind.org> | 2022-02-14 21:58:30 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2022-02-14 21:58:30 +0100 |
commit | faf8952b8732d6314e3d3429f5cc761564565e44 (patch) | |
tree | 0247aa13ee6f06f33f53b848503d1e0fb42ce884 /lib/Travelynx/Command/maintenance.pm | |
parent | 6fc21cac41e3b1bf4a6484fed736aec27b340b63 (diff) |
Send inactivity notification prior to account deletion
Diffstat (limited to 'lib/Travelynx/Command/maintenance.pm')
-rw-r--r-- | lib/Travelynx/Command/maintenance.pm | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/lib/Travelynx/Command/maintenance.pm b/lib/Travelynx/Command/maintenance.pm index 5f609cb..58189ff 100644 --- a/lib/Travelynx/Command/maintenance.pm +++ b/lib/Travelynx/Command/maintenance.pm @@ -18,6 +18,7 @@ sub run { my $verification_deadline = $now->clone->subtract( hours => 48 ); my $deletion_deadline = $now->clone->subtract( hours => 72 ); my $old_deadline = $now->clone->subtract( years => 1 ); + my $old_notification_deadline = $now->clone->subtract( weeks => 4 ); my $db = $self->app->pg->db; my $tx = $db->begin; @@ -82,12 +83,39 @@ sub run { printf( "Pruned %d pending mail change(s)\n", $rows ); } + my $to_notify = $db->select( + 'users', + [ 'id', 'name', 'email', 'last_seen' ], + { + last_seen => { '<', $old_deadline }, + deletion_notified => undef + } + ); + + for my $user ( $to_notify->hashes->each ) { + $self->app->sendmail->age_deletion_notification( + name => $user->{name}, + email => $user->{email}, + last_seen => $user->{last_seen}, + login_url => $self->app->base_url_for('login')->to_abs, + account_url => $self->app->base_url_for('account')->to_abs, + imprint_url => $self->app->base_url_for('impressum')->to_abs, + ); + $self->app->users->mark_deletion_notified( uid => $user->{id} ); + } + my $to_delete = $db->select( 'users', ['id'], { deletion_requested => { '<', $deletion_deadline } } ); my @uids_to_delete = $to_delete->arrays->map( sub { shift->[0] } )->each; - $to_delete - = $db->select( 'users', ['id'], { last_seen => { '<', $old_deadline } } ); + $to_delete = $db->select( + 'users', + ['id'], + { + last_seen => { '<', $old_deadline }, + deletion_notified => { '<', $old_notification_deadline } + } + ); push( @uids_to_delete, $to_delete->arrays->map( sub { shift->[0] } )->each ); |