PageRenderTime 21ms CodeModel.GetById 18ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/upload/includes/cron/jobs/prune_inactive_users.php

http://torrentpier2.googlecode.com/
PHP | 66 lines | 55 code | 11 blank | 0 comment | 6 complexity | 149363f76cb6349011804dc0e80c804c MD5 | raw file
 1<?php
 2
 3if (!defined('BB_ROOT')) die(basename(__FILE__));
 4
 5$users_per_cycle = 1000;
 6
 7require_once(INC_DIR .'functions_admin.php');
 8
 9$excluded_users = join(',', array(
10	GUEST_UID,
11	BOT_UID,
12));
13
14while (true)
15{
16	@set_time_limit(600);
17
18	$prune_users = $not_activated_users = $not_active_users = array();
19
20	if ($not_activated_days = intval($bb_cfg['user_not_activated_days_keep']))
21	{
22		$sql = "
23			SELECT user_id
24			FROM ". BB_USERS ."
25			WHERE user_active    = 0
26			  AND user_lastvisit = 0
27			  AND user_regdate   < ". (TIMENOW - 86400*$not_activated_days) ."
28			  AND user_id        NOT IN($excluded_users)
29			LIMIT $users_per_cycle
30		";
31		foreach (DB()->fetch_rowset($sql) as $row)
32		{
33			$not_activated_users[] = $row['user_id'];
34		}
35	}
36	if ($not_active_days = intval($bb_cfg['user_not_active_days_keep']))
37	{
38		$sql = "
39			SELECT user_id
40			FROM ". BB_USERS ."
41			WHERE user_active    = 1
42			  AND user_posts     = 0
43			  AND user_lastvisit < ". (TIMENOW - 86400*$not_active_days) ."
44			  AND user_id        NOT IN($excluded_users)
45			LIMIT $users_per_cycle
46		";
47		foreach (DB()->fetch_rowset($sql) as $row)
48		{
49			$not_active_users[] = $row['user_id'];
50		}
51	}
52
53	if ($prune_users = $not_activated_users + $not_active_users)
54	{
55		user_delete($prune_users);
56	}
57
58	if (count($prune_users) < $users_per_cycle)
59	{
60		break;
61	}
62
63	sleep(3);
64}
65
66unset($prune_users, $not_activated_users, $not_active_users);