2026-08-24 21:06:11 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Modules\Core\Privacy\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
|
|
|
use Lunar\Models\Customer;
|
2026-09-16 01:21:22 +03:00
|
|
|
use Modules\Core\Privacy\Enums\ExportRequestStatus;
|
2026-08-24 21:06:11 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A right-of-access export request. Created synchronously (fast — one insert), then
|
|
|
|
|
* ExportDataSubjectJob (queued) does the actual work of gathering every registered
|
|
|
|
|
* provider's data and, via Modules\Core\Privacy\Listeners\WriteExportToCsvListener,
|
|
|
|
|
* writing it to a file. file_path is null until that completes.
|
|
|
|
|
*
|
|
|
|
|
* `subject` is polymorphic — either a Lunar Customer (business account) or a User
|
|
|
|
|
* (individual), never both. See docs/privacy.md "User-scope vs Customer-scope".
|
|
|
|
|
*/
|
|
|
|
|
class DataExportRequest extends Model
|
|
|
|
|
{
|
|
|
|
|
protected $guarded = [];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'status' => ExportRequestStatus::class,
|
|
|
|
|
'completed_at' => 'datetime',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function subject(): MorphTo
|
|
|
|
|
{
|
|
|
|
|
return $this->morphTo(__FUNCTION__, 'subject_type', 'subject_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function isForCustomer(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->subject_type === (new Customer)->getMorphClass();
|
|
|
|
|
}
|
|
|
|
|
}
|