Files
laraundfelix/app/Domain/Catalog/ContentElementVersion.php
LarsandCursor c73207f2c3
Deploy Test / test (push) Successful in 26s
Deploy Test / deploy (push) Successful in 30s
Halte ungenutzte Medien bearbeitbar und lege Dateien direkt im Modul an.
Eine Fassung wird erst unveränderlich, wenn sie freigegeben und verwendet wird. Das Auge am Listeneintrag öffnet die Vorschau.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-17 10:34:42 +01:00

79 lines
2.4 KiB
PHP

<?php
namespace App\Domain\Catalog;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ContentElementVersion extends Model
{
protected $fillable = [
'content_element_id',
'number',
'status',
'content_hash',
'body',
'metadata',
'change_note',
'block_reason',
];
protected function casts(): array
{
return [
'status' => ContentVersionStatus::class,
'metadata' => 'array',
];
}
protected static function booted(): void
{
static::updating(function (ContentElementVersion $version): void {
$original = StatusValue::of($version->getOriginal('status'));
if (! in_array($original, [
ContentVersionStatus::Bereit->value,
ContentVersionStatus::Gesperrt->value,
], true)) {
return;
}
if (
$original === ContentVersionStatus::Bereit->value
&& StatusValue::of($version->status) === ContentVersionStatus::Bereit->value
&& ! app(ContentService::class)->isCommitted($version)
) {
$contentFields = ['body', 'metadata', 'content_hash', 'change_note', 'updated_at'];
if (array_diff(array_keys($version->getDirty()), $contentFields) === []) {
return;
}
}
$allowed = ['status', 'updated_at'];
if (
$original === ContentVersionStatus::Bereit->value
&& StatusValue::of($version->status) === ContentVersionStatus::Gesperrt->value
) {
$allowed[] = 'block_reason';
}
$dirty = array_diff(array_keys($version->getDirty()), $allowed);
if ($dirty !== [] || $original === ContentVersionStatus::Gesperrt->value) {
throw new DomainRuleException('Eine bereitgestellte Inhaltsfassung ist unveränderlich.');
}
if (StatusValue::of($version->status) !== ContentVersionStatus::Gesperrt->value) {
throw new DomainRuleException('Eine bereitgestellte Inhaltsfassung kann nur gesperrt werden.');
}
});
}
public function element(): BelongsTo
{
return $this->belongsTo(ContentElement::class, 'content_element_id');
}
}