src/Entity/Log.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTimeInterface;
  4. use Doctrine\DBAL\Types\Types;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. /**
  8.  * @ORM\Entity(repositoryClass="App\Repository\LogRepository")
  9.  * @ORM\Table(
  10.  *     name="log",
  11.  *     schema="perseo",
  12.  *     indexes={
  13.  *         @ORM\Index(name="idx_log_user", columns={"user"}),
  14.  *         @ORM\Index(name="idx_log_created_at", columns={"created_at"}),
  15.  *         @ORM\Index(name="idx_log_method", columns={"method"}),
  16.  *         @ORM\Index(name="idx_log_remote_addr", columns={"remote_addr"}),
  17.  *         @ORM\Index(name="idx_log_uri", columns={"uri"}, options={"lengths": {255}}),
  18.  *         @ORM\Index(name="idx_log_user_created", columns={"user", "created_at"})
  19.  *     }
  20.  * )
  21.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
  22.  *
  23.  * Performance notes:
  24.  * - No N+1 queries: This entity has no relationships, all data is denormalized
  25.  * - Indexes added for common filters: user, created_at, method, remote_addr, uri
  26.  * - Composite index (user, created_at) optimizes user activity reports
  27.  * - URI index limited to 255 chars to avoid key length issues
  28.  * - JSON fields (roles, headers, request, query) are not indexed (not searchable)
  29.  */
  30. class Log
  31. {
  32.     /**
  33.      * @ORM\Id
  34.      * @ORM\Column(type="bigint", options={"unsigned":true})
  35.      * @ORM\GeneratedValue(strategy="AUTO")
  36.      */
  37.     private $id;
  38.     /**
  39.      * @ORM\Column(type="string", nullable=true)
  40.      */
  41.     private $user;
  42.     /**
  43.      * @ORM\Column(type="json", nullable=true)
  44.      */
  45.     private $roles;
  46.     /**
  47.      * @ORM\Column(type="string", nullable=true)
  48.      */
  49.     private $webservice;
  50.     /**
  51.      * @ORM\Column(type="string", nullable=true)
  52.      */
  53.     private $uri;
  54.     /**
  55.      * @ORM\Column(type="string", nullable=true)
  56.      */
  57.     private $method;
  58.     /**
  59.      * @ORM\Column(type="json", nullable=true)
  60.      */
  61.     private $headers;
  62.     /**
  63.      * @ORM\Column(type="json", nullable=true)
  64.      */
  65.     private $request;
  66.     /**
  67.      * @ORM\Column(type="json", nullable=true)
  68.      */
  69.     private $query;
  70.     /**
  71.      * @ORM\Column(type="string", length=2000, nullable=true)
  72.      */
  73.     private $referer;
  74.     /**
  75.      * @ORM\Column(type="string", nullable=true, name="user_agent")
  76.      */
  77.     private $userAgent;
  78.     /**
  79.      * @ORM\Column(type="string", nullable=true, name="server_name")
  80.      */
  81.     private $serverName;
  82.     /**
  83.      * @ORM\Column(type="string", nullable=true, name="server_addr")
  84.      */
  85.     private $serverAddr;
  86.     /**
  87.      * @ORM\Column(type="string", nullable=true, name="remote_addr")
  88.      */
  89.     private $remoteAddr;
  90.     /**
  91.      * @ORM\Column(type="datetime", nullable=true, name="deleted_at")
  92.      */
  93.     private $deletedAt;
  94.     /**
  95.      * @ORM\Column(type="datetime", nullable=false, name="updated_at", options={"default":"2022-01-01 00:00:00"})
  96.      * @Gedmo\Timestampable(on="update")
  97.      */
  98.     private $updatedAt;
  99.     /**
  100.      * @ORM\Column(type="datetime", nullable=false, name="created_at", options={"default":"2022-01-01 00:00:00"})
  101.      * @Gedmo\Timestampable(on="create")
  102.      */
  103.     private $createdAt;
  104.     public function getId(): ?string
  105.     {
  106.         return $this->id;
  107.     }
  108.     public function getUser(): ?string
  109.     {
  110.         return $this->user;
  111.     }
  112.     public function setUser(?string $user): static
  113.     {
  114.         $this->user $user;
  115.         return $this;
  116.     }
  117.     public function getRoles(): ?array
  118.     {
  119.         return $this->roles;
  120.     }
  121.     public function setRoles(?array $roles): static
  122.     {
  123.         $this->roles $roles;
  124.         return $this;
  125.     }
  126.     public function getWebservice(): ?string
  127.     {
  128.         return $this->webservice;
  129.     }
  130.     public function setWebservice(?string $webservice): static
  131.     {
  132.         $this->webservice $webservice;
  133.         return $this;
  134.     }
  135.     public function getUri(): ?string
  136.     {
  137.         return $this->uri;
  138.     }
  139.     public function setUri(?string $uri): static
  140.     {
  141.         $this->uri $uri;
  142.         return $this;
  143.     }
  144.     public function getMethod(): ?string
  145.     {
  146.         return $this->method;
  147.     }
  148.     public function setMethod(?string $method): static
  149.     {
  150.         $this->method $method;
  151.         return $this;
  152.     }
  153.     public function getHeaders(): ?array
  154.     {
  155.         return $this->headers;
  156.     }
  157.     public function setHeaders(?array $headers): static
  158.     {
  159.         $this->headers $headers;
  160.         return $this;
  161.     }
  162.     public function getRequest(): ?array
  163.     {
  164.         return $this->request;
  165.     }
  166.     public function setRequest(?array $request): static
  167.     {
  168.         $this->request $request;
  169.         return $this;
  170.     }
  171.     public function getQuery(): ?array
  172.     {
  173.         return $this->query;
  174.     }
  175.     public function setQuery(?array $query): static
  176.     {
  177.         $this->query $query;
  178.         return $this;
  179.     }
  180.     public function getReferer(): ?string
  181.     {
  182.         return $this->referer;
  183.     }
  184.     public function setReferer(?string $referer): static
  185.     {
  186.         $this->referer $referer;
  187.         return $this;
  188.     }
  189.     public function getUserAgent(): ?string
  190.     {
  191.         return $this->userAgent;
  192.     }
  193.     public function setUserAgent(?string $userAgent): static
  194.     {
  195.         $this->userAgent $userAgent;
  196.         return $this;
  197.     }
  198.     public function getServerName(): ?string
  199.     {
  200.         return $this->serverName;
  201.     }
  202.     public function setServerName(?string $serverName): static
  203.     {
  204.         $this->serverName $serverName;
  205.         return $this;
  206.     }
  207.     public function getServerAddr(): ?string
  208.     {
  209.         return $this->serverAddr;
  210.     }
  211.     public function setServerAddr(?string $serverAddr): static
  212.     {
  213.         $this->serverAddr $serverAddr;
  214.         return $this;
  215.     }
  216.     public function getRemoteAddr(): ?string
  217.     {
  218.         return $this->remoteAddr;
  219.     }
  220.     public function setRemoteAddr(?string $remoteAddr): static
  221.     {
  222.         $this->remoteAddr $remoteAddr;
  223.         return $this;
  224.     }
  225.     public function getDeletedAt(): ?DateTimeInterface
  226.     {
  227.         return $this->deletedAt;
  228.     }
  229.     public function setDeletedAt(?DateTimeInterface $deletedAt): static
  230.     {
  231.         $this->deletedAt $deletedAt;
  232.         return $this;
  233.     }
  234.     public function getUpdatedAt(): ?DateTimeInterface
  235.     {
  236.         return $this->updatedAt;
  237.     }
  238.     public function setUpdatedAt(DateTimeInterface $updatedAt): static
  239.     {
  240.         $this->updatedAt $updatedAt;
  241.         return $this;
  242.     }
  243.     public function getCreatedAt(): ?DateTimeInterface
  244.     {
  245.         return $this->createdAt;
  246.     }
  247.     public function setCreatedAt(DateTimeInterface $createdAt): static
  248.     {
  249.         $this->createdAt $createdAt;
  250.         return $this;
  251.     }
  252.     public function getCreatedAtStringFecha(): ?string
  253.     {
  254.         return $this->getCreatedAt()?->format('d/m/Y');
  255.     }
  256.     public function getCreatedAtStringHora(): ?string
  257.     {
  258.         return $this->getCreatedAt()?->format('H:i:s');
  259.     }
  260. }