[ENTITY] Add a [Language] table, which has a char 64 field that maps to an int. This is then used in [Note], [LocalUser] and [ActorLanguage]

This commit is contained in:
Hugo Sales 2021-10-28 01:26:16 +01:00
parent 3388e0e8f1
commit 18aeeb3850
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
4 changed files with 206 additions and 24 deletions

View File

@ -0,0 +1,85 @@
<?php
declare(strict_types = 1);
// {{{ License
// 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
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// 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/>.
// }}}
namespace App\Entity;
use App\Core\DB\DB;
use App\Core\Entity;
/**
* Entity for actor languages
*
* @category DB
* @package GNUsocial
*
* @author Hugo Sales <hugo@hsal.es>
* @copyright 2021 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class ActorLanguage extends Entity
{
// {{{ Autocode
// @codeCoverageIgnoreStart
private int $actor_id;
private int $language_id;
public function setActorId(int $actor_id): self
{
$this->actor_id = $actor_id;
return $this;
}
public function getActorId(): int
{
return $this->actor_id;
}
public function setLanguageId(int $language_id): self
{
$this->language_id = $language_id;
return $this;
}
public function getLanguageId(): int
{
return $this->language_id;
}
// @codeCoverageIgnoreEnd
// }}} Autocode
public static function schemaDef(): array
{
return [
'name' => 'actor_language',
'description' => 'join table where one actor can have many languages',
'fields' => [
'actor_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'the actor this language entry refers to'],
'language_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Language.id', 'multiplicity' => 'many to many', 'not null' => true, 'description' => 'the language this entry refers to'],
],
'primary key' => ['actor_id', 'language_id'],
'indexes' => [
'actor_idx' => ['actor_id'],
],
];
}
}

97
src/Entity/Language.php Normal file
View File

@ -0,0 +1,97 @@
<?php
declare(strict_types = 1);
// {{{ License
// 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
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// 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/>.
// }}}
namespace App\Entity;
use App\Core\Entity;
/**
* Entity for languages
*
* @category DB
* @package GNUsocial
*
* @author Hugo Sales <hugo@hsal.es>
* @copyright 2021 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class Language extends Entity
{
// {{{ Autocode
// @codeCoverageIgnoreStart
private int $id;
private string $language;
private \DateTimeInterface $created;
public function setId(int $id): self
{
$this->id = $id;
return $this;
}
public function getId(): int
{
return $this->id;
}
public function setLanguage(string $language): self
{
$this->language = $language;
return $this;
}
public function getLanguage(): string
{
return $this->language;
}
public function setCreated(DateTimeInterface $created): self
{
$this->created = $created;
return $this;
}
public function getCreated(): DateTimeInterface
{
return $this->created;
}
// @codeCoverageIgnoreEnd
// }}} Autocode
public static function schemaDef(): array
{
return [
'name' => 'language',
'description' => 'all known languages',
'fields' => [
'id' => ['type' => 'serial', 'not null' => true, 'description' => 'unique identifier'],
'language' => ['type' => 'char', 'length' => 64, 'description' => 'The locale identifier for the language of a note. 2-leter-iso-language-code_4-leter-script-code_2-leter-iso-country-code, but kept longer in case we get a different format'],
'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
],
'primary key' => ['id'],
'indexes' => [
'language_idx' => ['language'],
],
];
}
}

View File

@ -57,7 +57,7 @@ class LocalUser extends Entity implements UserInterface
private ?string $outgoing_email;
private ?string $incoming_email;
private ?bool $is_email_verified;
private ?string $language;
private ?int $preferred_language;
private ?string $timezone;
private ?PhoneNumber $phone_number;
private ?int $sms_carrier;
@ -135,15 +135,15 @@ class LocalUser extends Entity implements UserInterface
return $this->is_email_verified;
}
public function setLanguage(?string $language): self
public function setPreferredLanguage(?string $preferred_language): self
{
$this->language = $language;
$this->preferred_language = $preferred_language;
return $this;
}
public function getLanguage(): ?string
public function getPreferredLanguage(): ?int
{
return $this->language;
return $this->preferred_language;
}
public function setTimezone(?string $timezone): self
@ -393,7 +393,7 @@ class LocalUser extends Entity implements UserInterface
'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'],
'is_email_verified' => ['type' => 'bool', 'default' => false, 'description' => 'Whether the user opened the comfirmation email'],
'language' => ['type' => 'varchar', 'length' => 50, 'description' => 'preferred language'],
'preferred_language' => ['type' => 'int', 'foreign key' => true, 'target' => 'Language.id', 'multiplicity' => 'one to many', 'description' => 'preferred language'],
'timezone' => ['type' => 'varchar', 'length' => 50, 'description' => 'timezone'],
'phone_number' => ['type' => 'phone_number', 'description' => 'phone number'],
'sms_carrier' => ['type' => 'int', 'foreign key' => true, 'target' => 'SmsCarrier.id', 'multiplicity' => 'one to one', 'description' => 'foreign key to sms_carrier'],

View File

@ -352,7 +352,7 @@ class Note extends Entity
'repeat_of' => ['type' => 'int', 'foreign key' => true, 'target' => 'Note.id', 'multiplicity' => 'one to one', 'description' => 'note this is a repeat of'],
'scope' => ['type' => 'int', 'not null' => true, 'default' => VisibilityScope::PUBLIC, 'description' => 'bit map for distribution scope; 0 = everywhere; 1 = this server only; 2 = addressees; 4 = groups; 8 = followers; 16 = messages; null = default'],
'url' => ['type' => 'text', 'description' => 'Permalink to Note'],
'language' => ['type' => 'varchar', 'length' => 10, 'description' => 'The locale identifier for the language of a note. 2-leter-iso-language-code_4-leter-script-code_2-leter-iso-country-code'],
'language' => ['type' => 'int', 'foreign key' => true, 'target' => 'Language.id', 'multiplicity' => 'one to many', 'description' => 'The language for this note'],
'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'],
],
@ -365,7 +365,7 @@ class Note extends Entity
'note_conversation_created_idx' => ['conversation', 'created'],
'note_reply_to_idx' => ['reply_to'],
],
'fulltext indexes' => ['notice_fulltext_idx' => ['content']],
'fulltext indexes' => ['notice_fulltext_idx' => ['content']], // TODO make this configurable
];
}
}