File tree Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change 16
16
*/
17
17
'blocked_env ' => ['production ' ],
18
18
'force_blocked_env ' => true ,
19
+
20
+ /*
21
+ | Model Ordering
22
+ |--------------------------------------------------------------------------
23
+ |
24
+ | Optionally specify the order of anonymization, these Models will be anonymized first.
25
+ |
26
+ */
27
+ 'ordered_models ' => []
19
28
];
Original file line number Diff line number Diff line change @@ -10,8 +10,9 @@ trait Anonymizable
10
10
{
11
11
public function anonymizableCondition (): Builder
12
12
{
13
- return static ::withTrashed ();
13
+ return static ::hasMacro ( ' withTrashed ' ) ? static :: withTrashed () : static :: query ();
14
14
}
15
+
15
16
public function anonymizableAttributes (Generator $ faker ): array
16
17
{
17
18
throw new LogicException ('Please implement the anonymizable method on your model. ' );
Original file line number Diff line number Diff line change @@ -56,6 +56,26 @@ public function handle(): int
56
56
57
57
$ this ->warn ('Anonymization started ' );
58
58
59
+ $ anonymizableClassesOrdered = collect (config ('anonymizer.ordered_models ' ) ?? [])
60
+ ->map (fn ($ ac ) => '\\' .$ ac );
61
+
62
+ $ anonymizableClasses = collect ($ anonymizableClasses )
63
+ ->diff ($ anonymizableClassesOrdered )
64
+ ->toArray ();
65
+
66
+ if (!empty ($ anonymizableClassesOrdered )) {
67
+ $ this ->warn ('Order dependent models anonymizing. ' );
68
+ }
69
+ foreach ($ anonymizableClassesOrdered as $ anonymizableClass ) {
70
+ $ this ->anonymizeTable (
71
+ new $ anonymizableClass ()
72
+ );
73
+ }
74
+
75
+ if (!empty ($ anonymizableClassesOrdered )) {
76
+ $ this ->warn ('Remaining models anonymizing. ' );
77
+ }
78
+ $ anonymizableClasses = collect ($ anonymizableClasses )->diff ($ anonymizableClassesOrdered )->all ();
59
79
foreach ($ anonymizableClasses as $ anonymizableClass ) {
60
80
$ this ->anonymizeTable (
61
81
new $ anonymizableClass ()
@@ -75,7 +95,10 @@ private function anonymizeTable(Model $model): void
75
95
76
96
$ progressBar = $ this ->output ->createProgressBar ($ this ->service ->getCount ($ model ));
77
97
78
- $ progressBar ->setFormat ('%current%/%max% [%bar%] %percent:3s%% | Remaining: %remaining:6s% ' );
98
+ $ progressBar ->setFormat ('%current%/%max% [%bar%] %percent:3s% ' );
99
+ if ($ this ->service ->getCount ($ model )>0 ) {
100
+ $ progressBar ->setFormat ('%current%/%max% [%bar%] %percent:3s%% | Remaining: %remaining:6s% ' );
101
+ }
79
102
80
103
$ this ->service ->getChunk ($ model , function (Collection $ chunkItems ) use ($ progressBar ) {
81
104
DB ::beginTransaction ();
You can’t perform that action at this time.
0 commit comments