-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for blomstra/gdpr (#88)
* feat: add support for blomstra/gdpr * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot <[email protected]>
- Loading branch information
1 parent
75c7cf2
commit 847fac2
Showing
3 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of fof/drafts. | ||
* | ||
* Copyright (c) FriendsOfFlarum. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FoF\Drafts\Data; | ||
|
||
use Blomstra\Gdpr\Data\Type; | ||
use FoF\Drafts\Draft; | ||
use Illuminate\Support\Arr; | ||
use PhpZip\ZipFile; | ||
|
||
class Drafts extends Type | ||
{ | ||
public function export(ZipFile $zip): void | ||
{ | ||
Draft::query() | ||
->where('user_id', $this->user->id) | ||
->each(function (Draft $draft) use ($zip) { | ||
$zip->addFromString( | ||
"draft-{$draft->id}.json", | ||
json_encode( | ||
$this->sanitize($draft), | ||
JSON_PRETTY_PRINT | ||
) | ||
); | ||
}); | ||
} | ||
|
||
protected function sanitize(Draft $draft): array | ||
{ | ||
return Arr::except($draft->toArray(), [ | ||
'user_id', 'relationships', 'scheduled_validation_error', 'extra', | ||
]); | ||
} | ||
|
||
public function anonymize(): void | ||
{ | ||
// In the case of drafts, it makes no sense to keep them after a user is anonymized. | ||
$this->delete(); | ||
} | ||
|
||
public function delete(): void | ||
{ | ||
Draft::query() | ||
->where('user_id', $this->user->id) | ||
->delete(); | ||
} | ||
} |