src/Entity/CRM/DataSource.php line 14

  1. <?php
  2. namespace App\Entity\CRM;
  3. use App\Enum\DataSourceSyncStatus;
  4. use App\Enum\DataSourceType;
  5. use App\Repository\DataSourceRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\DBAL\Types\Types;
  9. use Doctrine\ORM\Mapping as ORM;
  10. #[ORM\Entity(repositoryClassDataSourceRepository::class)]
  11. class DataSource
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id null;
  17.     #[ORM\ManyToOne(inversedBy'dataSources')]
  18.     #[ORM\JoinColumn(nullabletrue)]
  19.     private ?Branch $tenant null;
  20.     #[ORM\Column(length255)]
  21.     private ?string $name null;
  22.     #[ORM\Column(length16enumTypeDataSourceType::class)]
  23.     private DataSourceType $type DataSourceType::FTP;
  24.     #[ORM\Column]
  25.     private bool $enabled true;
  26.     #[ORM\Column(length255nullabletrue)]
  27.     private ?string $host null;
  28.     #[ORM\Column(nullabletrue)]
  29.     private ?int $port 21;
  30.     #[ORM\Column(length255nullabletrue)]
  31.     private ?string $username null;
  32.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  33.     private ?string $passwordEncrypted null;
  34.     #[ORM\Column(length255nullabletrue)]
  35.     private ?string $path null;
  36.     #[ORM\Column]
  37.     private bool $passive true;
  38.     #[ORM\Column(length255nullabletrue)]
  39.     private ?string $apiUrl null;
  40.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  41.     private ?string $apiKeyEncrypted null;
  42.     #[ORM\Column(length255nullabletrue)]
  43.     private ?string $localPath null;
  44.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  45.     private ?\DateTimeInterface $lastSyncAt null;
  46.     #[ORM\Column(length16enumTypeDataSourceSyncStatus::class, nullabletrue)]
  47.     private ?DataSourceSyncStatus $lastSyncStatus null;
  48.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  49.     private ?string $lastSyncError null;
  50.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  51.     private \DateTimeInterface $createdAt;
  52.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  53.     private \DateTimeInterface $updatedAt;
  54.     #[ORM\OneToMany(mappedBy'source'targetEntityTranscriptionJob::class)]
  55.     private Collection $transcriptionJobs;
  56.     private ?string $plainPassword null;
  57.     private ?string $plainApiKey null;
  58.     public function __construct()
  59.     {
  60.         $now = new \DateTimeImmutable();
  61.         $this->createdAt $now;
  62.         $this->updatedAt $now;
  63.         $this->transcriptionJobs = new ArrayCollection();
  64.     }
  65.     public function __toString(): string
  66.     {
  67.         return (string) ($this->name ?? ('ŹródÅ‚o #' $this->id));
  68.     }
  69.     public function getId(): ?int
  70.     {
  71.         return $this->id;
  72.     }
  73.     public function getTenant(): ?Branch
  74.     {
  75.         return $this->tenant;
  76.     }
  77.     public function setTenant(?Branch $tenant): static
  78.     {
  79.         $this->tenant $tenant;
  80.         return $this;
  81.     }
  82.     public function getName(): ?string
  83.     {
  84.         return $this->name;
  85.     }
  86.     public function setName(string $name): static
  87.     {
  88.         $this->name $name;
  89.         return $this;
  90.     }
  91.     public function getType(): DataSourceType
  92.     {
  93.         return $this->type;
  94.     }
  95.     public function setType(DataSourceType $type): static
  96.     {
  97.         $this->type $type;
  98.         return $this;
  99.     }
  100.     public function isEnabled(): bool
  101.     {
  102.         return $this->enabled;
  103.     }
  104.     public function setEnabled(bool $enabled): static
  105.     {
  106.         $this->enabled $enabled;
  107.         return $this;
  108.     }
  109.     public function getHost(): ?string
  110.     {
  111.         return $this->host;
  112.     }
  113.     public function setHost(?string $host): static
  114.     {
  115.         $this->host $host;
  116.         return $this;
  117.     }
  118.     public function getPort(): ?int
  119.     {
  120.         return $this->port;
  121.     }
  122.     public function setPort(?int $port): static
  123.     {
  124.         $this->port $port;
  125.         return $this;
  126.     }
  127.     public function getUsername(): ?string
  128.     {
  129.         return $this->username;
  130.     }
  131.     public function setUsername(?string $username): static
  132.     {
  133.         $this->username $username;
  134.         return $this;
  135.     }
  136.     public function getPasswordEncrypted(): ?string
  137.     {
  138.         return $this->passwordEncrypted;
  139.     }
  140.     public function setPasswordEncrypted(?string $passwordEncrypted): static
  141.     {
  142.         $this->passwordEncrypted $passwordEncrypted;
  143.         return $this;
  144.     }
  145.     public function getPath(): ?string
  146.     {
  147.         return $this->path;
  148.     }
  149.     public function setPath(?string $path): static
  150.     {
  151.         $this->path $path;
  152.         return $this;
  153.     }
  154.     public function isPassive(): bool
  155.     {
  156.         return $this->passive;
  157.     }
  158.     public function setPassive(bool $passive): static
  159.     {
  160.         $this->passive $passive;
  161.         return $this;
  162.     }
  163.     public function getApiUrl(): ?string
  164.     {
  165.         return $this->apiUrl;
  166.     }
  167.     public function setApiUrl(?string $apiUrl): static
  168.     {
  169.         $this->apiUrl $apiUrl;
  170.         return $this;
  171.     }
  172.     public function getApiKeyEncrypted(): ?string
  173.     {
  174.         return $this->apiKeyEncrypted;
  175.     }
  176.     public function setApiKeyEncrypted(?string $apiKeyEncrypted): static
  177.     {
  178.         $this->apiKeyEncrypted $apiKeyEncrypted;
  179.         return $this;
  180.     }
  181.     public function getLocalPath(): ?string
  182.     {
  183.         return $this->localPath;
  184.     }
  185.     public function setLocalPath(?string $localPath): static
  186.     {
  187.         $this->localPath $localPath;
  188.         return $this;
  189.     }
  190.     public function getLastSyncAt(): ?\DateTimeInterface
  191.     {
  192.         return $this->lastSyncAt;
  193.     }
  194.     public function setLastSyncAt(?\DateTimeInterface $lastSyncAt): static
  195.     {
  196.         $this->lastSyncAt $lastSyncAt;
  197.         return $this;
  198.     }
  199.     public function getLastSyncStatus(): ?DataSourceSyncStatus
  200.     {
  201.         return $this->lastSyncStatus;
  202.     }
  203.     public function setLastSyncStatus(?DataSourceSyncStatus $lastSyncStatus): static
  204.     {
  205.         $this->lastSyncStatus $lastSyncStatus;
  206.         return $this;
  207.     }
  208.     public function getLastSyncError(): ?string
  209.     {
  210.         return $this->lastSyncError;
  211.     }
  212.     public function setLastSyncError(?string $lastSyncError): static
  213.     {
  214.         $this->lastSyncError $lastSyncError;
  215.         return $this;
  216.     }
  217.     public function getCreatedAt(): \DateTimeInterface
  218.     {
  219.         return $this->createdAt;
  220.     }
  221.     public function getUpdatedAt(): \DateTimeInterface
  222.     {
  223.         return $this->updatedAt;
  224.     }
  225.     public function setUpdatedAt(\DateTimeInterface $updatedAt): static
  226.     {
  227.         $this->updatedAt $updatedAt;
  228.         return $this;
  229.     }
  230.     public function touch(): static
  231.     {
  232.         $this->updatedAt = new \DateTimeImmutable();
  233.         return $this;
  234.     }
  235.     public function getPlainPassword(): ?string
  236.     {
  237.         return $this->plainPassword;
  238.     }
  239.     public function setPlainPassword(?string $plainPassword): static
  240.     {
  241.         $this->plainPassword $plainPassword;
  242.         return $this;
  243.     }
  244.     public function getPlainApiKey(): ?string
  245.     {
  246.         return $this->plainApiKey;
  247.     }
  248.     public function setPlainApiKey(?string $plainApiKey): static
  249.     {
  250.         $this->plainApiKey $plainApiKey;
  251.         return $this;
  252.     }
  253.     public function getMaskedPassword(): ?string
  254.     {
  255.         if ($this->passwordEncrypted === null || $this->passwordEncrypted === '') {
  256.             return null;
  257.         }
  258.         return self::maskSecret($this->plainPassword);
  259.     }
  260.     public function getMaskedApiKey(): ?string
  261.     {
  262.         if ($this->apiKeyEncrypted === null || $this->apiKeyEncrypted === '') {
  263.             return null;
  264.         }
  265.         return self::maskSecret($this->plainApiKey);
  266.     }
  267.     public function hasPasswordConfigured(): bool
  268.     {
  269.         return $this->passwordEncrypted !== null && $this->passwordEncrypted !== '';
  270.     }
  271.     public function hasApiKeyConfigured(): bool
  272.     {
  273.         return $this->apiKeyEncrypted !== null && $this->apiKeyEncrypted !== '';
  274.     }
  275.     /**
  276.      * @return Collection<int, TranscriptionJob>
  277.      */
  278.     public function getTranscriptionJobs(): Collection
  279.     {
  280.         return $this->transcriptionJobs;
  281.     }
  282.     public function addTranscriptionJob(TranscriptionJob $transcriptionJob): static
  283.     {
  284.         if (!$this->transcriptionJobs->contains($transcriptionJob)) {
  285.             $this->transcriptionJobs->add($transcriptionJob);
  286.             $transcriptionJob->setSource($this);
  287.         }
  288.         return $this;
  289.     }
  290.     public function removeTranscriptionJob(TranscriptionJob $transcriptionJob): static
  291.     {
  292.         if ($this->transcriptionJobs->removeElement($transcriptionJob)) {
  293.             if ($transcriptionJob->getSource() === $this) {
  294.                 $transcriptionJob->setSource(null);
  295.             }
  296.         }
  297.         return $this;
  298.     }
  299.     private static function maskSecret(?string $plainText null): string
  300.     {
  301.         if ($plainText === null || $plainText === '') {
  302.             return '********';
  303.         }
  304.         $length strlen($plainText);
  305.         if ($length <= 4) {
  306.             return str_repeat('*'$length);
  307.         }
  308.         return substr($plainText02) . str_repeat('*'$length 4) . substr($plainText, -2);
  309.     }
  310. }