From f39bb5ec4e9dfe1a277182fd7704d67fae498cf9 Mon Sep 17 00:00:00 2001 From: John Kingsnorth Date: Wed, 21 Jan 2015 10:07:13 +0000 Subject: [PATCH] Fix error for users with no misaffiliation This fixes PDOException: SQLSTATE[23000]: Integrity constraint when College staff are registered. College staff do not have 'staff' or 'student', so the default '0' is not set, causing an error. --- lookup.module | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lookup.module b/lookup.module index f01a79c..59e953c 100644 --- a/lookup.module +++ b/lookup.module @@ -135,11 +135,18 @@ function user_lookup_details($name, $terms = array('displayName', 'mail', 'misAf if (isset($info[0]['mail'][0])) { $details['mail'] = $info[0]['mail'][0]; } + + $details['staff'] = 0; + $details['student'] = 0; + if (isset($info[0]['misaffiliation'])) { - $details['staff'] = in_array('staff', $info[0]['misaffiliation']) ? 1 : 0; - $details['student'] = in_array('student', $info[0]['misaffiliation']) ? 1 : 0; + if ( in_array('staff', $info[0]['misaffiliation']) ){ + $details['staff'] = 1; + } + if ( in_array('student', $info[0]['misaffiliation']) ){ + $details['student'] = 1; + } } - } ldap_close($ds); } @@ -371,4 +378,4 @@ function lookup_delete_all() { /** * @} End of 'addtogroup lookup'. - */ \ No newline at end of file + */