41769221930a2d3d8e962240c5f4565f7fd679e5
[clearscm.git] / maps / bin / domains.pl
1 #!/usr/bin/perl
2 ################################################################################
3 #
4 # File:         $RCSfile: domains,v $
5 # Revision:     $Revision: 1.1 $
6 # Description:  Display entries from the list table where there is at least one
7 #               entry with a null pattern (nuke the domain) and yet still other
8 #               entries with the same domain name but having a pattern. We may
9 #               want to eliminate the other entries since we're nuking the
10 #               whole domain anyway.
11 # Author:       Andrew@DeFaria.com
12 # Created:      Sat Oct 20 23:28:19 MST 2007
13 # Modified:     $Date: 2013/06/12 14:05:47 $
14 # Language:     Perl
15 #
16 # (c) Copyright 2007, Andrew@DeFaria.com, all rights reserved.
17 #
18 ################################################################################
19 use strict;
20 use warnings;
21
22 use FindBin;
23 use Getopt::Long;
24
25 use lib "$FindBin::Bin/../lib", '/opt/clearscm/lib';
26
27 use MAPS;
28 use Display;
29
30 sub Usage () {
31   display <<END;
32 $FindBin::Script { -verbose } { -debug } { -usage }
33 END
34
35   exit 1;
36 } # Usage
37
38 GetOptions (
39   "verbose" => sub { set_verbose },
40   "debug"   => sub { set_debug },
41   "usage"   => sub { Usage },
42 ) || Usage;
43
44 my $userid = $ENV{MAPS_USERNAME} ? $ENV{MAPS_USERNAME} : $ENV{USER};
45
46 # Main
47 SetContext $userid;
48
49 my $statement = "select domain from list where userid=\"$userid\" and type=\"null\" and pattern is null";
50
51 my $need_resequence = 0;
52
53 for my $domain (sort (GetRows($statement))) {
54   verbose "Processing domain $domain";
55   $statement = "select sequence from list where userid = \"$userid\" and domain = \"$domain\" and type = \"null\" and pattern is not null";
56
57   for my $sequence (GetRows $statement) {
58     display "Deleting $domain ($sequence)";
59     $need_resequence = 1;
60     DeleteList "null", $sequence;
61   } # for
62 } # for
63
64 if ($need_resequence) {
65   verbose "Resequencing null list...";
66   ResequenceList $userid, "null";
67   verbose "done";
68 } # if
69
70 exit;