stash light

This commit is contained in:
team 1
2026-02-12 10:03:52 +01:00
parent 5b650a8f28
commit 0bb0c0b42f
51 changed files with 6864 additions and 72 deletions

110
src/Entity/Document.php Normal file
View File

@@ -0,0 +1,110 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
#[ORM\Entity]
class Document
{
public const STATUS_ACTIVE = 'ACTIVE';
public const STATUS_ARCHIVED = 'ARCHIVED';
#[ORM\Id]
#[ORM\Column(type: 'uuid', unique: true)]
private Uuid $id;
#[ORM\Column(length: 255)]
private string $title;
#[ORM\Column(length: 20)]
private string $status = self::STATUS_ACTIVE;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
private User $createdBy;
#[ORM\Column]
private \DateTimeImmutable $createdAt;
#[ORM\OneToMany(mappedBy: 'document', targetEntity: DocumentVersion::class, cascade: ['persist'], orphanRemoval: true)]
private Collection $versions;
#[ORM\ManyToOne]
private ?DocumentVersion $currentVersion = null;
public function __construct()
{
$this->id = Uuid::v4();
$this->createdAt = new \DateTimeImmutable();
$this->versions = new ArrayCollection();
}
public function getId(): Uuid
{
return $this->id;
}
public function getCreatedAt(): \DateTimeImmutable
{
return $this->createdAt;
}
public function getTitle(): string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
public function getStatus(): string
{
return $this->status;
}
public function archive(): void
{
$this->status = self::STATUS_ARCHIVED;
}
public function getCreatedBy(): User
{
return $this->createdBy;
}
public function setCreatedBy(User $user): static
{
$this->createdBy = $user;
return $this;
}
public function getVersions(): Collection
{
return $this->versions;
}
public function addVersion(DocumentVersion $version): void
{
$this->versions->add($version);
$version->setDocument($this);
}
public function setCurrentVersion(?DocumentVersion $version): void
{
$this->currentVersion = $version;
}
public function getCurrentVersion(): ?DocumentVersion
{
return $this->currentVersion;
}
}

View File

@@ -0,0 +1,184 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;
use App\Repository\DocumentVersionRepository;
#[ORM\Entity(repositoryClass: DocumentVersionRepository::class)]
class DocumentVersion
{
public const INGEST_PENDING = 'PENDING';
public const INGEST_RUNNING = 'RUNNING';
public const INGEST_INDEXED = 'INDEXED';
public const INGEST_FAILED = 'FAILED';
public const INGEST_STATUSES = [
self::INGEST_PENDING,
self::INGEST_RUNNING,
self::INGEST_INDEXED,
self::INGEST_FAILED,
];
#[ORM\Id]
#[ORM\Column(type: 'uuid', unique: true)]
private Uuid $id;
#[ORM\ManyToOne(inversedBy: 'versions')]
#[ORM\JoinColumn(nullable: false)]
private Document $document;
#[ORM\Column]
private int $versionNumber;
#[ORM\Column(length: 255)]
private string $filePath;
#[ORM\Column(length: 64)]
private string $checksum;
#[ORM\Column(length: 20)]
private string $ingestStatus = self::INGEST_PENDING;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
private User $createdBy;
#[ORM\Column]
private \DateTimeImmutable $createdAt;
#[ORM\Column]
private bool $isActive = false;
public function __construct()
{
$this->id = Uuid::v4();
$this->createdAt = new \DateTimeImmutable();
}
// =========================
// ID
// =========================
public function getId(): Uuid
{
return $this->id;
}
// =========================
// Document Relation
// =========================
public function setDocument(Document $document): void
{
$this->document = $document;
}
public function getDocument(): Document
{
return $this->document;
}
// =========================
// Version Number
// =========================
public function getVersionNumber(): int
{
return $this->versionNumber;
}
public function setVersionNumber(int $number): void
{
$this->versionNumber = $number;
}
// =========================
// File Path
// =========================
public function setFilePath(string $path): void
{
$this->filePath = $path;
}
public function getFilePath(): string
{
return $this->filePath;
}
// =========================
// Checksum
// =========================
public function setChecksum(string $checksum): void
{
$this->checksum = $checksum;
}
public function getChecksum(): string
{
return $this->checksum;
}
// =========================
// Ingest Status
// =========================
public function setIngestStatus(string $status): void
{
if (!in_array($status, self::INGEST_STATUSES, true)) {
throw new \InvalidArgumentException('Invalid ingest status.');
}
$this->ingestStatus = $status;
}
public function getIngestStatus(): string
{
return $this->ingestStatus;
}
public function isIndexed(): bool
{
return $this->ingestStatus === self::INGEST_INDEXED;
}
// =========================
// Created By
// =========================
public function setCreatedBy(User $user): void
{
$this->createdBy = $user;
}
public function getCreatedBy(): User
{
return $this->createdBy;
}
// =========================
// Created At
// =========================
public function getCreatedAt(): \DateTimeImmutable
{
return $this->createdAt;
}
// =========================
// Active Flag
// =========================
public function setActive(bool $active): void
{
$this->isActive = $active;
}
public function isActive(): bool
{
return $this->isActive;
}
}

101
src/Entity/IngestJob.php Normal file
View File

@@ -0,0 +1,101 @@
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity]
class IngestJob
{
public const TYPE_DOCUMENT = 'DOCUMENT';
public const TYPE_GLOBAL_REINDEX = 'GLOBAL_REINDEX';
public const STATUS_RUNNING = 'RUNNING';
public const STATUS_COMPLETED = 'COMPLETED';
public const STATUS_FAILED = 'FAILED';
public const STATUS_ABORTED = 'ABORTED';
#[ORM\Id]
#[ORM\Column(type: 'uuid', unique: true)]
private Uuid $id;
#[ORM\Column(length: 30)]
private string $type;
#[ORM\Column(length: 20)]
private string $status = self::STATUS_RUNNING;
#[ORM\Column(type: 'uuid', nullable: true)]
private ?Uuid $documentId = null;
#[ORM\Column(type: 'uuid', nullable: true)]
private ?Uuid $documentVersionId = null;
#[ORM\Column]
private \DateTimeImmutable $startedAt;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $finishedAt = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: true)]
private ?User $startedBy = null;
#[ORM\Column(nullable: true)]
private ?string $logPath = null;
#[ORM\Column(type: 'text', nullable: true)]
private ?string $errorMessage = null;
public function __construct(string $type)
{
$this->id = Uuid::v4();
$this->type = $type;
$this->startedAt = new \DateTimeImmutable();
$this->status = self::STATUS_RUNNING;
}
public function getId(): Uuid { return $this->id; }
public function getType(): string { return $this->type; }
public function getStatus(): string { return $this->status; }
public function setDocumentId(?Uuid $id): void { $this->documentId = $id; }
public function getDocumentId(): ?Uuid { return $this->documentId; }
public function setDocumentVersionId(?Uuid $id): void { $this->documentVersionId = $id; }
public function getDocumentVersionId(): ?Uuid { return $this->documentVersionId; }
public function setStartedBy(?User $user): void { $this->startedBy = $user; }
public function getStartedBy(): ?User { return $this->startedBy; }
public function setLogPath(?string $path): void { $this->logPath = $path; }
public function getLogPath(): ?string { return $this->logPath; }
public function getStartedAt(): \DateTimeImmutable { return $this->startedAt; }
public function getFinishedAt(): ?\DateTimeImmutable { return $this->finishedAt; }
public function markCompleted(): void
{
$this->status = self::STATUS_COMPLETED;
$this->finishedAt = new \DateTimeImmutable();
}
public function markFailed(string $message): void
{
$this->status = self::STATUS_FAILED;
$this->errorMessage = $message;
$this->finishedAt = new \DateTimeImmutable();
}
public function markAborted(): void
{
$this->status = self::STATUS_ABORTED;
$this->finishedAt = new \DateTimeImmutable();
}
public function getErrorMessage(): ?string
{
return $this->errorMessage;
}
}

161
src/Entity/User.php Normal file
View File

@@ -0,0 +1,161 @@
<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\HasLifecycleCallbacks]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\Column(type: 'uuid', unique: true)]
private Uuid $id;
#[ORM\Column(length: 180, unique: true)]
private string $email;
#[ORM\Column]
private string $password;
#[ORM\Column(type: 'json')]
private array $roles = [];
#[ORM\Column]
private bool $isActive = true;
#[ORM\Column]
private \DateTimeImmutable $createdAt;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $updatedAt = null;
public function __construct()
{
$this->id = Uuid::v4();
$this->createdAt = new \DateTimeImmutable();
$this->roles = ['ROLE_USER'];
}
// =========================
// Security Identifier
// =========================
public function getUserIdentifier(): string
{
return $this->email;
}
// Symfony < 6 compatibility (optional)
public function getUsername(): string
{
return $this->email;
}
// =========================
// ID
// =========================
public function getId(): Uuid
{
return $this->id;
}
// =========================
// Email
// =========================
public function getEmail(): string
{
return $this->email;
}
public function setEmail(string $email): static
{
$this->email = strtolower($email);
return $this;
}
// =========================
// Password
// =========================
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): static
{
$this->password = $password;
return $this;
}
// =========================
// Roles
// =========================
public function getRoles(): array
{
$roles = $this->roles;
// Jeder User hat mindestens ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): static
{
$this->roles = $roles;
return $this;
}
// =========================
// Active Status
// =========================
public function isActive(): bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): static
{
$this->isActive = $isActive;
return $this;
}
// =========================
// Timestamps
// =========================
public function getCreatedAt(): \DateTimeImmutable
{
return $this->createdAt;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
#[ORM\PreUpdate]
public function updateTimestamp(): void
{
$this->updatedAt = new \DateTimeImmutable();
}
// =========================
// Erase Credentials (Pflicht)
// =========================
public function eraseCredentials(): void
{
// Falls später sensible Daten gespeichert werden
}
}