4 die "Usage: $0 password\n" unless ($#ARGV == 0);
5 $whpassword = $ARGV[0];
8 $logfile = "/moira/grouper.log";
9 $ENV{'PATH'} = "/moira/bin";
12 $warehouse = DBI->connect("dbi:Oracle:warehouse", "moira", $whpassword,
14 $moira = DBI->connect("dbi:Oracle:moira", "moira", "moira",
17 # Get the current term
18 ($term) = $warehouse->selectrow_array("SELECT term_code ".
19 "FROM wareuser.whsis_academic_terms ".
20 "WHERE is_current_term='Y'");
21 # Convert from "2000FA" to "FA00"
22 $term =~ s/\d\d(\d\d)(..)/$2$1/;
24 # Get list of current classes
26 $warehouse->selectcol_arrayref("SELECT UNIQUE master_subject ".
27 "FROM wareuser.subject_enrollment_moira ".
28 "WHERE term = " . $warehouse->quote($term));
30 # Get names of current Grouper lists
31 $sth = $moira->prepare("SELECT name FROM list");
33 while (($name) = $sth->fetchrow_array) {
34 next if $name !~ /^(fa|sp|su|ja)\d\d-/;
35 $lists{$name} = $name;
38 $lists{"registrar"} = "registrar";
40 # And MIT ID to username mappings
41 $sth = $moira->prepare("SELECT login, clearid FROM users ".
42 "WHERE status = 1 OR status = 2");
44 while (($user, $mitid) = $sth->fetchrow_array) {
45 $users{$mitid} = $user;
48 ($root_id) = $moira->selectrow_array("SELECT users_id FROM users ".
49 "WHERE login = 'root'");
51 open(MRTEST, "|$mrtest >/dev/null 2>&1");
52 print MRTEST "connect $db\n";
53 print MRTEST "auth\n";
54 open(LOG, ">>$logfile");
56 # Create any lists that don't already exist in Moira
57 foreach $class (@$classes) {
58 $base = "\L$term-$class";
59 $staff = "$base-staff";
61 # check_list(name, owner, export, desc)
62 &check_list($staff, $staff, 0,
63 "Teaching staff list for $class");
64 &check_list("$base-reg", $staff, 0,
65 "*** DO NOT MODIFY *** Automatically-created registered students list for $class");
66 &check_list("$base-others", $staff, 0,
67 "Non-registered students and miscellaneous people list for $class");
68 &check_list($base, $staff, 1,
69 "*** DO NOT MODIFY *** Automatically-created participants list for $class");
71 &add_member($staff, LIST, $base);
72 &add_member("$base-reg", LIST, $base);
73 &add_member("$base-others", LIST, $base);
77 # Now fill in -reg lists
78 foreach $class (@$classes) {
80 $clist = "\L$term-$class-reg";
82 # Get current list membership in Moira
84 $sth = $moira->prepare("SELECT u.login FROM users u, imembers i, list l ".
85 "WHERE l.list_id = i.list_id AND i.member_id = ".
86 "u.users_id AND i.direct = 1 AND i.member_type = ".
87 "'USER' AND l.name = " . $moira->quote($clist));
89 while (($login) = $sth->fetchrow_array) {
90 $mstudents{$login} = $login;
93 $wstudents = $warehouse->selectcol_arrayref("SELECT UNIQUE mit_id ".
94 "FROM wareuser.subject_enrollment_moira ".
95 "WHERE term = " . $warehouse->quote($term) .
96 " AND master_subject = " .
97 $warehouse->quote($class));
99 foreach $mitid (@$wstudents) {
100 $login = $users{$mitid};
102 if (!$mstudents{$login}) {
103 print LOG "Adding $login to $clist\n";
104 &add_member($login, USER, $clist);
107 delete $mstudents{$login};
111 # Everyone in wstudents will have been removed from mstudents
112 # now, so delete the remaining users since they don't belong
113 foreach $login (keys(%mstudents)) {
114 print LOG "Deleting $login from $clist\n";
115 &del_member($login, USER, $clist);
120 $moira->do("UPDATE list SET modtime = SYSDATE, modby = $root_id, ".
121 "modwith = 'grouper' WHERE name = " .
122 $moira->quote($clist));
126 print MRTEST "quit\n";
130 $warehouse->disconnect;
135 my ( $name, $owner, $export, $desc ) = @_;
136 if (!$lists{$name}) {
137 print LOG "Creating $name\n";
138 print MRTEST "qy alis $name 0 0 1 $export $export \"create unique GID\" 0 0 [NONE] LIST $owner NONE NONE \"$desc\"\n";
143 my ( $user, $type, $list ) = @_;
144 print MRTEST "qy amtl $list $type $user\n";
148 my ( $user, $type, $list ) = @_;
149 print MRTEST "qy dmfl $list $type $user\n";