Advertisement

How to auto delete the non-activated users.

General questions relating to Joomla! 4.x.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10
Locked
Outbreaker
Joomla! Intern
Joomla! Intern
Posts: 79
Joined: Fri Jun 19, 2009 7:00 pm

How to auto delete the non-activated users.

Post by Outbreaker » Mon Feb 20, 2023 1:48 am

Hi,
Is there a way to delete the non-activated users from Joomla after X days. 🤔

Advertisement
User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 18137
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: How to auto delete the non-activated users.

Post by toivo » Mon Feb 20, 2023 7:16 am

The simplest way is to use SQL queries, like the attached examples, assuming that you know your way around phpMyAdmin, MySQL Workbench or a similar MySQL client.

The first example lists the users who have not been activated within the set number of days. The second script creates first a temporary table of the users to be deleted, then removes the entries of those users from the table _user_usergroup_map and deletes them from the _users table.

This example could run without the temporary table, but it simplifies the queries when associated tables created by third party components during the registration need to be cleaned up, too.

Remember to back up the database first, just in case! Replace 'puhj1' with your own table prefix and set the variable @days to the number of days required.

List the candidates, showing the activation hash as verification:

Code: Select all

SET @days = 10;
SELECT id, username, DATE_FORMAT(registerDate, '%Y-%m-%d') AS registered, activation FROM puhj1_users
WHERE ((registerDate < DATE_SUB(CURRENT_DATE, INTERVAL @days DAY)) AND (activation NOT IN (' ', '0')));
Delete the users who have not been activated within the specified number of days:

Code: Select all

SET @days = 10;
DROP TEMPORARY TABLE IF EXISTS delete_users;
CREATE TEMPORARY TABLE delete_users
SELECT id FROM puhj1_users
WHERE ((registerDate < DATE_SUB(CURRENT_DATE, INTERVAL @days DAY)) AND (activation NOT IN (' ', '0')));
DELETE m FROM puhj1_user_usergroup_map m INNER JOIN delete_users ON id = user_id;
DELETE u FROM puhj1_users u INNER JOIN delete_users d ON d.id = u.id;
Toivo Talikka, Global Moderator

Outbreaker
Joomla! Intern
Joomla! Intern
Posts: 79
Joined: Fri Jun 19, 2009 7:00 pm

Re: How to auto delete the non-activated users.

Post by Outbreaker » Mon Feb 20, 2023 8:01 am

Is there a way to run this automatically even Hour or every Day?
I'm just done updating to Joomla 4, would be the new "Scheduled Tasks" a solution for doing this?

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 18137
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: How to auto delete the non-activated users.

Post by toivo » Mon Feb 20, 2023 9:12 am

It would be possible with cron or Scheduled Tasks but a PHP CLI script is needed.

Alternatively, the sequence of SQL commands could be fired from a task plugin, described in this article in the Joomla! Community Magazine: Get to know the new Joomla! Task Scheduler.
Toivo Talikka, Global Moderator

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 45086
Joined: Sat Apr 05, 2008 9:58 pm

Re: How to auto delete the non-activated users.

Post by Webdongle » Mon Feb 20, 2023 9:34 am

http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".

Outbreaker
Joomla! Intern
Joomla! Intern
Posts: 79
Joined: Fri Jun 19, 2009 7:00 pm

Re: How to auto delete the non-activated users.

Post by Outbreaker » Mon Feb 20, 2023 2:41 pm

I also stubble across those paying plugins. But no one works with the Joomla 4 "Scheduled Tasks" and i would be really nice to have an open-source plugin for this, it should even be included by default in Joomla to remove the spam accounts or user typo errors in emails.

I put a $20 bounty on such a open-source "Scheduled Tasks" plugin, because my coding sucks and want to make Joomla better. ;)

User avatar
AMurray
Joomla! Master
Joomla! Master
Posts: 10611
Joined: Sat Feb 13, 2010 7:35 am
Location: Australia

Re: How to auto delete the non-activated users.

Post by AMurray » Mon Feb 20, 2023 9:39 pm

The second one listed above I assume it has an internal mechanism that checks for users not logged in (since registration) for X days.

The first one is for J3 only and not updated in the last 14 months.
Regards - A Murray
Global Support Moderator

User avatar
Webdongle
Joomla! Master
Joomla! Master
Posts: 45086
Joined: Sat Apr 05, 2008 9:58 pm

Re: How to auto delete the non-activated users.

Post by Webdongle » Mon Feb 20, 2023 10:00 pm

AMurray wrote: Mon Feb 20, 2023 9:39 pm...
The first one is for J3 only and not updated in the last 14 months.
Oh yes. my bad I copy/pasted the wrong url
http://www.weblinksonline.co.uk/
https://www.weblinksonline.co.uk/updating-joomla.html
"When I'm right no one remembers but when I'm wrong no one forgets".

User avatar
mandville
Joomla! Master
Joomla! Master
Posts: 15162
Joined: Mon Mar 20, 2006 1:56 am
Location: The Girly Side of Joomla in Sussex

Re: How to auto delete the non-activated users.

Post by mandville » Mon Feb 20, 2023 10:11 pm

toivo wrote: Mon Feb 20, 2023 7:16 am The simplest way is to use SQL queries, like the attached examples, assuming that you know your way around phpMyAdmin, MySQL Workbench or a similar MySQL client.
could someone be so bold as do a free plugin for this?
HU2HY- Poor questions = Poor answer
Un requested Help PM's will be reported, added to the foe list and possibly just deleted
portable mini golf https://www.puttersminigolf.co.uk/

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 18137
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: How to auto delete the non-activated users.

Post by toivo » Mon Feb 20, 2023 10:15 pm

I'll give it a go :D
Toivo Talikka, Global Moderator

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 18137
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: How to auto delete the non-activated users.

Post by toivo » Fri Feb 24, 2023 8:44 am

One has to learn to walk before running... Instead of a task plugin, here is a Joomla 4 back end module called NonActivated for starters. The module lists and deletes user accounts that remain nonactivated after a set number of days. It is a rough product but at least it gives me inspiration to tackle the task plugin.

The module is safe to use because it relies on the User::delete() function to delete users and clean the #_user_usergroup_map. The User::delete() function triggers also the onUserBeforeDelete and onUserAfterDelete plugin events.

Feedback and suggestions are welcome! If this module is found useful, it will be submitted to JED.

NonActivated-Module-Parameters.png
NonActivated-Module-Example.png
You do not have the required permissions to view the files attached to this post.
Toivo Talikka, Global Moderator

Outbreaker
Joomla! Intern
Joomla! Intern
Posts: 79
Joined: Fri Jun 19, 2009 7:00 pm

Re: How to auto delete the non-activated users.

Post by Outbreaker » Fri Feb 24, 2023 9:55 am

Nice, After a quick test run i couldn't find any errors. :D
It's astonishing how many user type their emails wrong. I surprised that some big Joomla sites have still user ID's left. 😅

Outbreaker
Joomla! Intern
Joomla! Intern
Posts: 79
Joined: Fri Jun 19, 2009 7:00 pm

Re: How to auto delete the non-activated users.

Post by Outbreaker » Fri Feb 24, 2023 5:11 pm

A scheduled task would be excellent to fully atomize it. Because the back-end module is only triggered when someone logs into the back-end. ;)
I'm also don't get it way Joomla has after so long not added something like this by default, including a Clear Caches Scheduled Task. :(

Advertisement

Locked

Return to “General Questions/New to Joomla! 4.x”