What we _actually_ ran for the first load of student data
authorDan Scott <dan@coffeecode.net>
Fri, 2 Sep 2011 12:54:19 +0000 (08:54 -0400)
committerDan Scott <dscott@laurentian.ca>
Tue, 7 May 2013 18:38:23 +0000 (14:38 -0400)
Signed-off-by: Dan Scott <dscott@laurentian.ca>
tools/patron-load/ldap_sync

index 0b7e896..0cff2c9 100644 (file)
@@ -265,9 +265,10 @@ def update_existing_users():
 
     UPDATE actor.usr 
       SET home_ou = su.home_ou,
-        usrname = LOWER(su.usrname),
+        usrname = LOWER(su.email),
         profile = su.profile,
-        email = LOWER(su.email)
+        email = LOWER(su.email),
+        expire_date = '2012-09-30'::date
       FROM scratchpad.usr_staging su
       WHERE su.ident_value= actor.usr.ident_value
         AND su.profile IS NOT NULL
@@ -303,7 +304,7 @@ def insert_new_users():
       WHERE profile IS NULL;
 
     INSERT INTO actor.usr (usrname, passwd, email, first_given_name, family_name, home_ou, ident_type, ident_value, profile, expire_date)
-      SELECT LOWER(usrname), MD5(RANDOM()::TEXT), LOWER(email), first_given_name, family_name, home_ou, 2, ident_value, profile, '2012-09-30'::date
+      SELECT LOWER(email), MD5(RANDOM()::TEXT), LOWER(email), first_given_name, family_name, home_ou, 2, ident_value, profile, '2012-09-30'::date
         FROM scratchpad.usr_staging WHERE ident_value IN (
           SELECT ident_value
             FROM scratchpad.usr_staging
@@ -338,7 +339,7 @@ def search_for_students(con, attributes, create_date):
     search_scope = ldap.SCOPE_SUBTREE
     ldap_filter = '(&(objectclass=lulEduPerson))'
     ldap_filter = '(&(objectclass=lulEduPerson)(lulPrimaryAffiliation=*)(createTimestamp>=%s000000Z))' % create_date
-    ldap_filter = '(&(lulStudentLevel=*)(createTimestamp>=%s000000Z))' % create_date
+    ldap_filter = '(&(lulStudentLevel=*))'
 
     try:
         result_id = con.search(base_dn, search_scope, ldap_filter, attributes)
@@ -366,9 +367,14 @@ def insert_into_staging(result_data):
     usrname = result_data['cn'][0].strip()
     email = result_data['mail'][0].strip()
     family_name = result_data['sn'][0].strip()
-    given_name = result_data['givenName'][0].strip()
     datatel = result_data['lulColleagueId'][0].strip()
 
+    if 'givenName' in result_data:
+        given_name = result_data['givenName'][0].strip()
+    else:
+        given_name = 'LDAP_NULL'
+        print >> sys.stderr, 'No givenName for %s' % (usrname)
+
     if len(datatel) != 7:
         print >> sys.stderr, 'Datatel number not 7 chars for %s (%s)' % (usrname, datatel)
         if len(datatel) == 6: