source: trunk/LATMOS-Accounts/bin/la-delete @ 2380

Last change on this file since 2380 was 1044, checked in by nanardon, 12 years ago

Kill redundant LATMOS::Account::default_base()

Use $LA->base(undef) to get default base instead

  • Property svn:executable set to *
  • Property svn:keywords set to Id Rev
File size: 1.7 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use LATMOS::Accounts;
6use Getopt::Long;
7use Pod::Usage;
8
9=head1 NAME
10
11    la-delete - Tools to delete object in LATMOS-Accounts
12
13=head1 SYNOPSIS
14
15    la-delete [options] obj_id
16
17=cut
18
19GetOptions(
20    'c|config=s' => \my $config,
21    'b|base=s'   => \my $base,
22    'o|object=s' => \my $otype,
23    'force'      => \my $force,
24    'help'       => sub { pod2usage(0) },
25) or pod2usage();
26
27$otype ||= 'user';
28
29=head1 OPTIONS
30
31=over 4
32
33=item -c|--config configdir
34
35Use this configuration directory instead of the default one.
36
37=item -b|--base basename
38
39Query this specific base instead of the default one.
40
41=item -o|object object_type
42
43Query will be performed on this object. Default is the 'User' object.
44
45=item --force
46
47Do not ask confirmation before deleting
48
49=back
50
51=cut
52
53if (!$ARGV[0]) {warn "You must specify 'obj_id', aborting\n"; pod2usage(); }
54
55my $LA = LATMOS::Accounts->new($config, noacl => 1);
56my $labase = $LA->base($base);
57$labase && $labase->load or die "Cannot load base";
58$labase->wexported(1);
59
60if (!$labase->get_object($otype, $ARGV[0])) {
61    die "Cannot find object $otype $ARGV[0]\n";
62}
63
64if (!$force) {
65    my $alea = int(rand(1000));
66    print "Deleting object is definitive !\n";
67    print "Are you sure you want to delete objet $otype $ARGV[0] ?\n";
68    print "To confirm please enter this number: $alea\n";
69    my $enter = <STDIN>;
70    chomp($enter);
71    if (!($enter =~ /^\d+$/ && $enter == $alea)) {
72        die "Wonrg input, aborting\n";
73    }
74}
75
76if ($labase->delete_object($otype, $ARGV[0])) {
77    $labase->commit;
78    print "$otype/$ARGV[0] succefully deleted\n";
79    $LA->call_batch_sync;
80} else {
81    warn "Cannot delete $otype/$ARGV[0]\n";
82    exit(1);
83}
Note: See TracBrowser for help on using the repository browser.