Skip to content

Commit 39d27f8

Browse files
caseysoftwareclaude
andcommitted
Don't save contacts with owner -1 when no one is logged in
CContact::hook_preStore() fills an empty contact_owner with the current user id. Before login that id is -1, which the unsigned contact_owner column rejects in strict SQL mode ("Out of range value"). This is what happens on an LDAP user's first login: the contact insert fails, the new user is saved with user_contact = 0, and is then missing from User Management, so an admin cannot give it a role. Use 0 (no owner) when the current user id is not positive. Refs #320 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016CP89WVmGZ1VVCCZMS6ntN
1 parent 444070c commit 39d27f8

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎modules/contacts/contacts.class.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ protected function hook_preStore()
6666
{
6767
$this->contact_company = (int) $this->contact_company;
6868
$this->contact_department = (int) $this->contact_department;
69-
$this->contact_owner = ((int) $this->contact_owner) ? (int) $this->contact_owner : (int) $this->_AppUI->user_id;
69+
// Visitors who are not logged in have user_id -1 (for example LDAP's
70+
// first login), which the unsigned column rejects; store them as 0
71+
// (no owner) instead.
72+
$this->contact_owner = ((int) $this->contact_owner) ? (int) $this->contact_owner : max(0, (int) $this->_AppUI->user_id);
7073
$this->contact_private = (int) $this->contact_private;
7174

7275
$this->contact_first_name = ($this->contact_first_name == null) ? '' : $this->contact_first_name;

0 commit comments

Comments
 (0)