]> andersk Git - moira.git/blame - regtape/grouper.pl
use new version of alis
[moira.git] / regtape / grouper.pl
CommitLineData
008e908b 1#!/moira/bin/perl -Tw
2# $Id$
3
4die "Usage: $0 password\n" unless ($#ARGV == 0);
5$whpassword = $ARGV[0];
4ec2c27e 6$db = "";
008e908b 7$mrtest = "mrtest";
8$ENV{'PATH'} = "/moira/bin";
9use DBI;
10
11$warehouse = DBI->connect("dbi:Oracle:warehouse", "moira", $whpassword,
12 { RaiseError => 1 });
13$moira = DBI->connect("dbi:Oracle:moira", "moira", "moira",
14 { RaiseError => 1});
15
16# Get the current term
17($term) = $warehouse->selectrow_array("SELECT term_code ".
18 "FROM wareuser.whsis_academic_terms ".
19 "WHERE is_current_term='Y'");
20# Convert from "2000FA" to "FA00"
21$term =~ s/\d\d(\d\d)(..)/$2$1/;
22
23# Get list of current classes
24$classes =
25 $warehouse->selectcol_arrayref("SELECT UNIQUE master_subject ".
26 "FROM wareuser.subject_enrollment_moira ".
27 "WHERE term = " . $warehouse->quote($term));
28
29# Get names of current Grouper lists
30$sth = $moira->prepare("SELECT name FROM list");
31$sth->execute;
32while (($name) = $sth->fetchrow_array) {
33 next if $name !~ /^(fa|sp|su|ja)\d\d-/;
34 $lists{$name} = $name;
35}
36
37$lists{"registrar"} = "registrar";
38
39# And MIT ID to username mappings
40$sth = $moira->prepare("SELECT login, clearid FROM users ".
41 "WHERE status = 1 OR status = 2");
42$sth->execute;
43while (($user, $mitid) = $sth->fetchrow_array) {
44 $users{$mitid} = $user;
45}
46
47($root_id) = $moira->selectrow_array("SELECT users_id FROM users ".
48 "WHERE login = 'root'");
49
50open(MRTEST, "|$mrtest");
51print MRTEST "connect $db\n";
52print MRTEST "auth\n";
53
54# Create any lists that don't already exist in Moira
55foreach $class (@$classes) {
56 $base = "\L$term-$class";
57 $staff = "$base-staff";
58
59 # check_list(name, owner, export, parent, desc)
60
61 &check_list($base, "registrar", 1, "",
62 "Automatically-created class participants list for $class");
63 &check_list("$base-reg", "registrar", 0, $base,
64 "Automatically-generated registered students list for $class");
65 &check_list($staff, $staff, 0, $base,
66 "Automatically-created teaching staff list for $class");
67 &check_list("$base-others", $staff, 0, $base,
68 "Automatically-created non-registered students and miscellaneous people list for $class");
69}
70
71# Now fill in -reg lists
72foreach $class (@$classes) {
73 $changed = 0;
74 $clist = "\L$term-$class-reg";
75
76 # Get current list membership in Moira
77 %mstudents = ();
78 $sth = $moira->prepare("SELECT u.login FROM users u, imembers i, list l ".
79 "WHERE l.list_id = i.list_id AND i.member_id = ".
80 "u.users_id AND i.direct = 1 AND i.member_type = ".
81 "'USER' AND l.name = " . $moira->quote($clist));
82 $sth->execute;
83 while (($login) = $sth->fetchrow_array) {
84 $mstudents{$login} = $login;
85 }
86
87 $wstudents = $warehouse->selectcol_arrayref("SELECT UNIQUE mit_id ".
88 "FROM wareuser.subject_enrollment_moira ".
89 "WHERE term = " . $warehouse->quote($term) .
90 " AND master_subject = " .
91 $warehouse->quote($class));
92
93 foreach $mitid (@$wstudents) {
94 $login = $users{$mitid};
95 next if !$login;
96 if (!$mstudents{$login}) {
97 print "Adding $login to $clist\n";
98 &add_member($login, USER, $clist);
99 $changed = 1;
100 } else {
101 delete $mstudents{$login};
102 }
103 }
104
105 # Everyone in wstudents will have been removed from mstudents
106 # now, so delete the remaining users since they don't belong
107 foreach $login (keys(%mstudents)) {
108 print "Deleting $login from $clist\n";
109 &del_member($login, USER, $clist);
110 $changed = 1;
111 }
112
113 if ($changed) {
114 $moira->do("UPDATE list SET modtime = SYSDATE, modby = $root_id, ".
115 "modwith = 'grouper' WHERE name = " .
116 $moira->quote($clist));
117 }
118}
119
120print MRTEST "quit\n";
121close(MRTEST);
122$moira->disconnect;
123$warehouse->disconnect;
124
125exit 0;
126
127sub check_list {
128 my ( $name, $owner, $export, $parent, $desc ) = @_;
129 if (!$lists{$name}) {
130 print "Creating $name\n";
346598e0 131 print MRTEST "qy alis $name 1 0 1 $export $export \"create unique GID\" 0 LIST $owner \"$desc\"\n";
008e908b 132 if ($parent) {
133 &add_member($name, LIST, $parent);
134 }
135 }
136}
137
138sub add_member {
139 my ( $user, $type, $list ) = @_;
140 print MRTEST "qy amtl $list $type $user\n";
141}
142
143sub del_member {
144 my ( $user, $type, $list ) = @_;
145 print MRTEST "qy dmfl $list $type $user\n";
146}
This page took 0.565556 seconds and 5 git commands to generate.