#!/usr/bin/perl

use DataOneLdap;
use strict;

use Getopt::Long();

sub usage {
   my $command = $0;
   $command =~ s#^.*/##;

   print STDERR (
      "Delete everything in ldap without regard for constraints",
      "usage: $command [--help]\n" 
   );

   die("\n")
}

my $help;
my $nodeid;

Getopt::Long::GetOptions(
   'help!' => \$help
) or usage("Invalid commmand line options.");

usage() if (defined $help);

my $d1Ldap = new DataOneLdap();

my $ldap = $d1Ldap->connect();

my $mesg = $ldap->search( filter => "(objectClass=*)", base=>"dc=org");
my @entries = ();
my $i = 0;
do
	{
	++$i;	
	@entries = $mesg->entries;
	foreach my $entry (@entries) 
		{
		my $dn = $entry->dn();
		print "DN = $dn\n";
		$ldap->delete($dn);
		}
	} while ((scalar(@entries) > 0) && ($i < 10));

$ldap->unbind;