diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index e5ab1c02902..8327aedf9ce 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -1062,7 +1062,7 @@ if (count($listofextcals)) $event->ref = $event->id; $userId = $userstatic->findUserIdByEmail($namecal); - if(!empty($userId)) + if (!empty($userId) && $userId > 0) { $event->userassigned[$userId] = $userId; $event->percentage = -1; diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 6d278e635fa..42d2f8705fb 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -3240,42 +3240,62 @@ class User extends CommonObject /** * Cache the SQL results of the function "findUserIdByEmail($email)" - * + * + * NOTE: findUserIdByEmailCache[...] === -1 means not found in database + * * @var array */ private $findUserIdByEmailCache; /** - * Find a user by the given e-mail or part of a e-mail and return its user id when found + * Find a user by the given e-mail and return it's user id when found * - * @param string $email The full e-mail or a part of a e-mail - * @return int|null The id of the user when found, otherwise null + * NOTE: + * Use AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR + * to disable exact e-mail search + * + * @param string $email The full e-mail (or a part of a e-mail) + * @return int <0 = user was not found, >0 = The id of the user */ public function findUserIdByEmail($email) { - if($this->findUserIdByEmailCache[$email]) + if ($this->findUserIdByEmailCache[$email]) { return $this->findUserIdByEmailCache[$email]; } + $this->findUserIdByEmailCache[$email] = -1; + + global $conf; + $sql = 'SELECT rowid'; $sql .= ' FROM '.MAIN_DB_PREFIX.'user'; - $sql .= ' WHERE email LIKE "%'.$email.'%"'; + + if (!empty($conf->global->AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR)) + { + $sql .= ' WHERE email LIKE "%'.$email.'%"'; + } + else + { + $sql .= ' WHERE email = "'.$email.'"'; + } + + $sql .= ' LIMIT 1'; $resql = $this->db->query($sql); if (!$resql) { - return 0; + return -1; } $obj = $this->db->fetch_object($resql); if (!$obj) { - return 0; + return -1; } - $this->findUserIdByEmailCache[$email] = (int)$obj->rowid; + $this->findUserIdByEmailCache[$email] = (int) $obj->rowid; - return (int)$obj->rowid; + return $this->findUserIdByEmailCache[$email]; } }