From 465f8ed1b317afb1c7aefde04e53118a19be1a18 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Tue, 29 Jan 2013 21:44:24 +0100 Subject: Finished the factoring of localpart-related methods. --- misc/deleteExpiredEntries.pl | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) (limited to 'misc') diff --git a/misc/deleteExpiredEntries.pl b/misc/deleteExpiredEntries.pl index 29e26b0..1234920 100755 --- a/misc/deleteExpiredEntries.pl +++ b/misc/deleteExpiredEntries.pl @@ -24,6 +24,7 @@ use Pod::Usage; use Config::Auto; use lib 'lib'; use Fripost::Schema::Auth; +use Fripost::Schema::Pending; use POSIX 'strftime'; # TODO: put that in a config file @@ -32,37 +33,12 @@ my $config = { ldap_bind_dn => [ 'cn=DeletePendingEntries','ou=services','o=mail , ldap_suffix => [ 'ou=virtual','o=mailHosting','dc=fripost,dc=dev' ] }; -my $fp = Fripost::Schema::Auth->auth( undef, 'deletependingentries', %$config ); - - my $maxage = $ARGV[0] // 86400; # 24h by default -my $now = int(strftime "%s", gmtime); - -my $maxdate = Net::LDAP::Util::escape_filter_value( - strftime ("%Y%m%d%H%M%SZ", localtime($now - $maxage)) - ); -my $entries = $fp->ldap->search ( - base => Fripost::Schema::Util::canonical_dn(@{$fp->suffix}), - scope => 'subtree', - deref => 'never', - filter => "(&(objectClass=FripostPendingEntry) - (createTimestamp<=$maxdate))", - attrs => [ '1.1' ], - callback => \&delete_entry - ); -die $entries->error."\n" if $entries->code; +my $fp = Fripost::Schema::Auth::->auth( undef, 'deletependingentries', %$config ) // die; +Fripost::Schema::Pending::find ($fp, -quiet => 1, -delete => 1, + '-max-age' => $maxage); $fp->done; -sub delete_entry { - my ($mesg, $obj) = @_; - if (defined $obj and $obj->isa('Net::LDAP::Entry')) { - print STDERR "Deleting DN ".$obj->dn."\n"; - $obj->delete; - my $mesg = $obj->update($fp->ldap); - die $mesg->error."\n" if $mesg->code; - } - $mesg->pop_entry; -} ####################################################################### -- cgit v1.2.3