Feat: Updating the Privacy Providers, moving them into the appropriate Modules, Updating Privacy views
This commit is contained in:
@@ -9,9 +9,12 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Modules\Core\Privacy\Contracts\PersonalDataProvider;
|
||||
use Modules\Core\Privacy\DTOs\CustomerSubject;
|
||||
use Modules\Core\Privacy\Events\PersonalDataGathered;
|
||||
use Modules\Core\Privacy\DTOs\ExportReport;
|
||||
use Modules\Core\Privacy\DTOs\ProviderExportResult;
|
||||
use Modules\Core\Privacy\Enums\ExportRequestStatus;
|
||||
use Modules\Core\Privacy\Models\DataExportRequest;
|
||||
use Modules\Core\Privacy\Services\PrivacyManager;
|
||||
@@ -49,10 +52,16 @@ class ExportDataSubjectJob implements ShouldQueue
|
||||
{
|
||||
if ($this->request->isForCustomer()) {
|
||||
$subject = new CustomerSubject(customerId: $this->request->subject_id);
|
||||
$results = array_map(fn ($provider) => $provider->exportForCustomer($subject), $manager->providers());
|
||||
$results = array_map(
|
||||
fn (PersonalDataProvider $provider) => $this->safeExport($provider, 'exportForCustomer', $subject),
|
||||
$manager->providers()
|
||||
);
|
||||
} else {
|
||||
$subject = new UserSubject(userId: $this->request->subject_id, email: $this->request->email);
|
||||
$results = array_map(fn ($provider) => $provider->exportForUser($subject), $manager->providers());
|
||||
$results = array_map(
|
||||
fn (PersonalDataProvider $provider) => $this->safeExport($provider, 'exportForUser', $subject),
|
||||
$manager->providers()
|
||||
);
|
||||
}
|
||||
|
||||
Event::dispatch(new PersonalDataGathered(
|
||||
@@ -65,4 +74,29 @@ class ExportDataSubjectJob implements ShouldQueue
|
||||
{
|
||||
$this->request->update(['status' => ExportRequestStatus::Failed]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Catches per-provider so one provider throwing doesn't discard every
|
||||
* other provider's already-gathered export data for this same request —
|
||||
* without this, the whole array_map aborts, handle() never reaches
|
||||
* Event::dispatch(), and failed() marks the ENTIRE request Failed even
|
||||
* though most providers may have already gathered their data
|
||||
* successfully. Logged via Log::error() so a thrown provider is still
|
||||
* visible to staff, not just an empty/missing section in the export.
|
||||
*
|
||||
* @param 'exportForCustomer'|'exportForUser' $method
|
||||
*/
|
||||
private function safeExport(PersonalDataProvider $provider, string $method, CustomerSubject|UserSubject $subject): ProviderExportResult
|
||||
{
|
||||
try {
|
||||
return $provider->{$method}($subject);
|
||||
} catch (Throwable $e) {
|
||||
Log::error("Privacy provider {$provider->name()}::{$method}() threw during export", [
|
||||
'provider' => $provider->name(),
|
||||
'exception' => $e,
|
||||
]);
|
||||
|
||||
return new ProviderExportResult($provider->name(), [], $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user