Skip to content

Commit

Permalink
Merge pull request #283 from dotkernel/issue-264
Browse files Browse the repository at this point in the history
bump for doctrine orm 2 -> 3, dbal 3 -> 4 through roave psr container
  • Loading branch information
arhimede authored Jun 17, 2024
2 parents d6f82af + d1ebb75 commit 33f5edf
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 71 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"ext-json": "*",
"dotkernel/dot-cache": "^4.0",
"dotkernel/dot-cli": "^3.5.0",
"dotkernel/dot-data-fixtures": "^1.1.3",
"dotkernel/dot-data-fixtures": "^1.2.2",
"dotkernel/dot-dependency-injection": "^1.0",
"dotkernel/dot-errorhandler": "^3.3.2",
"dotkernel/dot-mail": "^4.1.1",
Expand All @@ -76,8 +76,9 @@
"mezzio/mezzio-hal": "^2.9",
"mezzio/mezzio-problem-details": "^1.13.1",
"mezzio/mezzio-twigrenderer": "^2.15.0",
"ramsey/uuid-doctrine": "^2.0.0",
"roave/psr-container-doctrine": "^4.1.0",
"ramsey/uuid-doctrine": "^2.1.0",
"roave/psr-container-doctrine": "^5.1.0",
"doctrine/orm": "^3.2",
"symfony/filesystem": "^7.0.3"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion config/autoload/local.test.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ return [
'connection' => [
'orm_default' => [
'params' => [
'url' => 'sqlite:///:memory:',
'url' => 'sqlite3:///:memory:',
],
],
],
Expand Down
2 changes: 1 addition & 1 deletion config/migrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'table_storage' => [
'table_name' => 'doctrine_migration_versions',
'version_column_name' => 'version',
'version_column_length' => 1024,
'version_column_length' => 191,
'executed_at_column_name' => 'executed_at',
'execution_time_column_name' => 'execution_time',
],
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 Version20240529123458 extends AbstractMigration
final class Version20240613153602 extends AbstractMigration
{
public function getDescription(): string
{
Expand All @@ -20,22 +20,22 @@ 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)\', identity VARCHAR(100) NOT NULL, firstName VARCHAR(255) NOT NULL, lastName VARCHAR(255) NOT NULL, password VARCHAR(100) NOT NULL, status VARCHAR(20) NOT NULL, 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)\', roleUuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary)\', 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_role (uuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary)\', 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');
$this->addSql('CREATE TABLE oauth_access_tokens (id INT UNSIGNED AUTO_INCREMENT NOT NULL, client_id INT UNSIGNED DEFAULT NULL, user_id VARCHAR(255) DEFAULT NULL, token VARCHAR(100) NOT NULL, revoked TINYINT(1) DEFAULT 0 NOT NULL, expires_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_CA42527C19EB6921 (client_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE oauth_access_token_scopes (access_token_id INT UNSIGNED NOT NULL, scope_id INT UNSIGNED NOT NULL, INDEX IDX_9FDF62E92CCB2688 (access_token_id), INDEX IDX_9FDF62E9682B5931 (scope_id), PRIMARY KEY(access_token_id, scope_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE oauth_auth_codes (id INT UNSIGNED AUTO_INCREMENT NOT NULL, client_id INT UNSIGNED DEFAULT NULL, revoked TINYINT(1) DEFAULT 0 NOT NULL, expiresDatetime DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_BB493F8319EB6921 (client_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE oauth_auth_code_scopes (auth_code_id INT UNSIGNED NOT NULL, scope_id INT UNSIGNED NOT NULL, INDEX IDX_988BFFBF69FEDEE4 (auth_code_id), INDEX IDX_988BFFBF682B5931 (scope_id), PRIMARY KEY(auth_code_id, scope_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE oauth_clients (id INT UNSIGNED AUTO_INCREMENT NOT NULL, user_id BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid_binary)\', name VARCHAR(40) NOT NULL, secret VARCHAR(100) DEFAULT NULL, redirect VARCHAR(191) NOT NULL, revoked TINYINT(1) DEFAULT 0 NOT NULL, isConfidential TINYINT(1) DEFAULT 0 NOT NULL, INDEX IDX_13CE8101A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE oauth_refresh_tokens (id INT UNSIGNED AUTO_INCREMENT NOT NULL, access_token_id INT UNSIGNED DEFAULT NULL, revoked TINYINT(1) DEFAULT 0 NOT NULL, expires_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_5AB6872CCB2688 (access_token_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE oauth_scopes (id INT UNSIGNED AUTO_INCREMENT NOT NULL, scope VARCHAR(191) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE user (uuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary)\', identity VARCHAR(191) NOT NULL, password VARCHAR(191) NOT NULL, status VARCHAR(20) NOT NULL, isDeleted TINYINT(1) NOT NULL, hash VARCHAR(64) NOT NULL, created DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', UNIQUE INDEX UNIQ_8D93D6496A95E9C4 (identity), UNIQUE INDEX UNIQ_8D93D649D1B862B8 (hash), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE user_roles (userUuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary)\', roleUuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary)\', INDEX IDX_54FCD59FD73087E9 (userUuid), INDEX IDX_54FCD59F88446210 (roleUuid), PRIMARY KEY(userUuid, roleUuid)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE user_avatar (uuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary)\', name VARCHAR(191) NOT NULL, created DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', userUuid BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid_binary)\', UNIQUE INDEX UNIQ_73256912D73087E9 (userUuid), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE user_detail (uuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary)\', firstName VARCHAR(191) DEFAULT NULL, lastName VARCHAR(191) DEFAULT NULL, email VARCHAR(191) NOT NULL, created DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', userUuid BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid_binary)\', UNIQUE INDEX UNIQ_4B5464AED73087E9 (userUuid), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE user_reset_password (uuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary)\', expires DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', hash VARCHAR(64) NOT NULL, status VARCHAR(20) NOT NULL, created DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', userUuid BINARY(16) DEFAULT NULL COMMENT \'(DC2Type:uuid_binary)\', UNIQUE INDEX UNIQ_D21DE3BCD1B862B8 (hash), INDEX IDX_D21DE3BCD73087E9 (userUuid), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE user_role (uuid BINARY(16) NOT NULL COMMENT \'(DC2Type:uuid_binary)\', name VARCHAR(20) NOT NULL, created DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', UNIQUE INDEX UNIQ_2DE8C6A35E237E06 (name), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('CREATE TABLE admin (uuid BINARY(16) NOT NULL, identity VARCHAR(100) NOT NULL, firstName VARCHAR(191) NOT NULL, lastName VARCHAR(191) NOT NULL, password VARCHAR(100) NOT NULL, status VARCHAR(20) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_880E0D766A95E9C4 (identity), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE admin_roles (userUuid BINARY(16) NOT NULL, roleUuid BINARY(16) NOT NULL, INDEX IDX_1614D53DD73087E9 (userUuid), INDEX IDX_1614D53D88446210 (roleUuid), PRIMARY KEY(userUuid, roleUuid)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE admin_role (uuid BINARY(16) NOT NULL, name VARCHAR(30) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_7770088A5E237E06 (name), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE oauth_access_tokens (id INT UNSIGNED AUTO_INCREMENT NOT NULL, user_id VARCHAR(25) DEFAULT NULL, token VARCHAR(100) NOT NULL, revoked TINYINT(1) DEFAULT 0 NOT NULL, expires_at DATETIME NOT NULL, client_id INT UNSIGNED DEFAULT NULL, INDEX IDX_CA42527C19EB6921 (client_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE oauth_access_token_scopes (access_token_id INT UNSIGNED NOT NULL, scope_id INT UNSIGNED NOT NULL, INDEX IDX_9FDF62E92CCB2688 (access_token_id), INDEX IDX_9FDF62E9682B5931 (scope_id), PRIMARY KEY(access_token_id, scope_id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE oauth_auth_codes (id INT UNSIGNED AUTO_INCREMENT NOT NULL, revoked TINYINT(1) DEFAULT 0 NOT NULL, expiresDatetime DATETIME DEFAULT NULL, client_id INT UNSIGNED DEFAULT NULL, INDEX IDX_BB493F8319EB6921 (client_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE oauth_auth_code_scopes (auth_code_id INT UNSIGNED NOT NULL, scope_id INT UNSIGNED NOT NULL, INDEX IDX_988BFFBF69FEDEE4 (auth_code_id), INDEX IDX_988BFFBF682B5931 (scope_id), PRIMARY KEY(auth_code_id, scope_id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE oauth_clients (id INT UNSIGNED AUTO_INCREMENT NOT NULL, name VARCHAR(40) NOT NULL, secret VARCHAR(100) DEFAULT NULL, redirect VARCHAR(191) NOT NULL, revoked TINYINT(1) DEFAULT 0 NOT NULL, isConfidential TINYINT(1) DEFAULT 0 NOT NULL, user_id BINARY(16) DEFAULT NULL, INDEX IDX_13CE8101A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE oauth_refresh_tokens (id INT UNSIGNED AUTO_INCREMENT NOT NULL, revoked TINYINT(1) DEFAULT 0 NOT NULL, expires_at DATETIME NOT NULL, access_token_id INT UNSIGNED DEFAULT NULL, INDEX IDX_5AB6872CCB2688 (access_token_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE oauth_scopes (id INT UNSIGNED AUTO_INCREMENT NOT NULL, scope VARCHAR(191) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE user (uuid BINARY(16) NOT NULL, identity VARCHAR(191) NOT NULL, password VARCHAR(191) NOT NULL, status VARCHAR(20) NOT NULL, isDeleted TINYINT(1) NOT NULL, hash VARCHAR(64) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_8D93D6496A95E9C4 (identity), UNIQUE INDEX UNIQ_8D93D649D1B862B8 (hash), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE user_roles (userUuid BINARY(16) NOT NULL, roleUuid BINARY(16) NOT NULL, INDEX IDX_54FCD59FD73087E9 (userUuid), INDEX IDX_54FCD59F88446210 (roleUuid), PRIMARY KEY(userUuid, roleUuid)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE user_avatar (uuid BINARY(16) NOT NULL, name VARCHAR(191) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, userUuid BINARY(16) DEFAULT NULL, UNIQUE INDEX UNIQ_73256912D73087E9 (userUuid), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE user_detail (uuid BINARY(16) NOT NULL, firstName VARCHAR(191) DEFAULT NULL, lastName VARCHAR(191) DEFAULT NULL, email VARCHAR(191) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, userUuid BINARY(16) DEFAULT NULL, UNIQUE INDEX UNIQ_4B5464AED73087E9 (userUuid), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE user_reset_password (uuid BINARY(16) NOT NULL, expires DATETIME NOT NULL, hash VARCHAR(64) NOT NULL, status VARCHAR(20) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, userUuid BINARY(16) DEFAULT NULL, UNIQUE INDEX UNIQ_D21DE3BCD1B862B8 (hash), INDEX IDX_D21DE3BCD73087E9 (userUuid), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE user_role (uuid BINARY(16) NOT NULL, name VARCHAR(20) NOT NULL, created DATETIME NOT NULL, updated DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_2DE8C6A35E237E06 (name), PRIMARY KEY(uuid)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('ALTER TABLE admin_roles ADD CONSTRAINT FK_1614D53DD73087E9 FOREIGN KEY (userUuid) REFERENCES admin (uuid)');
$this->addSql('ALTER TABLE admin_roles ADD CONSTRAINT FK_1614D53D88446210 FOREIGN KEY (roleUuid) REFERENCES admin_role (uuid)');
$this->addSql('ALTER TABLE oauth_access_tokens ADD CONSTRAINT FK_CA42527C19EB6921 FOREIGN KEY (client_id) REFERENCES oauth_clients (id)');
Expand Down
5 changes: 0 additions & 5 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
<code>matching</code>
</UndefinedInterfaceMethod>
</file>
<file src="src/User/src/Repository/UserRepository.php">
<TooManyArguments>
<code>orX</code>
</TooManyArguments>
</file>
<file src="src/App/src/Entity/OAuthAccessToken.php">
<UndefinedInterfaceMethod>
<code>matching</code>
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 @@ -8,6 +8,7 @@
use Api\App\Entity\AbstractEntity;
use Api\App\Entity\PasswordTrait;
use Api\App\Entity\RoleInterface;
use Api\App\Entity\TimestampsTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;

Check warning on line 13 in src/Admin/src/Entity/Admin.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'Collection'
use Doctrine\ORM\Mapping as ORM;
Expand All @@ -19,6 +20,7 @@
class Admin extends AbstractEntity implements UserEntityInterface

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

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'UserEntityInterface'
{
use PasswordTrait;
use TimestampsTrait;

public const STATUS_ACTIVE = 'active';
public const STATUS_INACTIVE = 'inactive';
Expand All @@ -30,10 +32,10 @@ class Admin extends AbstractEntity implements UserEntityInterface
#[ORM\Column(name: "identity", type: "string", length: 100, unique: true)]
protected string $identity = '';

#[ORM\Column(name: "firstName", type: "string", length: 255)]
#[ORM\Column(name: "firstName", type: "string", length: 191)]
protected string $firstName = '';

#[ORM\Column(name: "lastName", type: "string", length: 255)]
#[ORM\Column(name: "lastName", type: "string", length: 191)]

Check warning on line 38 in src/Admin/src/Entity/Admin.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'Column'
protected string $lastName = '';

#[ORM\Column(name: "password", type: "string", length: 100)]

Check warning on line 41 in src/Admin/src/Entity/Admin.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'Column'
Expand Down
3 changes: 3 additions & 0 deletions src/Admin/src/Entity/AdminRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
use Api\Admin\Repository\AdminRoleRepository;
use Api\App\Entity\AbstractEntity;
use Api\App\Entity\RoleInterface;
use Api\App\Entity\TimestampsTrait;
use Doctrine\ORM\Mapping as ORM;

Check warning on line 11 in src/Admin/src/Entity/AdminRole.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'Mapping'

#[ORM\Entity(repositoryClass: AdminRoleRepository::class)]

Check warning on line 13 in src/Admin/src/Entity/AdminRole.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'Entity'
#[ORM\Table("admin_role")]

Check warning on line 14 in src/Admin/src/Entity/AdminRole.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'Table'
#[ORM\HasLifecycleCallbacks]

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

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'HasLifecycleCallbacks'
class AdminRole extends AbstractEntity implements RoleInterface
{
use TimestampsTrait;

public const ROLE_ADMIN = 'admin';
public const ROLE_SUPERUSER = 'superuser';
public const ROLES = [
Expand Down
42 changes: 2 additions & 40 deletions src/App/src/Entity/AbstractEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Api\App\Entity;

use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Laminas\Stdlib\ArraySerializableInterface;

Check warning on line 8 in src/App/src/Entity/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'ArraySerializableInterface'
use Ramsey\Uuid\Uuid;

Check warning on line 9 in src/App/src/Entity/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'Uuid'
Expand All @@ -14,60 +13,23 @@
use function method_exists;
use function ucfirst;

#[ORM\MappedSuperclass]

Check warning on line 16 in src/App/src/Entity/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'MappedSuperclass'
abstract class AbstractEntity implements ArraySerializableInterface
{
#[ORM\Id]

Check warning on line 19 in src/App/src/Entity/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'Id'
#[ORM\Column(name: 'uuid', type: "uuid_binary", unique: true)]
protected UuidInterface $uuid;

#[ORM\Column(name: "created", type: "datetime_immutable")]
protected DateTimeImmutable $created;

#[ORM\Column(name: "updated", type: "datetime_immutable", nullable: true)]
protected ?DateTimeImmutable $updated = null;

public function __construct()
{
$this->uuid = Uuid::uuid4();
$this->created = new DateTimeImmutable();
$this->uuid = Uuid::uuid4();
}

public function getUuid(): UuidInterface

Check warning on line 28 in src/App/src/Entity/AbstractEntity.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'UuidInterface'
{
return $this->uuid;
}

public function getCreated(): ?DateTimeImmutable
{
return $this->created;
}

public function getCreatedFormatted(string $dateFormat = 'Y-m-d H:i:s'): string
{
return $this->created->format($dateFormat);
}

public function getUpdated(): ?DateTimeImmutable
{
return $this->updated;
}

public function getUpdatedFormatted(string $dateFormat = 'Y-m-d H:i:s'): ?string
{
if ($this->updated instanceof DateTimeImmutable) {
return $this->updated->format($dateFormat);
}

return null;
}

#[ORM\PrePersist]
#[ORM\PreUpdate]
public function touch(): void
{
$this->updated = new DateTimeImmutable();
}

public function exchangeArray(array $array): void
{
foreach ($array as $property => $values) {
Expand Down
2 changes: 1 addition & 1 deletion src/App/src/Entity/OAuthAccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class OAuthAccessToken implements AccessTokenEntityInterface
#[ORM\JoinColumn(name: "client_id", referencedColumnName: "id")]
private ClientEntityInterface $client;

#[ORM\Column(name: "user_id", type: "string", nullable: true)]
#[ORM\Column(name: "user_id", type: "string", length: 25, nullable: true)]
private ?string $userId;

#[ORM\Column(name: "token", type: "string", length: 100)]
Expand Down
54 changes: 54 additions & 0 deletions src/App/src/Entity/TimestampsTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace Api\App\Entity;

use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;

Check warning on line 8 in src/App/src/Entity/TimestampsTrait.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'Mapping'

#[ORM\HasLifecycleCallbacks]
trait TimestampsTrait
{
#[ORM\Column(name: "created", type: "datetime_immutable")]

Check warning on line 13 in src/App/src/Entity/TimestampsTrait.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'Column'
protected DateTimeImmutable $created;

#[ORM\Column(name: "updated", type: "datetime_immutable", nullable: true)]

Check warning on line 16 in src/App/src/Entity/TimestampsTrait.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'Column'
protected ?DateTimeImmutable $updated = null;

public function getCreated(): ?DateTimeImmutable
{
return $this->created;
}

public function getCreatedFormatted(string $dateFormat = 'Y-m-d H:i:s'): string
{
return $this->created->format($dateFormat);
}

public function getUpdated(): ?DateTimeImmutable
{
return $this->updated;
}

public function getUpdatedFormatted(string $dateFormat = 'Y-m-d H:i:s'): ?string
{
if ($this->updated instanceof DateTimeImmutable) {
return $this->updated->format($dateFormat);
}

return null;
}

#[ORM\PrePersist]
public function created(): void
{
$this->created = new DateTimeImmutable();
}

#[ORM\PreUpdate]

Check warning on line 49 in src/App/src/Entity/TimestampsTrait.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined class

Undefined class 'PreUpdate'
public function touch(): void
{
$this->updated = new DateTimeImmutable();
}
}
Loading

0 comments on commit 33f5edf

Please sign in to comment.