first commit

This commit is contained in:
team 1
2026-04-20 16:36:28 +02:00
parent a0ec07a99c
commit 2587ac8b4b
41 changed files with 5126 additions and 2280 deletions

View File

@@ -8,6 +8,7 @@ use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ORM\Table(name: 'document_tag')]
#[ORM\Index(name: 'idx_document_tag_tag_id', columns: ['tag_id'])]
class DocumentTag
{
#[ORM\Id]
@@ -22,8 +23,8 @@ class DocumentTag
public function __construct(Document $document, Tag $tag)
{
$this->document = $document;
$this->tag = $tag;
$this->setDocument($document);
$this->setTag($tag);
}
public function getDocument(): Document
@@ -35,4 +36,20 @@ class DocumentTag
{
return $this->tag;
}
public function isSameRelation(Document $document, Tag $tag): bool
{
return $this->document->getId()->equals($document->getId())
&& $this->tag->getId()->equals($tag->getId());
}
private function setDocument(Document $document): void
{
$this->document = $document;
}
private function setTag(Tag $tag): void
{
$this->tag = $tag;
}
}

View File

@@ -1,8 +1,12 @@
<?php
declare(strict_types=1);
namespace App\Entity;
use App\Tag\TagTypes;
use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity]
@@ -24,25 +28,25 @@ class Tag
#[ORM\Column(type: 'text', nullable: true)]
private ?string $description = null;
/**
* NEU: Governance-Typ des Tags
* - generic
* - catalog_entity
*/
#[ORM\Column(length: 50)]
private string $type = 'generic';
private string $type = TagTypes::GENERIC;
#[ORM\Column]
private \DateTimeImmutable $createdAt;
public function __construct(string $slug, string $label, ?string $description = null)
{
public function __construct(
string $slug,
string $label,
?string $description = null,
string $type = TagTypes::GENERIC,
) {
$this->id = Uuid::v4();
$this->createdAt = new \DateTimeImmutable();
$this->slug = $slug;
$this->label = $label;
$this->description = $description;
$this->setSlug($slug);
$this->setLabel($label);
$this->setDescription($description);
$this->setType($type);
}
public function getId(): Uuid
@@ -57,7 +61,14 @@ class Tag
public function setSlug(string $slug): static
{
$slug = $this->normalizeSlug($slug);
if ($slug === '') {
throw new InvalidArgumentException('Tag slug must not be empty.');
}
$this->slug = $slug;
return $this;
}
@@ -68,7 +79,14 @@ class Tag
public function setLabel(string $label): static
{
$label = trim($label);
if ($label === '') {
throw new InvalidArgumentException('Tag label must not be empty.');
}
$this->label = $label;
return $this;
}
@@ -79,7 +97,9 @@ class Tag
public function setDescription(?string $description): static
{
$this->description = $description;
$description = trim((string) $description);
$this->description = $description !== '' ? $description : null;
return $this;
}
@@ -90,13 +110,43 @@ class Tag
public function setType(string $type): static
{
$type = trim($type);
$this->type = $type !== '' ? $type : 'generic';
$normalizedType = TagTypes::normalize($type);
if (!TagTypes::isValid($normalizedType)) {
throw new InvalidArgumentException(sprintf('Unsupported tag type "%s".', $type));
}
$this->type = $normalizedType;
return $this;
}
public function isGeneric(): bool
{
return $this->type === TagTypes::GENERIC;
}
public function isCatalogEntity(): bool
{
return $this->type === TagTypes::CATALOG_ENTITY;
}
public function isSalesSignal(): bool
{
return $this->type === TagTypes::SALES_SIGNAL;
}
public function getCreatedAt(): \DateTimeImmutable
{
return $this->createdAt;
}
private function normalizeSlug(string $slug): string
{
$slug = mb_strtolower(trim($slug));
$slug = preg_replace('/\s+/u', '-', $slug) ?? $slug;
$slug = preg_replace('/-+/u', '-', $slug) ?? $slug;
return trim($slug, '-');
}
}

View File

@@ -9,14 +9,16 @@ use Symfony\Component\Uid\Uuid;
#[ORM\Entity]
#[ORM\Table(name: 'tag_rebuild_job')]
#[ORM\Index(columns: ['status'], name: 'idx_tag_rebuild_job_status')]
#[ORM\Index(columns: ['created_at'], name: 'idx_tag_rebuild_job_created_at')]
#[ORM\Index(name: 'idx_tag_rebuild_job_status', columns: ['status'])]
#[ORM\Index(name: 'idx_tag_rebuild_job_created_at', columns: ['created_at'])]
class TagRebuildJob
{
public const STATUS_QUEUED = 'QUEUED';
public const STATUS_RUNNING = 'RUNNING';
public const STATUS_QUEUED = 'QUEUED';
public const STATUS_RUNNING = 'RUNNING';
public const STATUS_COMPLETED = 'COMPLETED';
public const STATUS_FAILED = 'FAILED';
public const STATUS_FAILED = 'FAILED';
private const ERROR_MESSAGE_MAX_LENGTH = 4000;
#[ORM\Id]
#[ORM\Column(type: 'uuid', unique: true)]
@@ -44,6 +46,19 @@ class TagRebuildJob
$this->status = self::STATUS_QUEUED;
}
/**
* @return list<string>
*/
public static function statuses(): array
{
return [
self::STATUS_QUEUED,
self::STATUS_RUNNING,
self::STATUS_COMPLETED,
self::STATUS_FAILED,
];
}
public function getId(): Uuid
{
return $this->id;
@@ -54,24 +69,59 @@ class TagRebuildJob
return $this->status;
}
public function isQueued(): bool
{
return $this->status === self::STATUS_QUEUED;
}
public function isRunning(): bool
{
return $this->status === self::STATUS_RUNNING;
}
public function isCompleted(): bool
{
return $this->status === self::STATUS_COMPLETED;
}
public function isFailed(): bool
{
return $this->status === self::STATUS_FAILED;
}
public function isActive(): bool
{
return $this->isQueued() || $this->isRunning();
}
public function markRunning(): void
{
$this->status = self::STATUS_RUNNING;
$this->startedAt = new \DateTimeImmutable();
$this->finishedAt = null;
$this->errorMessage = null;
}
public function markCompleted(): void
{
if ($this->startedAt === null) {
$this->startedAt = new \DateTimeImmutable();
}
$this->status = self::STATUS_COMPLETED;
$this->finishedAt = new \DateTimeImmutable();
$this->errorMessage = null;
}
public function markFailed(string $message): void
{
if ($this->startedAt === null) {
$this->startedAt = new \DateTimeImmutable();
}
$this->status = self::STATUS_FAILED;
$this->finishedAt = new \DateTimeImmutable();
$this->errorMessage = $message;
$this->errorMessage = $this->normalizeErrorMessage($message);
}
public function getCreatedAt(): \DateTimeImmutable
@@ -93,4 +143,19 @@ class TagRebuildJob
{
return $this->errorMessage;
}
private function normalizeErrorMessage(string $message): ?string
{
$message = trim($message);
if ($message === '') {
return 'Unknown tag rebuild failure.';
}
if (mb_strlen($message) > self::ERROR_MESSAGE_MAX_LENGTH) {
$message = mb_substr($message, 0, self::ERROR_MESSAGE_MAX_LENGTH);
}
return $message;
}
}