Introduced a two-tier media pipeline with dynamic disks, asset tracking, admin controls, and alerting around
upload/archival workflows.
- Added storage metadata + asset tables and models so every photo/variant knows where it lives
(database/migrations/2025_10_20_090000_create_media_storage_targets_table.php, database/ migrations/2025_10_20_090200_create_event_media_assets_table.php, app/Models/MediaStorageTarget.php:1, app/
Models/EventMediaAsset.php:1, app/Models/EventStorageAssignment.php:1, app/Models/Event.php:27).
- Rewired guest and tenant uploads to pick the event’s hot disk, persist EventMediaAsset records, compute
checksums, and clean up on delete (app/Http/Controllers/Api/EventPublicController.php:243, app/Http/
Controllers/Api/Tenant/PhotoController.php:25, app/Models/Photo.php:25).
- Implemented storage services, archival job scaffolding, monitoring config, and queue-failure notifications for upload issues (app/Services/Storage/EventStorageManager.php:16, app/Services/Storage/
StorageHealthService.php:9, app/Jobs/ArchiveEventMediaAssets.php:16, app/Providers/AppServiceProvider.php:39, app/Notifications/UploadPipelineFailed.php:8, config/storage-monitor.php:1).
- Seeded default hot/cold targets and exposed super-admin tooling via a Filament resource and capacity widget (database/seeders/MediaStorageTargetSeeder.php:13, database/seeders/DatabaseSeeder.php:17, app/Filament/Resources/MediaStorageTargetResource.php:1, app/Filament/Widgets/StorageCapacityWidget.php:12, app/Providers/Filament/SuperAdminPanelProvider.php:47).
- Dropped cron skeletons and artisan placeholders to schedule storage monitoring, archival dispatch, and upload queue health checks (cron/storage_monitor.sh, cron/archive_dispatcher.sh, cron/upload_queue_health.sh, routes/console.php:9).
142 lines
3.3 KiB
PHP
142 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use App\Models\EventStorageAssignment;
|
|
use App\Models\EventMediaAsset;
|
|
use App\Models\MediaStorageTarget;
|
|
|
|
class Event extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'events';
|
|
protected $guarded = [];
|
|
protected $casts = [
|
|
'date' => 'datetime',
|
|
'is_active' => 'boolean',
|
|
'name' => 'array',
|
|
'description' => 'array',
|
|
];
|
|
|
|
public function storageAssignments(): HasMany
|
|
{
|
|
return $this->hasMany(EventStorageAssignment::class);
|
|
}
|
|
|
|
public function mediaAssets(): HasMany
|
|
{
|
|
return $this->hasMany(EventMediaAsset::class);
|
|
}
|
|
|
|
public function currentStorageTarget(?string $role = 'hot'): ?MediaStorageTarget
|
|
{
|
|
$assignment = $this->storageAssignments()
|
|
->where('role', $role)
|
|
->where('status', 'active')
|
|
->latest('assigned_at')
|
|
->first();
|
|
|
|
return $assignment?->storageTarget;
|
|
}
|
|
|
|
public function tenant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Tenant::class);
|
|
}
|
|
|
|
public function eventType(): BelongsTo
|
|
{
|
|
return $this->belongsTo(EventType::class);
|
|
}
|
|
|
|
public function photos(): HasMany
|
|
{
|
|
return $this->hasMany(Photo::class);
|
|
}
|
|
|
|
public function taskCollections(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(
|
|
TaskCollection::class,
|
|
'event_task_collection',
|
|
'event_id',
|
|
'task_collection_id'
|
|
);
|
|
}
|
|
|
|
public function tasks(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Task::class, 'event_task', 'event_id', 'task_id')
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function eventPackage(): BelongsTo
|
|
{
|
|
return $this->belongsTo(EventPackage::class);
|
|
}
|
|
|
|
public function eventPackages(): HasMany
|
|
{
|
|
return $this->hasMany(EventPackage::class);
|
|
}
|
|
|
|
public function joinTokens(): HasMany
|
|
{
|
|
return $this->hasMany(EventJoinToken::class);
|
|
}
|
|
|
|
public function hasActivePackage(): bool
|
|
{
|
|
return $this->eventPackage && $this->eventPackage->isActive();
|
|
}
|
|
|
|
public function getPackageLimits(): array
|
|
{
|
|
if (!$this->hasActivePackage()) {
|
|
return [];
|
|
}
|
|
|
|
return $this->eventPackage->package->limits;
|
|
}
|
|
|
|
public function canUploadPhoto(): bool
|
|
{
|
|
if (!$this->hasActivePackage()) {
|
|
return false;
|
|
}
|
|
|
|
return $this->eventPackage->canUploadPhoto();
|
|
}
|
|
|
|
public function getSettingsAttribute($value): array
|
|
{
|
|
if (is_array($value)) {
|
|
return $value;
|
|
}
|
|
|
|
if (is_string($value) && $value !== '') {
|
|
$decoded = json_decode($value, true);
|
|
|
|
return is_array($decoded) ? $decoded : [];
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
public function setSettingsAttribute($value): void
|
|
{
|
|
if (is_string($value)) {
|
|
$decoded = json_decode($value, true);
|
|
$value = is_array($decoded) ? $decoded : [];
|
|
}
|
|
|
|
$this->attributes['settings'] = json_encode($value ?? []);
|
|
}
|
|
}
|