forked from GNUsocial/gnu-social
[ENTITY] Add 'normalized_nickname' to GSActor, the result of Nickname::normalize, so we can make sure we don't have very similar nicknames duplicated
This commit is contained in:
parent
f2727f9327
commit
bd249b508b
@ -92,7 +92,7 @@ class Security extends Controller
|
||||
$valid_nickname = Nickname::normalize($data['nickname'], check_already_used: true);
|
||||
|
||||
try {
|
||||
$actor = GSActor::create(['nickname' => $data['nickname']]);
|
||||
$actor = GSActor::create(['nickname' => $data['nickname'], 'normalized_nickname' => Nickname::normalize($data['nickname'], check_already_used: true)]);
|
||||
$user = LocalUser::create([
|
||||
'nickname' => $data['nickname'],
|
||||
'outgoing_email' => $data['email'],
|
||||
|
@ -48,6 +48,7 @@ class GSActor extends Entity
|
||||
// {{{ Autocode
|
||||
private int $id;
|
||||
private string $nickname;
|
||||
private string $normalized_nickname;
|
||||
private ?string $fullname;
|
||||
private int $roles = 4;
|
||||
private ?string $homepage;
|
||||
@ -82,6 +83,17 @@ class GSActor extends Entity
|
||||
return $this->nickname;
|
||||
}
|
||||
|
||||
public function setNormalizedNickname(string $normalized_nickname): self
|
||||
{
|
||||
$this->normalized_nickname = $normalized_nickname;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getNormalizedNickname(): string
|
||||
{
|
||||
return $this->normalized_nickname;
|
||||
}
|
||||
|
||||
public function setFullname(?string $fullname): self
|
||||
{
|
||||
$this->fullname = $fullname;
|
||||
@ -181,29 +193,28 @@ class GSActor extends Entity
|
||||
return $this->location_service;
|
||||
}
|
||||
|
||||
public function setCreated(\DateTimeInterface $created): self
|
||||
public function setCreated(DateTimeInterface $created): self
|
||||
{
|
||||
$this->created = $created;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreated(): \DateTimeInterface
|
||||
public function getCreated(): DateTimeInterface
|
||||
{
|
||||
return $this->created;
|
||||
}
|
||||
|
||||
public function setModified(\DateTimeInterface $modified): self
|
||||
public function setModified(DateTimeInterface $modified): self
|
||||
{
|
||||
$this->modified = $modified;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getModified(): \DateTimeInterface
|
||||
public function getModified(): DateTimeInterface
|
||||
{
|
||||
return $this->modified;
|
||||
}
|
||||
|
||||
|
||||
// }}} Autocode
|
||||
|
||||
public function getAvatarUrl()
|
||||
@ -282,23 +293,25 @@ class GSActor extends Entity
|
||||
'name' => 'gsactor',
|
||||
'description' => 'local and remote users, groups and bots are gsactors, for instance',
|
||||
'fields' => [
|
||||
'id' => ['type' => 'serial', 'not null' => true, 'description' => 'unique identifier'],
|
||||
'nickname' => ['type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'nickname or username'],
|
||||
'fullname' => ['type' => 'text', 'description' => 'display name'],
|
||||
'roles' => ['type' => 'int', 'not null' => true, 'default' => UserRoles::USER, 'description' => 'Bitmap of permissions this gsactor has'],
|
||||
'homepage' => ['type' => 'text', 'description' => 'identifying URL'],
|
||||
'bio' => ['type' => 'text', 'description' => 'descriptive biography'],
|
||||
'location' => ['type' => 'text', 'description' => 'physical location'],
|
||||
'lat' => ['type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'latitude'],
|
||||
'lon' => ['type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'longitude'],
|
||||
'location_id' => ['type' => 'int', 'description' => 'location id if possible'],
|
||||
'location_service' => ['type' => 'int', 'description' => 'service used to obtain location id'],
|
||||
'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
|
||||
'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
|
||||
'id' => ['type' => 'serial', 'not null' => true, 'description' => 'unique identifier'],
|
||||
'nickname' => ['type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'nickname or username'],
|
||||
'normalized_nickname' => ['type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'normalized (as per Nickanme::normalize) nickname or username'],
|
||||
'fullname' => ['type' => 'text', 'description' => 'display name'],
|
||||
'roles' => ['type' => 'int', 'not null' => true, 'default' => UserRoles::USER, 'description' => 'Bitmap of permissions this gsactor has'],
|
||||
'homepage' => ['type' => 'text', 'description' => 'identifying URL'],
|
||||
'bio' => ['type' => 'text', 'description' => 'descriptive biography'],
|
||||
'location' => ['type' => 'text', 'description' => 'physical location'],
|
||||
'lat' => ['type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'latitude'],
|
||||
'lon' => ['type' => 'numeric', 'precision' => 10, 'scale' => 7, 'description' => 'longitude'],
|
||||
'location_id' => ['type' => 'int', 'description' => 'location id if possible'],
|
||||
'location_service' => ['type' => 'int', 'description' => 'service used to obtain location id'],
|
||||
'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
|
||||
'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
|
||||
],
|
||||
'primary key' => ['id'],
|
||||
'indexes' => [
|
||||
'gsactor_nickname_idx' => ['nickname'],
|
||||
'gsactor_nickname_idx' => ['nickname'],
|
||||
'gsactor_normalized_nickname_idx' => ['normalized_nickname'],
|
||||
],
|
||||
'fulltext indexes' => [
|
||||
'gsactor_fulltext_idx' => ['nickname', 'fullname', 'location', 'bio', 'homepage'],
|
||||
|
@ -19,7 +19,9 @@
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Core\DB\DB;
|
||||
use App\Core\Entity;
|
||||
|
||||
use DateTimeInterface;
|
||||
|
||||
/**
|
||||
@ -66,31 +68,35 @@ class LocalGroup extends Entity
|
||||
return $this->nickname;
|
||||
}
|
||||
|
||||
public function setCreated(\DateTimeInterface $created): self
|
||||
public function setCreated(DateTimeInterface $created): self
|
||||
{
|
||||
$this->created = $created;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreated(): \DateTimeInterface
|
||||
public function getCreated(): DateTimeInterface
|
||||
{
|
||||
return $this->created;
|
||||
}
|
||||
|
||||
public function setModified(\DateTimeInterface $modified): self
|
||||
public function setModified(DateTimeInterface $modified): self
|
||||
{
|
||||
$this->modified = $modified;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getModified(): \DateTimeInterface
|
||||
public function getModified(): DateTimeInterface
|
||||
{
|
||||
return $this->modified;
|
||||
}
|
||||
|
||||
|
||||
// }}} Autocode
|
||||
|
||||
public function getActor()
|
||||
{
|
||||
return DB::find('gsactor', ['id' => $this->group_id]);
|
||||
}
|
||||
|
||||
public static function schemaDef(): array
|
||||
{
|
||||
return [
|
||||
|
Loading…
Reference in New Issue
Block a user