forked from GNUsocial/gnu-social
[UTIL] Rename and rewrite isTaken to checkTaken
This commit is contained in:
parent
bd249b508b
commit
ec1081ed43
@ -23,8 +23,6 @@ namespace App\Util;
|
|||||||
|
|
||||||
use App\Core\DB\DB;
|
use App\Core\DB\DB;
|
||||||
use App\Entity\GSActor;
|
use App\Entity\GSActor;
|
||||||
use App\Entity\LocalGroup;
|
|
||||||
use App\Entity\LocalUser;
|
|
||||||
use App\Util\Exception\NicknameBlacklistedException;
|
use App\Util\Exception\NicknameBlacklistedException;
|
||||||
use App\Util\Exception\NicknameEmptyException;
|
use App\Util\Exception\NicknameEmptyException;
|
||||||
use App\Util\Exception\NicknameException;
|
use App\Util\Exception\NicknameException;
|
||||||
@ -160,7 +158,7 @@ class Nickname
|
|||||||
} elseif (self::isReserved($nickname) || Common::isSystemPath($nickname)) {
|
} elseif (self::isReserved($nickname) || Common::isSystemPath($nickname)) {
|
||||||
throw new NicknameReservedException();
|
throw new NicknameReservedException();
|
||||||
} elseif ($check_already_used) {
|
} elseif ($check_already_used) {
|
||||||
$actor = self::isTaken($nickname);
|
$actor = self::checkTaken($nickname);
|
||||||
if ($actor instanceof GSActor) {
|
if ($actor instanceof GSActor) {
|
||||||
throw new NicknameTakenException($actor);
|
throw new NicknameTakenException($actor);
|
||||||
}
|
}
|
||||||
@ -216,18 +214,16 @@ class Nickname
|
|||||||
*
|
*
|
||||||
* @return null|GSActor Returns GSActor if nickname found
|
* @return null|GSActor Returns GSActor if nickname found
|
||||||
*/
|
*/
|
||||||
public static function isTaken(string $nickname): ?GSActor
|
public static function checkTaken(string $nickname): ?GSActor
|
||||||
{
|
{
|
||||||
$found = DB::findBy('local_user', ['nickname' => $nickname]);
|
foreach (['local_user' => 'id', 'local_group' => 'group_id'] as $table => $id_field) {
|
||||||
if ($found instanceof LocalUser) {
|
$ret = DB::dql("select a from gsactor a join {$table} t with a.id = t.{$id_field} " .
|
||||||
return $found->getGSActor();
|
'where a.normalized_nickname = :nick', ['nick' => self::normalize($nickname, check_already_used: false)]);
|
||||||
}
|
|
||||||
|
|
||||||
$found = DB::findBy('local_group', ['nickname' => $nickname]);
|
if (!empty($ret)) {
|
||||||
if ($found instanceof LocalGroup) {
|
return $ret[0];
|
||||||
return $found->getGSActor();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user