Address feedback

This commit is contained in:
Sekan, Tobias 2020-08-25 12:16:44 +02:00
parent 22ff5a320f
commit 4c851884e5
2 changed files with 31 additions and 11 deletions

View File

@ -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;

View File

@ -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];
}
}