appbox = $appbox; $this->table = $table; } /** * Returns users with duplicated emails * * @return array An array of User */ public function getWrongEmailUsers() { if (version_compare($this->appbox->get_version(), '3.9', '>=')) { return []; } $builder = $this->appbox->get_connection()->createQueryBuilder(); /** @var Statement $stmt */ $stmt = $builder ->select('u.usr_mail', 'u.usr_id', 'u.last_conn', 'u.usr_login') ->from($this->table, 'u') ->where($builder->expr()->isNotNull('u.usr_mail')) ->execute() ; $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC); $stmt->closeCursor(); $users = []; foreach ($rs as $row) { if (!isset($users[$row['usr_mail']])) { $users[$row['usr_mail']] = []; } $users[$row['usr_mail']][] = $row; } $badUsers = []; foreach ($users as $email => $usrs) { if (count($usrs) > 1) { $badUsers[$email] = []; foreach ($usrs as $usrInfo) { $badUsers[$email][$usrInfo['usr_id']] = $usrInfo; } } } unset($users); return $badUsers; } /** * Whether there is users with same emails * * @return bool */ public function hasWrongEmailUsers() { return count($this->getWrongEmailUsers()) > 0; } }