Wunderbyte-GmbH / moodle-mod_newsletter

Native Moodle newsletter module
6 stars 6 forks source link

Deleting records from the user table #47

Open haunted2 opened 3 years ago

haunted2 commented 3 years ago

Hello, This plugin deletes records from the user tables if the user if it has not been confirmed for more than a certain time and is subscribed to a newsletter. https://github.com/Wunderbyte-GmbH/moodle-mod_newsletter/blob/ed9cdee3297af9d747a3590acdc5812d23e420ec/classes/task/send_newsletter.php#L69

$query = "SELECT u.id FROM {user} u INNER JOIN {newsletter_subscriptions} ns ON u.id = ns.userid WHERE u.confirmed = 0 AND :now - u.timecreated > :limit"; $ids = $DB->get_fieldset_sql($query, array('now' => time(), 'limit' => $config->activation_timeout)); if (!empty($ids)) { list($insql, $params) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED); $DB->delete_records_select('user', "id " . $insql, $params);

I believe this should be pointed out. Not everyone might want this to happen, plus the database might get dirty because an unconfirmed user may have custom fields in the user_info_data table, populated during account creation

dasistwas commented 3 years ago

Thank you for pointing that out. I do think, that only users are deleted who registered via the newsletter subscription for guest users. But if there are default values for custom user profile fields that might be written to that table. Moodle deletes unconfirmed users anyway so maybe that could just be removed from the code. What do you think @haunted2 ?

haunted2 commented 3 years ago

Moodle deletes unconfirmed users (only if the scheduled task \core\task\delete_unconfirmed_users_task is active and the cron.php is running), but it uses the global function delete_user() (lib/moodlelib.php) which deletes a lot of user related stuff but not the record in the user table.

As far as I know, Moodle never physically deletes that record, but does a logical deletion, changing username, email and password, just like when an administrator deletes a user using the "trash" icon from the users list.