[DATABASE][TOOLS] Update local_user, SchemaDefDriver and bin/generate_entity_fields to use the phone_number type (which maps to a varchar 35 and does validation)

This commit is contained in:
Hugo Sales 2020-07-26 00:18:15 +00:00 committed by Hugo Sales
parent db52e282b9
commit db32a5fcfc
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
3 changed files with 31 additions and 29 deletions

View File

@ -9,17 +9,18 @@ define('ROOT', dirname(__DIR__));
require ROOT . '/vendor/autoload.php'; require ROOT . '/vendor/autoload.php';
const types = [ const types = [
'blob' => '', 'blob' => '',
'bool' => 'bool', 'bool' => 'bool',
'char' => 'string', 'char' => 'string',
'datetime' => '\DateTimeInterface', 'datetime' => '\DateTimeInterface',
'timestamp' => '\DateTimeInterface', 'timestamp' => '\DateTimeInterface',
'html' => 'string', 'html' => 'string',
'int' => 'int', 'int' => 'int',
'numeric' => 'float', 'numeric' => 'float',
'serial' => 'int', 'serial' => 'int',
'text' => 'string', 'text' => 'string',
'varchar' => 'string', 'varchar' => 'string',
'phone_number' => 'PhoneNumberType',
]; ];
$path = Yaml::parseFile(ROOT . '/config/services.yaml')['services']['app.core.schemadef_driver']['arguments'][0]; $path = Yaml::parseFile(ROOT . '/config/services.yaml')['services']['app.core.schemadef_driver']['arguments'][0];

View File

@ -40,17 +40,18 @@ class SchemaDefDriver extends StaticPHPDriver
* V2 DB type => Doctrine type * V2 DB type => Doctrine type
*/ */
private const types = [ private const types = [
'varchar' => 'string', 'varchar' => 'string',
'char' => 'string', // char is a fixed witdh varchar 'char' => 'string', // char is a fixed witdh varchar
'int' => 'integer', 'int' => 'integer',
'serial' => 'integer', 'serial' => 'integer',
'tinyint' => 'smallint', // no portable tinyint 'tinyint' => 'smallint', // no portable tinyint
'bigint' => 'bigint', 'bigint' => 'bigint',
'bool' => 'boolean', 'bool' => 'boolean',
'numeric' => 'decimal', 'numeric' => 'decimal',
'text' => 'text', 'text' => 'text',
'datetime' => 'datetime', 'datetime' => 'datetime',
'timestamp' => 'datetime', 'timestamp' => 'datetime',
'phone_number' => 'phone_number',
// Unused in V2, but might start being used // Unused in V2, but might start being used
'date' => 'date', 'date' => 'date',
'time' => 'time', 'time' => 'time',

View File

@ -52,7 +52,7 @@ class LocalUser implements UserInterface
private ?bool $is_email_verified; private ?bool $is_email_verified;
private ?string $language; private ?string $language;
private ?string $timezone; private ?string $timezone;
private ?string $sms_phone_number; private ?PhoneNumberType $phone_number;
private ?int $sms_carrier; private ?int $sms_carrier;
private ?string $sms_email; private ?string $sms_email;
private ?string $uri; private ?string $uri;
@ -132,14 +132,14 @@ class LocalUser implements UserInterface
return $this->timezone; return $this->timezone;
} }
public function setSmsPhoneNumber(?string $sms_phone_number): self public function setPhoneNumber(?PhoneNumberType $phone_number): self
{ {
$this->sms_phone_number = $sms_phone_number; $this->phone_number = $phone_number;
return $this; return $this;
} }
public function getSmsPhoneNumber(): ?string public function getPhoneNumber(): ?PhoneNumberType
{ {
return $this->sms_phone_number; return $this->phone_number;
} }
public function setSmsCarrier(?int $sms_carrier): self public function setSmsCarrier(?int $sms_carrier): self
@ -248,7 +248,7 @@ class LocalUser implements UserInterface
'is_email_verified' => ['type' => 'bool', 'default' => false, 'description' => 'Whether the user opened the comfirmation email'], 'is_email_verified' => ['type' => 'bool', 'default' => false, 'description' => 'Whether the user opened the comfirmation email'],
'language' => ['type' => 'varchar', 'length' => 50, 'description' => 'preferred language'], 'language' => ['type' => 'varchar', 'length' => 50, 'description' => 'preferred language'],
'timezone' => ['type' => 'varchar', 'length' => 50, 'description' => 'timezone'], 'timezone' => ['type' => 'varchar', 'length' => 50, 'description' => 'timezone'],
'sms_phone_number' => ['type' => 'varchar', 'length' => 64, 'description' => 'sms phone number'], 'phone_number' => ['type' => 'phone_number', 'description' => 'phone number'],
'sms_carrier' => ['type' => 'int', 'description' => 'foreign key to sms_carrier'], 'sms_carrier' => ['type' => 'int', 'description' => 'foreign key to sms_carrier'],
'sms_email' => ['type' => 'varchar', 'length' => 191, 'description' => 'built from sms and carrier (see 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'], 'uri' => ['type' => 'varchar', 'length' => 191, 'description' => 'universally unique identifier, usually a tag URI'],
@ -262,7 +262,7 @@ class LocalUser implements UserInterface
'unique keys' => [ 'unique keys' => [
'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_sms_key' => ['sms_phone_number'], 'user_phone_number_key' => ['phone_number'],
'user_uri_key' => ['uri'], 'user_uri_key' => ['uri'],
], ],
'foreign keys' => [ 'foreign keys' => [