Nenhuma descrição

UserTableSSNDecrypter.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. class UserTableSSNDecrypter extends Seeder {
  3. public function run()
  4. {
  5. // True to show messages
  6. $debug = false;
  7. // Disable query logging to avoid memory exhaustion
  8. DB::disableQueryLog();
  9. $this->command->info('Users SSN Decryption started');
  10. // Initiates time
  11. $time_start = microtime(true);
  12. try
  13. {
  14. // Get all users in the database
  15. $users = User::all();
  16. // Iterate over all users
  17. foreach ($users as $user)
  18. {
  19. // Skip update if too short in length
  20. if(strlen($user->ssn)<10)
  21. continue;
  22. // Update table
  23. DB::table('users')
  24. ->where('id', $user->id)
  25. ->update(array(
  26. 'ssn' => Crypt::decrypt($user->ssn),
  27. // 'program_id' => $program_id, //should change when I know how this info will be given
  28. // 'updated_at' => date("Y-m-d H:i:s", time()),
  29. )
  30. );
  31. if($debug){
  32. $this->command->info('Decrypted ssn for '.$user->email.': '.$user->surnames.', '.$user->first_name);
  33. }
  34. }
  35. }
  36. // If an exception is raised, show the message and add to error
  37. catch(Exception $e)
  38. {
  39. $this->command->info($e->getMessage());
  40. };
  41. // Stop time
  42. $time_end = microtime(true);
  43. // Display separator
  44. $this->command->info('------------------------------------------------------------');
  45. }
  46. }