diff --git a/config/packages/doctrine.yaml b/config/packages/doctrine.yaml index 95228da2c64578ea987b5169476a01cdc16f8547..e1983cc24205975b1e85cfb389518189d248d5b4 100644 --- a/config/packages/doctrine.yaml +++ b/config/packages/doctrine.yaml @@ -1,5 +1,7 @@ doctrine: dbal: + types: + datetimemicroseconds: App\Doctrine\Types\DateTimeMicrosecondsType url: '%env(resolve:DATABASE_URL)%' # IMPORTANT: You MUST configure your server version, diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 0538c9484891aa6afeb62d52335ebb87f5496657..c1989d4214f1d33db8e7d8b7129176ea18cbef33 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -18,12 +18,12 @@ security: api_token: pattern: ^/api/token$ security: false - api: - pattern: ^/api(?!/doc$) # Accepts routes under /api except /api/doc (pour api/doc, on utilisera donc le firewall "main" ce qui permettra d'accéder au swagger quand on est authentifié via Session PHP avec le role Admin - security: true - stateless: true # Pas d'authentification, pas de session utilisateur (mais le compte user est vérifié via le token) - oauth2: true - user_checker: App\Security\EasyUserChecker +# api: +# pattern: ^/api(?!/doc$) # Accepts routes under /api except /api/doc (pour api/doc, on utilisera donc le firewall "main" ce qui permettra d'accéder au swagger quand on est authentifié via Session PHP avec le role Admin +# security: true +# stateless: true # Pas d'authentification, pas de session utilisateur (mais le compte user est vérifié via le token) +# oauth2: true +# user_checker: App\Security\EasyUserChecker dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ @@ -62,7 +62,7 @@ security: - { path: ^/token, role: PUBLIC_ACCESS } - { path: ^/.well-known, roles: PUBLIC_ACCESS } - { path: ^/api/doc, role: ROLE_ADMIN } # swagger Firewall: main - - { path: ^/api, roles: [ROLE_OAUTH2_EMAIL] } # Firewall: Api + - { path: ^/api, roles: [ROLE_OAUTH2_EMAIL, ROLE_ADMIN] } # Firewall: Api - { path: ^/, role: ROLE_USER } when@test: diff --git a/src/Doctrine/Types/DateTimeMicrosecondsType.php b/src/Doctrine/Types/DateTimeMicrosecondsType.php new file mode 100644 index 0000000000000000000000000000000000000000..7b35737c1f708edb0ccf069dad1419ecef3ecda2 --- /dev/null +++ b/src/Doctrine/Types/DateTimeMicrosecondsType.php @@ -0,0 +1,71 @@ +<?php + +namespace App\Doctrine\Types; + +use DateTime; +use DateTimeInterface; +use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\ConversionException; + +/** + * Override datetime datatype to support microseconds + */ +class DateTimeMicrosecondsType extends Type +{ + const TYPENAME = 'datetimemicroseconds'; // modify to match your type name + + public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) + { + if (isset($fieldDeclaration['version']) && $fieldDeclaration['version'] == true) { + return 'TIMESTAMP'; + } + + return 'DATETIME(6)'; + } + + public function convertToPHPValue($value, AbstractPlatform $platform) + { + if ($value === null || $value instanceof DateTimeInterface) { + return $value; + } + + $val = DateTime::createFromFormat('Y-m-d H:i:s.u', $value); + + if ( ! $val) { + $val = date_create($value); + } + + if ( ! $val) { + throw ConversionException::conversionFailedFormat( + $value, + $this->getName(), + 'Y-m-d H:i:s.u' + ); + } + + return $val; + } + + public function convertToDatabaseValue($value, AbstractPlatform $platform) + { + if (null === $value) { + return $value; + } + + if ($value instanceof DateTimeInterface) { + return $value->format('Y-m-d H:i:s.u'); + } + + throw ConversionException::conversionFailedInvalidType( + $value, + $this->getName(), + ['null', 'DateTime'] + ); + } + + public function getName() + { + return self::TYPENAME; + } +} \ No newline at end of file diff --git a/src/Entity/MetaInfo.php b/src/Entity/MetaInfo.php index beea0badaf0dece7d951c8c55c1c528fb5351023..76fcb4712f4f539be53e63b19a26ba81f3d6aaa4 100644 --- a/src/Entity/MetaInfo.php +++ b/src/Entity/MetaInfo.php @@ -53,7 +53,7 @@ class MetaInfo * @ORM\ManyToOne(targetEntity=Graphy::class, inversedBy="metaInfos") * @Groups({"metaInfo:read"}) */ - private $createdBy; + private $graphies; public function __toString() { diff --git a/src/Entity/Trace.php b/src/Entity/Trace.php index 84829ffb4cf35927f5dd9da735a2efb4a93ac782..f813bd88f354bcd0b443f0c358a9193fcd00ea84 100644 --- a/src/Entity/Trace.php +++ b/src/Entity/Trace.php @@ -27,6 +27,12 @@ class Trace */ private $createdAt; + /** + * @Groups({"trace:read"}) + * @ORM\Column(type="datetimemicroseconds") + */ + private $timestamp; + /** * @ORM\ManyToOne(targetEntity=User::class, inversedBy="traces") * @Groups({"trace:read"}) @@ -126,4 +132,16 @@ class Trace return $this; } + + public function getTimestamp() + { + return $this->timestamp; + } + + public function setTimestamp($timestamp): self + { + $this->timestamp = $timestamp; + + return $this; + } }