aboutsummaryrefslogtreecommitdiffstats
path: root/misc
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem.moulin@fripost.org>2013-01-29 21:44:24 +0100
committerGuilhem Moulin <guilhem.moulin@fripost.org>2013-01-29 21:44:24 +0100
commit465f8ed1b317afb1c7aefde04e53118a19be1a18 (patch)
treeb9f92574022267058f34326edfa25195afdc4e4b /misc
parent38bbf969d6c29891f40973a0db376d5f5ee5ab07 (diff)
Finished the factoring of localpart-related methods.
Diffstat (limited to 'misc')
-rwxr-xr-xmisc/deleteExpiredEntries.pl32
1 files changed, 4 insertions, 28 deletions
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;
-}
#######################################################################