Prune Users

Automatically delete user accounts based on their last activity
User avatar
kasimi
mChat developer
Posts: 1173
Joined: 06 Oct 2016, 09:56
Location: Germany

Re: Prune Users

Post by kasimi »

I see where your problem is. To only prune users who have been active at least once, try this:
  • Open ext/kasimi/pruneusers/cron/prune_users.php
  • Find, around line 124:

    Code: Select all

    AND u.user_lastvisit < ' . (int) $lifetime;
    
  • On a new line above, add:

    Code: Select all

    AND u.user_lastvisit > 0
    
User avatar
jan_2017
Distinguished Donor
Posts: 166
Joined: 13 May 2017, 18:07

Re: Prune Users

Post by jan_2017 »

Okay :D

I will test it , very thanks!

Bye Jan :wave:
User avatar
jan_2017
Distinguished Donor
Posts: 166
Joined: 13 May 2017, 18:07

Re: Prune Users

Post by jan_2017 »

I have found an error in acp error log:
Ein allgemeiner Fehler ist aufgetreten: General Error
» SQL ERROR [ mysqli ]

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND u.user_lastvisit < 1514029275' at line 6 [1064]

SQL

SELECT u.user_id, u.username
FROM phpbb_users u
WHERE u.user_type = 0
AND u.user_id <> 1
AND u.user_lastvisit > 0;
AND u.user_lastvisit < 1514029275

BACKTRACE

FILE: (not given by php)
LINE: (not given by php)
CALL: msg_handler()

FILE: [ROOT]/phpbb/db/driver/driver.php
LINE: 999
CALL: trigger_error()

FILE: [ROOT]/phpbb/db/driver/mysqli.php
LINE: 193
CALL: phpbb\db\driver\driver->sql_error()

FILE: [ROOT]/phpbb/db/driver/factory.php
LINE: 329
CALL: phpbb\db\driver\mysqli->sql_query()

FILE: [ROOT]/ext/kasimi/pruneusers/cron/prune_users.php
LINE: 126
CALL: phpbb\db\driver\factory->sql_query()

FILE: [ROOT]/ext/kasimi/pruneusers/cron/prune_users.php
LINE: 76
CALL: kasimi\pruneusers\cron\prune_users->get_expired_users()

FILE: (not given by php)
LINE: (not given by php)
CALL: kasimi\pruneusers\cron\prune_users->run()

FILE: [ROOT]/phpbb/cron/task/wrapper.php
LINE: 104
CALL: call_user_func_array()

FILE: [ROOT]/cron.php
LINE: 78
CALL: phpbb\cron\task\wrapper->__call()
User avatar
kasimi
mChat developer
Posts: 1173
Joined: 06 Oct 2016, 09:56
Location: Germany

Re: Prune Users

Post by kasimi »

You added a semicolon that doesn't belong there:

Code: Select all

AND u.user_lastvisit > 0;
Remove it and you should be good to go. :+1:
User avatar
jan_2017
Distinguished Donor
Posts: 166
Joined: 13 May 2017, 18:07

Re: Prune Users

Post by jan_2017 »

small mistake big effect

thanks , i have fixed it
Painkiller88
Distinguished Donor
Posts: 28
Joined: 01 Jan 2019, 12:41

Re: Prune Users

Post by Painkiller88 »

I'm not sure if u are still working on this ext, but it would be great, as we all love your mChat, to make it possible like for mchat rooms, to enter a user ID that posts into the chat that the user has to make at least 1 post or his account will be pruned after the set time.

Maybe let the admin set the exact text to be posted into the chat.

I saw this already at terry2's board, but as it is ur extension i better ask u if you can do this :)

thanks :)
User avatar
kasimi
mChat developer
Posts: 1173
Joined: 06 Oct 2016, 09:56
Location: Germany

Re: Prune Users

Post by kasimi »

I probably won't add that feature to this extension, but editing the code so that these users are deleted too should be easy:
  • Open ext/kasimi/pruneusers/cron/prune_users.php
  • Find the SQL query on lines 120-124:

    Code: Select all

    $sql = 'SELECT u.user_id, u.username
        FROM ' . USERS_TABLE . ' u
        WHERE u.user_type = ' . USER_NORMAL . '
            AND u.user_id <> ' . ANONYMOUS . '
            AND u.user_lastvisit < ' . (int) $lifetime;
    
  • Replace with:

    Code: Select all

    global $table_prefix;
    $sql = 'SELECT u.user_id, u.username
        FROM ' . USERS_TABLE . ' u
        LEFT JOIN (
                SELECT mt.user_id, MAX(mt.message_time) AS latest_message_time
                FROM ' . $table_prefix . 'mchat mt
                GROUP BY mt.user_id
            ) AS m
            ON u.user_id = m.user_id
        WHERE u.user_type = ' . USER_NORMAL . '
            AND u.user_id <> ' . ANONYMOUS . '
            AND (u.user_lastvisit < ' . (int) $lifetime . ' OR m.latest_message_time < ' . (int) $lifetime . ')';
    
clight77
Posts: 26
Joined: 01 May 2017, 01:06

Re: Prune Users

Post by clight77 »

Hi any chance members with 0 post count could be added for pruning also?

Thanks
User avatar
kasimi
mChat developer
Posts: 1173
Joined: 06 Oct 2016, 09:56
Location: Germany

Re: Prune Users

Post by kasimi »

Sure:
  • Open ext/kasimi/pruneusers/cron/prune_users.php
  • In the SQL query on lines 120-124, find:

    Code: Select all

    AND u.user_id <> ' . ANONYMOUS . '
  • On a new line below, add:

    Code: Select all

    AND user_posts = 0
clight77
Posts: 26
Joined: 01 May 2017, 01:06

Re: Prune Users

Post by clight77 »

Hey thanks for the response :)

Who is online

Users browsing this forum: CCBot [Bot] and 0 guests