diff --git a/src/Entity/ActorLanguage.php b/src/Entity/ActorLanguage.php new file mode 100644 index 0000000000..7490db4cec --- /dev/null +++ b/src/Entity/ActorLanguage.php @@ -0,0 +1,85 @@ +. + +// }}} + +namespace App\Entity; + +use App\Core\DB\DB; +use App\Core\Entity; + +/** + * Entity for actor languages + * + * @category DB + * @package GNUsocial + * + * @author Hugo Sales + * @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'], + ], + ]; + } +} diff --git a/src/Entity/Language.php b/src/Entity/Language.php new file mode 100644 index 0000000000..483871534f --- /dev/null +++ b/src/Entity/Language.php @@ -0,0 +1,97 @@ +. + +// }}} + +namespace App\Entity; + +use App\Core\Entity; + +/** + * Entity for languages + * + * @category DB + * @package GNUsocial + * + * @author Hugo Sales + * @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'], + ], + ]; + } +} diff --git a/src/Entity/LocalUser.php b/src/Entity/LocalUser.php index b27f8f9212..3ff4eb89bb 100644 --- a/src/Entity/LocalUser.php +++ b/src/Entity/LocalUser.php @@ -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 @@ -387,23 +387,23 @@ class LocalUser extends Entity implements UserInterface 'name' => 'local_user', 'description' => 'local users, bots, etc', 'fields' => [ - 'id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to actor table'], - 'nickname' => ['type' => 'varchar', 'not null' => true, 'length' => 64, 'description' => 'nickname or username, foreign key to actor'], - '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.'], - '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'], - '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'], - 'sms_email' => ['type' => 'varchar', 'length' => 191, 'description' => 'built from sms and carrier (see sms_carrier)'], - 'uri' => ['type' => 'varchar', 'length' => 191, 'description' => 'universally unique identifier, usually a tag URI'], - 'auto_follow_back' => ['type' => 'bool', 'default' => false, 'description' => 'automatically follow users who follow us'], - 'follow_policy' => ['type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => '0 = anybody can follow; 1 = require approval'], - 'is_stream_private' => ['type' => 'bool', 'default' => false, 'description' => 'whether to limit all notices to followers only'], - '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' => 'int', 'foreign key' => true, 'target' => 'Actor.id', 'multiplicity' => 'one to one', 'not null' => true, 'description' => 'foreign key to actor table'], + 'nickname' => ['type' => 'varchar', 'not null' => true, 'length' => 64, 'description' => 'nickname or username, foreign key to actor'], + '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.'], + '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'], + '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'], + 'sms_email' => ['type' => 'varchar', 'length' => 191, 'description' => 'built from sms and carrier (see sms_carrier)'], + 'uri' => ['type' => 'varchar', 'length' => 191, 'description' => 'universally unique identifier, usually a tag URI'], + 'auto_follow_back' => ['type' => 'bool', 'default' => false, 'description' => 'automatically follow users who follow us'], + 'follow_policy' => ['type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => '0 = anybody can follow; 1 = require approval'], + 'is_stream_private' => ['type' => 'bool', 'default' => false, 'description' => 'whether to limit all notices to followers only'], + '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'], 'unique keys' => [ diff --git a/src/Entity/Note.php b/src/Entity/Note.php index d44fc991f1..569d280db0 100644 --- a/src/Entity/Note.php +++ b/src/Entity/Note.php @@ -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 ]; } }