Skip to content

Commit 70c5132

Browse files
authored
Merge pull request #4 from theodson/feature/optional_model_ordering
Feature/optional model ordering
2 parents 66c479c + 03cec4c commit 70c5132

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

config/anonymizer.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,16 @@
33
return [
44
'locale' => 'en_US',
55
'chunk_size' => 1000,
6-
'models_path' => app_path('Models')
6+
'models_path' => app_path('Models'),
7+
8+
/*
9+
|--------------------------------------------------------------------------
10+
| Model Ordering
11+
|--------------------------------------------------------------------------
12+
|
13+
| Optionally specify the order of anonymization, these Models will be anonymized first.
14+
|
15+
*/
16+
'ordered_models' => []
17+
718
];

src/Commands/AnonymizerCommand.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,26 @@ public function handle(): int
5454

5555
$this->warn('Anonymization started');
5656

57+
$anonymizableClassesOrdered = collect(config('anonymizer.ordered_models') ?? [])
58+
->map(fn($ac) => '\\'.$ac);
59+
60+
$anonymizableClasses = collect($anonymizableClasses)
61+
->diff($anonymizableClassesOrdered)
62+
->toArray();
63+
64+
if (!empty($anonymizableClassesOrdered)) {
65+
$this->warn('Order dependent models anonymizing.');
66+
}
67+
foreach ($anonymizableClassesOrdered as $anonymizableClass) {
68+
$this->anonymizeTable(
69+
new $anonymizableClass()
70+
);
71+
}
72+
73+
if (!empty($anonymizableClassesOrdered)) {
74+
$this->warn('Remaining models anonymizing.');
75+
}
76+
$anonymizableClasses = collect($anonymizableClasses)->diff($anonymizableClassesOrdered)->all();
5777
foreach ($anonymizableClasses as $anonymizableClass) {
5878
$this->anonymizeTable(
5979
new $anonymizableClass()

0 commit comments

Comments
 (0)