Added fix to phpbb3 when userid returns none.

This commit is contained in:
Raynaldo Rivera 2014-11-29 16:06:13 -07:00
parent de34d35add
commit e7950a26f7

View File

@ -62,7 +62,10 @@ class Phpbb3Manager:
cursor = connections['phpbb3'].cursor() cursor = connections['phpbb3'].cursor()
cursor.execute(Phpbb3Manager.SQL_USER_ID_FROM_USERNAME, [username]) cursor.execute(Phpbb3Manager.SQL_USER_ID_FROM_USERNAME, [username])
row = cursor.fetchone() row = cursor.fetchone()
return row[0] if row is not None:
return row[0]
else:
return None
@staticmethod @staticmethod
def __get_all_groups(): def __get_all_groups():
@ -158,34 +161,36 @@ class Phpbb3Manager:
@staticmethod @staticmethod
def update_groups(username, groups): def update_groups(username, groups):
userid = Phpbb3Manager.__get_user_id(username) userid = Phpbb3Manager.__get_user_id(username)
forum_groups = Phpbb3Manager.__get_all_groups() if userid is not None:
user_groups = set(Phpbb3Manager.__get_user_groups(userid)) forum_groups = Phpbb3Manager.__get_all_groups()
act_groups = set([g.replace(' ', '-') for g in groups]) user_groups = set(Phpbb3Manager.__get_user_groups(userid))
addgroups = act_groups - user_groups act_groups = set([g.replace(' ', '-') for g in groups])
remgroups = user_groups - act_groups addgroups = act_groups - user_groups
print username remgroups = user_groups - act_groups
print addgroups print username
print remgroups print addgroups
for g in addgroups: print remgroups
if not g in forum_groups: for g in addgroups:
forum_groups[g] = Phpbb3Manager.__create_group(g) if not g in forum_groups:
Phpbb3Manager.__add_user_to_group(userid, forum_groups[g]) forum_groups[g] = Phpbb3Manager.__create_group(g)
Phpbb3Manager.__add_user_to_group(userid, forum_groups[g])
for g in remgroups: for g in remgroups:
Phpbb3Manager.__remove_user_from_group(userid, forum_groups[g]) Phpbb3Manager.__remove_user_from_group(userid, forum_groups[g])
@staticmethod @staticmethod
def remove_group(username, group): def remove_group(username, group):
cursor = connections['phpbb3'].cursor() cursor = connections['phpbb3'].cursor()
userid = Phpbb3Manager.__get_user_id(username) userid = Phpbb3Manager.__get_user_id(username)
groupid = Phpbb3Manager.__get_group_id(group) if userid is not None:
groupid = Phpbb3Manager.__get_group_id(group)
if userid: if userid:
if groupid: if groupid:
try: try:
cursor.execute(Phpbb3Manager.SQL_REMOVE_USER_GROUP, [userid, groupid]) cursor.execute(Phpbb3Manager.SQL_REMOVE_USER_GROUP, [userid, groupid])
except: except:
pass pass
@staticmethod @staticmethod
def check_user(username): def check_user(username):