4 * Copyright 1999-2001 (c) VA Linux Systems
5 * Copyright 2013, Franck Villaume - TrivialDev
7 * This file is part of FusionForge. FusionForge is free software;
8 * you can redistribute it and/or modify it under the terms of the
9 * GNU General Public License as published by the Free Software
10 * Foundation; either version 2 of the Licence, or (at your option)
13 * FusionForge is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 require dirname(__FILE__).'/../www/env.inc.php';
24 require_once $gfcommon.'include/pre.php';
25 require $gfcommon.'include/cron_utils.php';
31 // one hour ago for projects
33 db_query_params ('DELETE FROM groups WHERE status=$1 and register_time < $2',
38 // one week ago for users
39 $then=(time()-604800);
40 db_query_params ('DELETE FROM pfo_user_role WHERE EXISTS (SELECT user_id FROM users
41 WHERE status=$1 and add_date < $2 AND users.user_id=pfo_user_role.user_id)',
45 $result = db_query_params ('SELECT user_id, email FROM users WHERE status=$1 and add_date < $2',
48 if (db_numrows($result)) {
51 require_once 'common/include/Plugin.class.php';
52 require_once 'common/include/PluginManager.class.php';
54 // SCM-specific plugins subsystem
55 require_once 'common/include/SCMPlugin.class.php';
57 setup_plugin_manager () ;
59 while ($row = db_fetch_array($result)) {
60 $hook_params = array();
61 $hook_params['user'] = &user_get_object($row['user_id']);
62 $hook_params['user_id'] = $row['user_id'];
63 plugin_hook ("user_delete", $hook_params);
67 db_query_params ('DELETE FROM users WHERE status=$1 and add_date < $2',
72 #30 days ago for sessions
73 $then=(time()-(30*60*60*24));
74 db_query_params ('DELETE FROM user_session WHERE time < $1',
78 #one month ago for preferences
79 $then=(time()-604800*4);
80 db_query_params ('DELETE FROM user_preferences WHERE set_date < $1',
85 $then=(time()-604800*3);
86 db_query_params ('UPDATE people_job SET status_id = 3 where post_date < $1',
90 #1 day ago for form keys
91 $then=(time()-(60*60*24));
92 db_query_params ('DELETE FROM form_keys WHERE creation_date < $1',
96 // Purge delete files older than one month.
97 if (is_dir(forge_get_config('data_path').'/tracker')) {
98 system('find "'.forge_get_config('data_path').'/tracker" -name "*.removed" -type f -mtime +30 -exec rm -- {} \\;');
103 $err .= "Error: ".db_error();