optimize code and ingest docs
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
@@ -25,11 +27,11 @@ class DocumentVersion
|
||||
#[ORM\Column(type: 'uuid', unique: true)]
|
||||
private Uuid $id;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'versions')]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
#[ORM\ManyToOne(targetEntity: Document::class, inversedBy: 'versions')]
|
||||
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
|
||||
private Document $document;
|
||||
|
||||
#[ORM\Column]
|
||||
#[ORM\Column(type: 'integer')]
|
||||
private int $versionNumber;
|
||||
|
||||
#[ORM\Column(length: 255)]
|
||||
@@ -41,14 +43,14 @@ class DocumentVersion
|
||||
#[ORM\Column(length: 20)]
|
||||
private string $ingestStatus = self::INGEST_PENDING;
|
||||
|
||||
#[ORM\ManyToOne]
|
||||
#[ORM\ManyToOne(targetEntity: User::class)]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private User $createdBy;
|
||||
|
||||
#[ORM\Column]
|
||||
#[ORM\Column(type: 'datetime_immutable')]
|
||||
private \DateTimeImmutable $createdAt;
|
||||
|
||||
#[ORM\Column]
|
||||
#[ORM\Column(type: 'boolean')]
|
||||
private bool $isActive = false;
|
||||
|
||||
public function __construct()
|
||||
@@ -57,22 +59,18 @@ class DocumentVersion
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
// =========================
|
||||
// ID
|
||||
// =========================
|
||||
|
||||
public function getId(): Uuid
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Document Relation
|
||||
// =========================
|
||||
|
||||
public function setDocument(Document $document): void
|
||||
{
|
||||
$this->document = $document;
|
||||
|
||||
if (!$document->getVersions()->contains($this)) {
|
||||
$document->addVersion($this);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDocument(): Document
|
||||
@@ -80,10 +78,6 @@ class DocumentVersion
|
||||
return $this->document;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Version Number
|
||||
// =========================
|
||||
|
||||
public function getVersionNumber(): int
|
||||
{
|
||||
return $this->versionNumber;
|
||||
@@ -94,10 +88,6 @@ class DocumentVersion
|
||||
$this->versionNumber = $number;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// File Path
|
||||
// =========================
|
||||
|
||||
public function setFilePath(string $path): void
|
||||
{
|
||||
$this->filePath = $path;
|
||||
@@ -108,10 +98,6 @@ class DocumentVersion
|
||||
return $this->filePath;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Checksum
|
||||
// =========================
|
||||
|
||||
public function setChecksum(string $checksum): void
|
||||
{
|
||||
$this->checksum = $checksum;
|
||||
@@ -122,10 +108,6 @@ class DocumentVersion
|
||||
return $this->checksum;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Ingest Status
|
||||
// =========================
|
||||
|
||||
public function setIngestStatus(string $status): void
|
||||
{
|
||||
if (!in_array($status, self::INGEST_STATUSES, true)) {
|
||||
@@ -145,10 +127,6 @@ class DocumentVersion
|
||||
return $this->ingestStatus === self::INGEST_INDEXED;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Created By
|
||||
// =========================
|
||||
|
||||
public function setCreatedBy(User $user): void
|
||||
{
|
||||
$this->createdBy = $user;
|
||||
@@ -159,19 +137,11 @@ class DocumentVersion
|
||||
return $this->createdBy;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Created At
|
||||
// =========================
|
||||
|
||||
public function getCreatedAt(): \DateTimeImmutable
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Active Flag
|
||||
// =========================
|
||||
|
||||
public function setActive(bool $active): void
|
||||
{
|
||||
$this->isActive = $active;
|
||||
@@ -182,15 +152,8 @@ class DocumentVersion
|
||||
return $this->isActive;
|
||||
}
|
||||
|
||||
//#########################################################
|
||||
// Helper
|
||||
//#########################################################
|
||||
public function getFileExtension(): string
|
||||
{
|
||||
if (!$this->filePath) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return mb_strtolower(pathinfo($this->filePath, PATHINFO_EXTENSION));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user