Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented enumType class for admin status column #216

Draft
wants to merge 1 commit into
base: 4.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/autoload/doctrine.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Ramsey\Uuid\Doctrine\UuidBinaryType;
use Ramsey\Uuid\Doctrine\UuidType;
use Roave\PsrContainerDoctrine\EntityManagerFactory;
use Frontend\Admin\Entity\EnumAdminStatus;

return [
'dependencies' => [
Expand Down Expand Up @@ -43,6 +44,7 @@
UuidType::NAME => UuidType::class,
UuidBinaryType::NAME => UuidBinaryType::class,
UuidBinaryOrderedTimeType::NAME => UuidBinaryOrderedTimeType::class,
EnumAdminStatus::NAME => EnumAdminStatus::class,
],
'cache' => [
PhpFileCache::class => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20231211222316 extends AbstractMigration
final class Version20240112105344 extends AbstractMigration
{
public function getDescription(): string
{
Expand All @@ -20,7 +20,7 @@ public function getDescription(): string
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE admin (uuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary_ordered_time)\', identity VARCHAR(100) NOT NULL, firstName VARCHAR(255) NOT NULL, lastName VARCHAR(255) NOT NULL, password VARCHAR(100) NOT NULL, status ENUM(\'pending\', \'active\'), created DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', UNIQUE INDEX UNIQ_880E0D766A95E9C4 (identity), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE admin (uuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary_ordered_time)\', identity VARCHAR(100) NOT NULL, firstName VARCHAR(255) NOT NULL, lastName VARCHAR(255) NOT NULL, password VARCHAR(100) NOT NULL, status ENUM(active, pending, deleted) DEFAULT \'active\' DEFAULT \'active\' NOT NULL COMMENT \'(DC2Type:admin-enum-status)\', created DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', UNIQUE INDEX UNIQ_880E0D766A95E9C4 (identity), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE admin_roles (userUuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary_ordered_time)\', roleUuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary_ordered_time)\', INDEX IDX_1614D53DD73087E9 (userUuid), INDEX IDX_1614D53D88446210 (roleUuid), PRIMARY KEY(userUuid, roleUuid)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE admin_login (uuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary_ordered_time)\', adminIp VARCHAR(50) DEFAULT NULL, country VARCHAR(50) DEFAULT NULL, continent VARCHAR(50) DEFAULT NULL, organization VARCHAR(50) DEFAULT NULL, deviceType VARCHAR(20) DEFAULT NULL, deviceBrand VARCHAR(20) DEFAULT NULL, deviceModel VARCHAR(40) DEFAULT NULL, isMobile ENUM(\'yes\', \'no\'), osName VARCHAR(20) DEFAULT NULL, osVersion VARCHAR(20) DEFAULT NULL, osPlatform VARCHAR(20) DEFAULT NULL, clientType VARCHAR(20) DEFAULT NULL, clientName VARCHAR(40) DEFAULT NULL, clientEngine VARCHAR(20) DEFAULT NULL, clientVersion VARCHAR(20) DEFAULT NULL, loginStatus ENUM(\'success\', \'fail\'), identity VARCHAR(100) DEFAULT NULL, created DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE admin_role (uuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary_ordered_time)\', name VARCHAR(30) NOT NULL, created DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', UNIQUE INDEX UNIQ_7770088A5E237E06 (name), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
Expand Down
6 changes: 4 additions & 2 deletions src/Admin/src/Entity/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ class Admin extends AbstractEntity implements AdminInterface
{
public const STATUS_ACTIVE = 'active';
public const STATUS_INACTIVE = 'pending';
public const STATUS_DELETED = 'deleted';
public const STATUSES = [
self::STATUS_ACTIVE,
self::STATUS_INACTIVE,
self::STATUS_DELETED
];

#[ORM\Column(name: "identity", type: "string", length: 100, unique: true, nullable: false)]
Expand All @@ -39,10 +41,10 @@ class Admin extends AbstractEntity implements AdminInterface

#[ORM\Column(
name: "status",
type: "string",
type: "admin-enum-status",
length: 20,
nullable: false,
columnDefinition: "ENUM('pending', 'active')"
options: ["values" => self::STATUSES, "default" => self::STATUS_ACTIVE]
)]
protected string $status = self::STATUS_ACTIVE;

Expand Down
32 changes: 32 additions & 0 deletions src/Admin/src/Entity/EnumAdminStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Frontend\Admin\Entity;

use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;

class EnumAdminStatus extends Type
{
const NAME = 'admin-enum-status';

public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string

Check failure on line 12 in src/Admin/src/Entity/EnumAdminStatus.php

View workflow job for this annotation

GitHub Actions / PHP 8.1-ubuntu-latest

ParamNameMismatch

src/Admin/src/Entity/EnumAdminStatus.php:12:45: ParamNameMismatch: Argument 1 of Frontend\Admin\Entity\EnumAdminStatus::getSQLDeclaration has wrong name $fieldDeclaration, expecting $column as defined by Doctrine\DBAL\Types\Type::getSQLDeclaration (see https://psalm.dev/230)

Check failure on line 12 in src/Admin/src/Entity/EnumAdminStatus.php

View workflow job for this annotation

GitHub Actions / PHP 8.2-ubuntu-latest

ParamNameMismatch

src/Admin/src/Entity/EnumAdminStatus.php:12:45: ParamNameMismatch: Argument 1 of Frontend\Admin\Entity\EnumAdminStatus::getSQLDeclaration has wrong name $fieldDeclaration, expecting $column as defined by Doctrine\DBAL\Types\Type::getSQLDeclaration (see https://psalm.dev/230)

Check warning on line 12 in src/Admin/src/Entity/EnumAdminStatus.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/src/Entity/EnumAdminStatus.php#L12

Added line #L12 was not covered by tests
{
return "ENUM(".implode(", ", $fieldDeclaration["values"])
. ") DEFAULT '" . $fieldDeclaration["default"] . "'";

Check warning on line 15 in src/Admin/src/Entity/EnumAdminStatus.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/src/Entity/EnumAdminStatus.php#L14-L15

Added lines #L14 - L15 were not covered by tests
}

public function convertToPHPValue($value, AbstractPlatform $platform)

Check warning on line 18 in src/Admin/src/Entity/EnumAdminStatus.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/src/Entity/EnumAdminStatus.php#L18

Added line #L18 was not covered by tests
{
return $value;

Check warning on line 20 in src/Admin/src/Entity/EnumAdminStatus.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/src/Entity/EnumAdminStatus.php#L20

Added line #L20 was not covered by tests
}

public function getName(): string

Check warning on line 23 in src/Admin/src/Entity/EnumAdminStatus.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/src/Entity/EnumAdminStatus.php#L23

Added line #L23 was not covered by tests
{
return self::NAME;

Check warning on line 25 in src/Admin/src/Entity/EnumAdminStatus.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/src/Entity/EnumAdminStatus.php#L25

Added line #L25 was not covered by tests
}

public function requiresSQLCommentHint(AbstractPlatform $platform): bool

Check warning on line 28 in src/Admin/src/Entity/EnumAdminStatus.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/src/Entity/EnumAdminStatus.php#L28

Added line #L28 was not covered by tests
{
return true;

Check warning on line 30 in src/Admin/src/Entity/EnumAdminStatus.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/src/Entity/EnumAdminStatus.php#L30

Added line #L30 was not covered by tests
}
}
Loading