error('environment is product'); return 1; } $this->info('environment is ' . App::environment()); if ($this->option('test')) { $this->info('test mode'); } else { $this->error('this is not test mode'); } if (!$this->confirm("desensitize all users information?")) { return 0; } $users = UserInfo::cursor(); $total = UserInfo::count(); $desensitized = 0; $jumped = 0; foreach ($users as $key => $user) { if ( mb_substr($user->username, 0, 4) === 'test' || $user->username === 'admin' ) { $this->info('test user jump' . $user->username); $jumped++; continue; } $desensitized++; if (!$this->option('test')) { $curr = UserInfo::find($user->id); $curr->password = Str::uuid() . '*'; $curr->email = Str::uuid() . '@email.com'; $curr->username = mb_substr($curr->username, 0, 2) . mt_rand(1000, 9999) . '****'; $curr->nickname = mb_substr($curr->nickname, 0, 1) . '**'; $curr->save(); } $this->info('desensitized ' . $user->username); } $this->info("all done total={$total} desensitized={$desensitized} jumped={$jumped}"); return 0; } }