5 |
use Getopt::Long; |
use Getopt::Long; |
6 |
use Data::Dumper; |
use Data::Dumper; |
7 |
|
|
8 |
my ($lists,$debug) = (0,0); |
my ($list_opt,$debug) = (0,0); |
9 |
|
my $add_opt; |
10 |
|
|
11 |
my $result = GetOptions( |
my $result = GetOptions( |
12 |
"lists" => \$lists, |
"list" => \$list_opt, |
13 |
|
"add=s" => \$add_opt, |
14 |
"debug" => \$debug, |
"debug" => \$debug, |
15 |
); |
); |
16 |
|
|
23 |
namespace => "Noticer", |
namespace => "Noticer", |
24 |
# additional_classes => qw/Class::DBI::AbstractSearch/, |
# additional_classes => qw/Class::DBI::AbstractSearch/, |
25 |
# additional_base_classes => qw/My::Stuff/, |
# additional_base_classes => qw/My::Stuff/, |
26 |
relationships => 1 |
relationships => 1, |
27 |
); |
); |
28 |
|
|
29 |
if ($lists) { |
my $lists = $loader->find_class('lists'); |
30 |
my $lists = $loader->find_class('lists'); |
my $users = $loader->find_class('users'); |
31 |
my $users = $loader->find_class('users'); |
my $user_list = $loader->find_class('user_list'); |
32 |
my $user_list = $loader->find_class('user_list'); |
|
33 |
|
if ($list_opt) { |
34 |
foreach my $list ($lists->retrieve_all) { |
foreach my $list ($lists->retrieve_all) { |
35 |
print $list->name,"\n"; |
print $list->name,"\n"; |
36 |
foreach my $user_on_list ($user_list->search(list_id => $list->id)) { |
foreach my $user_on_list ($user_list->search(list_id => $list->id)) { |
38 |
print "\t",$user->full_name," <", $user->email, ">\n"; |
print "\t",$user->full_name," <", $user->email, ">\n"; |
39 |
} |
} |
40 |
} |
} |
41 |
|
} elsif ($add_opt) { |
42 |
|
#my $noticer = $loader->find_class('Noticer') || die "can't find my class!"; |
43 |
|
my $list = $lists->find_or_create({ |
44 |
|
name => $add_opt, |
45 |
|
}) || die "can't add list $add_opt\n"; |
46 |
|
while(<>) { |
47 |
|
chomp; |
48 |
|
next if (/^#/ || /^\s*$/); |
49 |
|
my ($email, $name) = split(/\s+/,$_, 2); |
50 |
|
print "# $name <$email>\n"; |
51 |
|
my $this_user = $users->find_or_create({ |
52 |
|
email => $email, |
53 |
|
full_name => $name, |
54 |
|
}) || die "can't find or create member\n"; |
55 |
|
my $user_on_list = $user_list->find_or_create({ |
56 |
|
user_id => $this_user->id, |
57 |
|
list_id => $list->id, |
58 |
|
}) || die "can't add user to list"; |
59 |
|
} |
60 |
|
|
61 |
|
foreach my $c_name ($loader->tables) { |
62 |
|
my $c = $loader->find_class($c_name)|| die "can't find $c_name"; |
63 |
|
$c->dbi_commit(); |
64 |
|
} |
65 |
|
|
66 |
} else { |
} else { |
67 |
die "$0: unknown command"; |
die "$0 --list --add=name_of_list --debug\n"; |
68 |
} |
} |
69 |
|
|
70 |
|
|