[DB] Fix local_user table to use a numeric id, since the username is editable

This commit is contained in:
Hugo Sales 2020-09-05 20:19:58 +00:00 committed by Hugo Sales
parent a69c9a4f25
commit 460cbbd4c9
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -1,6 +1,7 @@
<?php <?php
// {{{ License // {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social // This file is part of GNU social - https://www.gnu.org/software/social
// //
// GNU social is free software: you can redistribute it and/or modify // GNU social is free software: you can redistribute it and/or modify
@ -15,6 +16,7 @@
// //
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}} // }}}
namespace App\Entity; namespace App\Entity;
@ -46,7 +48,8 @@ class LocalUser extends Entity implements UserInterface
{ {
// {{{ Autocode // {{{ Autocode
private ?string $nickname; private int $id;
private string $nickname;
private ?string $password; private ?string $password;
private ?string $outgoing_email; private ?string $outgoing_email;
private ?string $incoming_email; private ?string $incoming_email;
@ -63,13 +66,24 @@ class LocalUser extends Entity implements UserInterface
private DateTimeInterface $created; private DateTimeInterface $created;
private DateTimeInterface $modified; private DateTimeInterface $modified;
public function setNickname(?string $nickname): self public function setId(int $id): self
{
$this->id = $id;
return $this;
}
public function getId(): int
{
return $this->id;
}
public function setNickname(string $nickname): self
{ {
$this->nickname = $nickname; $this->nickname = $nickname;
return $this; return $this;
} }
public function getNickname(): ?string public function getNickname(): string
{ {
return $this->nickname; return $this->nickname;
} }
@ -243,7 +257,7 @@ class LocalUser extends Entity implements UserInterface
public function getActor() public function getActor()
{ {
return DB::findOneBy('gsactor', ['nickname' => $this->nickname]); return DB::find('gsactor', ['id' => $this->id]);
} }
/** /**
@ -344,7 +358,8 @@ class LocalUser extends Entity implements UserInterface
'name' => 'local_user', 'name' => 'local_user',
'description' => 'local users, bots, etc', 'description' => 'local users, bots, etc',
'fields' => [ 'fields' => [
'nickname' => ['type' => 'varchar', 'length' => 64, 'description' => 'nickname or username, foreign key to gsactor'], 'id' => ['type' => 'int', 'not null' => true, 'description' => 'foreign key to gsactor table'],
'nickname' => ['type' => 'varchar', 'not null' => true, 'length' => 64, 'description' => 'nickname or username, foreign key to gsactor'],
'password' => ['type' => 'varchar', 'length' => 191, 'description' => 'salted password, can be null for users with federated authentication'], 'password' => ['type' => 'varchar', 'length' => 191, 'description' => 'salted password, can be null for users with federated authentication'],
'outgoing_email' => ['type' => 'varchar', 'length' => 191, 'description' => 'email address for password recovery, notifications, etc.'], 'outgoing_email' => ['type' => 'varchar', 'length' => 191, 'description' => 'email address for password recovery, notifications, etc.'],
'incoming_email' => ['type' => 'varchar', 'length' => 191, 'description' => 'email address for post-by-email'], 'incoming_email' => ['type' => 'varchar', 'length' => 191, 'description' => 'email address for post-by-email'],
@ -361,15 +376,16 @@ class LocalUser extends Entity implements UserInterface
'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], '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'], 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
], ],
'primary key' => ['nickname'], 'primary key' => ['id'],
'unique keys' => [ 'unique keys' => [
'user_nickname_key' => ['nickname'],
'user_outgoing_email_key' => ['outgoing_email'], 'user_outgoing_email_key' => ['outgoing_email'],
'user_incoming_email_key' => ['incoming_email'], 'user_incoming_email_key' => ['incoming_email'],
'user_phone_number_key' => ['phone_number'], 'user_phone_number_key' => ['phone_number'],
'user_uri_key' => ['uri'], 'user_uri_key' => ['uri'],
], ],
'foreign keys' => [ 'foreign keys' => [
'user_nickname_fkey' => ['gsactor', ['nickname' => 'nickname']], 'user_id_fkey' => ['gsactor', ['id' => 'id']],
'user_carrier_fkey' => ['sms_carrier', ['sms_carrier' => 'id']], 'user_carrier_fkey' => ['sms_carrier', ['sms_carrier' => 'id']],
], ],
'indexes' => [ 'indexes' => [