From fbe3c283db64e8106eb65223a9e4c580216642e6 Mon Sep 17 00:00:00 2001 From: Iain C Docherty Date: Sat, 27 Feb 2016 15:14:24 -0500 Subject: [PATCH] Delete expired sitter_auths --- bin/clean_up_sitterauths.pl | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/bin/clean_up_sitterauths.pl b/bin/clean_up_sitterauths.pl index 8b41b3427..849b1540c 100644 --- a/bin/clean_up_sitterauths.pl +++ b/bin/clean_up_sitterauths.pl @@ -15,24 +15,32 @@ my $rs = Lacuna->db->resultset("SitterAuths"); -# we do not warn about expired auths since we've already warned them for the -# previous AUTH_WARNING_DAYS days. -out("Checking for messages to send."); - my $soon = DateTime->now()->add(days => $rs->AUTH_WARNING_DAYS); my $dtf = Lacuna->db->storage->datetime_parser; +out("Checking for sitter_auths to delete."); +# Delete any that have already expired +# +$rs->search({ + expiry => { + '<' => $dtf->format_datetime(DateTime->now), + } +})->delete; + +# we do not warn about expired auths since we've already warned them for the +# previous AUTH_WARNING_DAYS days. + +out("Checking for messages to send."); my $warnings = $rs->search({ expiry => { '<' => $dtf->format_datetime($soon), '>' => $dtf->format_datetime(DateTime->now), }, - },{ - join => ['sitter', 'baby'], - '+select' => [ 'sitter.name', 'baby.name' ], - '+as' => [ 'sitter_name', 'baby_name' ], - }, -); +},{ + join => [ 'sitter', 'baby' ], + '+select' => [ 'sitter.name', 'baby.name' ], + '+as' => [ 'sitter_name', 'baby_name' ], +}); my %expiring_sitters; my %expiring_babies; @@ -91,7 +99,6 @@ out("Done."); -our $quiet; sub out { unless ($quiet) { say DateTime->now, " ", @_;