|
32 | 32 | * Manages the user notification and deletion workflow |
33 | 33 | */ |
34 | 34 | class manager { |
35 | | - |
36 | 35 | /** @var \stdClass Moodle config object for this plugin */ |
37 | 36 | protected \stdClass $config; |
38 | 37 |
|
@@ -370,13 +369,15 @@ protected function warn_inactive_users(): int { |
370 | 369 | // Notify users. |
371 | 370 | $numwarnedusers = 0; |
372 | 371 | foreach ($userstowarn as $user) { |
373 | | - if (!email_to_user( |
374 | | - $user, |
375 | | - get_admin(), |
376 | | - $this->config->warning_email_subject, |
377 | | - html_to_text(nl2br($this->config->warning_email_body)), |
378 | | - $this->config->warning_email_body |
379 | | - )) { |
| 372 | + if ( |
| 373 | + !email_to_user( |
| 374 | + $user, |
| 375 | + get_admin(), |
| 376 | + $this->config->warning_email_subject, |
| 377 | + html_to_text(nl2br($this->config->warning_email_body)), |
| 378 | + $this->config->warning_email_body |
| 379 | + ) |
| 380 | + ) { |
380 | 381 | logger::error(get_string('error_sending_warning_mail_to_user', 'tool_userautodelete', $user->id)); |
381 | 382 | continue; |
382 | 383 | } |
@@ -416,13 +417,15 @@ protected function delete_inactive_users(): int { |
416 | 417 | foreach ($userstodelete as $user) { |
417 | 418 | // Send deletion mail if enabled. |
418 | 419 | if ($this->config->delete_email_enable) { |
419 | | - if (!email_to_user( |
420 | | - $user, |
421 | | - get_admin(), |
422 | | - $this->config->delete_email_subject, |
423 | | - html_to_text(nl2br($this->config->delete_email_body)), |
424 | | - $this->config->delete_email_body |
425 | | - )) { |
| 420 | + if ( |
| 421 | + !email_to_user( |
| 422 | + $user, |
| 423 | + get_admin(), |
| 424 | + $this->config->delete_email_subject, |
| 425 | + html_to_text(nl2br($this->config->delete_email_body)), |
| 426 | + $this->config->delete_email_body |
| 427 | + ) |
| 428 | + ) { |
426 | 429 | logger::error(get_string('error_sending_delete_mail_to_user', 'tool_userautodelete', $user->id)); |
427 | 430 | } else { |
428 | 431 | logger::info(get_string('delete_email_sent_to_user', 'tool_userautodelete', $user->id)); |
@@ -458,32 +461,34 @@ protected function delete_inactive_users(): int { |
458 | 461 | protected function anonymize_user_record(int $userid): void { |
459 | 462 | global $DB; |
460 | 463 |
|
461 | | - if ($DB->update_record('user', [ |
462 | | - 'id' => $userid, |
463 | | - 'username' => "DELETED-USER-{$userid}", |
464 | | - 'password' => '', |
465 | | - 'idnumber' => '', |
466 | | - 'firstname' => 'DELETED', |
467 | | - 'lastname' => 'DELETED', |
468 | | - 'email' => "DELETED-USER-{$userid}@localhost", |
469 | | - 'phone1' => '', |
470 | | - 'phone2' => '', |
471 | | - 'institution' => '', |
472 | | - 'department' => '', |
473 | | - 'address' => '', |
474 | | - 'city' => '', |
475 | | - 'country' => '', |
476 | | - 'lastip' => '', |
477 | | - 'secret' => '', |
478 | | - 'picture' => 0, |
479 | | - 'description' => '', |
480 | | - 'imagealt' => '', |
481 | | - 'lastnamephonetic' => '', |
482 | | - 'firstnamephonetic' => '', |
483 | | - 'middlename' => '', |
484 | | - 'alternatename' => '', |
485 | | - 'moodlenetprofile' => '', |
486 | | - ])) { |
| 464 | + if ( |
| 465 | + $DB->update_record('user', [ |
| 466 | + 'id' => $userid, |
| 467 | + 'username' => "DELETED-USER-{$userid}", |
| 468 | + 'password' => '', |
| 469 | + 'idnumber' => '', |
| 470 | + 'firstname' => 'DELETED', |
| 471 | + 'lastname' => 'DELETED', |
| 472 | + 'email' => "DELETED-USER-{$userid}@localhost", |
| 473 | + 'phone1' => '', |
| 474 | + 'phone2' => '', |
| 475 | + 'institution' => '', |
| 476 | + 'department' => '', |
| 477 | + 'address' => '', |
| 478 | + 'city' => '', |
| 479 | + 'country' => '', |
| 480 | + 'lastip' => '', |
| 481 | + 'secret' => '', |
| 482 | + 'picture' => 0, |
| 483 | + 'description' => '', |
| 484 | + 'imagealt' => '', |
| 485 | + 'lastnamephonetic' => '', |
| 486 | + 'firstnamephonetic' => '', |
| 487 | + 'middlename' => '', |
| 488 | + 'alternatename' => '', |
| 489 | + 'moodlenetprofile' => '', |
| 490 | + ]) |
| 491 | + ) { |
487 | 492 | logger::info(get_string('user_anonymized', 'tool_userautodelete', $userid)); |
488 | 493 | } else { |
489 | 494 | logger::error(get_string('error_anonymizing_user', 'tool_userautodelete', $userid)); |
@@ -527,5 +532,4 @@ protected function cleanup(): int { |
527 | 532 |
|
528 | 533 | return $numrecoveredusers; |
529 | 534 | } |
530 | | - |
531 | 535 | } |
0 commit comments