„Dokumente“ heißt jetzt „Downloads“
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m38s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m31s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m39s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m54s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 3m50s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 3m55s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 3m18s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 3m19s
CI / Build-Artefakte aktuell (pull_request) Successful in 55s

Der Name „Dokumente“ bleibt dem kommenden QM-Modul (QM-Dokumente und
-Formulare) vorbehalten.

- Plugin plugins-core/downloads (Inhaus\Plugins\Downloads), Adresse
  /downloads, Rechte downloads.*, Objekttyp download_folder,
  Block downloads.folder, Kachel downloads.favorites
- Migration für bestehende Installationen: Tabellen und Spalten,
  Rechte, Sichtbarkeiten, Menü, Startseiten-Anordnung, Blöcke in
  Seiten und Fassungen, Plugin-Zustand; mit Test
- Alte Links unter /dokumente leiten dauerhaft weiter

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-26 15:03:32 +00:00
parent c71131d054
commit f78cc96be7
120 changed files with 1091 additions and 866 deletions

View file

@ -0,0 +1,67 @@
<?php
namespace Inhaus\Plugins\Downloads\Models;
use App\Models\User;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
#[Fillable(['folder_id', 'title', 'description', 'created_by', 'updated_by'])]
class Download extends Model
{
protected static function booted(): void
{
// Dateien aller Fassungen mit entfernen.
static::deleting(fn (Download $download) => $download->versions()->get()->each->delete());
}
/**
* @return BelongsTo<DownloadFolder, $this>
*/
public function folder(): BelongsTo
{
return $this->belongsTo(DownloadFolder::class, 'folder_id');
}
/**
* @return BelongsTo<DownloadVersion, $this>
*/
/**
* @return BelongsToMany<User, $this>
*/
public function favoritedBy(): BelongsToMany
{
return $this->belongsToMany(User::class, 'download_favorites')->withPivot('created_at');
}
public function currentVersion(): BelongsTo
{
return $this->belongsTo(DownloadVersion::class, 'current_version_id');
}
/**
* @return HasMany<DownloadVersion, $this>
*/
public function versions(): HasMany
{
return $this->hasMany(DownloadVersion::class)->orderByDesc('version');
}
/**
* @return BelongsTo<User, $this>
*/
public function updater(): BelongsTo
{
return $this->belongsTo(User::class, 'updated_by');
}
public function downloadUrl(?DownloadVersion $version = null): string
{
$version ??= $this->currentVersion;
return route('downloads.download', ['download' => $this->id, 'version' => $version?->version, 'name' => $version?->name ?? 'datei']);
}
}

View file

@ -0,0 +1,51 @@
<?php
namespace Inhaus\Plugins\Downloads\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Inhaus\Plugins\Downloads\FolderTree;
#[Fillable(['parent_id', 'name', 'description', 'sort', 'created_by'])]
class DownloadFolder extends Model
{
protected static function booted(): void
{
static::saved(fn (DownloadFolder $folder) => FolderTree::flush($folder->wasRecentlyCreated || $folder->wasChanged('parent_id')));
static::deleted(fn () => FolderTree::flush(true));
}
/**
* @return array{0: string, 1: int}
*/
public function permissionResource(): array
{
return ['download_folder', $this->id];
}
/**
* @return BelongsTo<DownloadFolder, $this>
*/
public function parent(): BelongsTo
{
return $this->belongsTo(DownloadFolder::class, 'parent_id');
}
/**
* @return HasMany<DownloadFolder, $this>
*/
public function children(): HasMany
{
return $this->hasMany(DownloadFolder::class, 'parent_id')->orderBy('sort')->orderBy('name');
}
/**
* @return HasMany<Download, $this>
*/
public function downloads(): HasMany
{
return $this->hasMany(Download::class, 'folder_id');
}
}

View file

@ -0,0 +1,47 @@
<?php
namespace Inhaus\Plugins\Downloads\Models;
use App\Models\User;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\Storage;
/**
* Eine Fassung einer Datei. Die Datei liegt außerhalb von public/ und
* wird nur an Personen ausgeliefert, die den Ordner sehen dürfen.
*/
#[Fillable(['download_id', 'version', 'name', 'path', 'mime', 'size', 'note', 'uploaded_by', 'created_at'])]
class DownloadVersion extends Model
{
public const DISK = 'local';
public const UPDATED_AT = null;
protected static function booted(): void
{
static::deleted(fn (DownloadVersion $version) => Storage::disk(self::DISK)->delete($version->path));
}
/**
* @return BelongsTo<Download, $this>
*/
public function download(): BelongsTo
{
return $this->belongsTo(Download::class);
}
/**
* @return BelongsTo<User, $this>
*/
public function uploader(): BelongsTo
{
return $this->belongsTo(User::class, 'uploaded_by');
}
public function extension(): string
{
return strtoupper(pathinfo($this->name, PATHINFO_EXTENSION));
}
}