Ei kuvausta

UserTableSSNDecrypter.php 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. class UserTableSSNDecrypter extends Seeder
  3. {
  4. public function run()
  5. {
  6. // True to show messages
  7. $debug = false;
  8. // Disable query logging to avoid memory exhaustion
  9. DB::disableQueryLog();
  10. $this->command->info('Users SSN Decryption started');
  11. // Initiates time
  12. $time_start = microtime(true);
  13. try {
  14. // Get all users in the database
  15. $users = User::all();
  16. // Iterate over all users
  17. foreach ($users as $user) {
  18. // Skip update if too short in length
  19. if (strlen($user->ssn) < 10)
  20. continue;
  21. // Update table
  22. DB::table('users')
  23. ->where('id', $user->id)
  24. ->update(
  25. 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. $this->command->info($e->getMessage());
  39. };
  40. // Stop time
  41. $time_end = microtime(true);
  42. // Display separator
  43. $this->command->info('------------------------------------------------------------');
  44. }
  45. }