Skip to content
Snippets Groups Projects
Commit 1796a7b5 authored by Robert Anderson's avatar Robert Anderson
Browse files

User data cleanup

Added cleanup functionality to remove old user data if the user no longer exists
parent 532c0930
No related branches found
No related tags found
No related merge requests found
......@@ -50,7 +50,10 @@ our $pluginInfo = {
# Users data
Users_data_set => \&data_set,
Users_data_get => \&data_get
Users_data_get => \&data_get,
# Cleanup run by smadmin
Cleanup => \&cleanup
};
# Module config
......@@ -142,15 +145,6 @@ sub init
AND Name = %{query.Name}
';
$config->{'users_data_cleanup_query'} = '
DELETE FROM
@TP@users_data
WHERE UserID NOT IN
(
SELECT ID FROM users
)
';
# Default cache time for user data
$config->{'userdb_data_cache_time'} = 300;
......@@ -228,16 +222,6 @@ sub init
}
}
if (defined($scfg->{'mod_userdb_sql'}->{'users_data_cleanup_query'}) &&
$scfg->{'mod_userdb_sql'}->{'users_data_cleanup_query'} ne "") {
if (ref($scfg->{'mod_userdb_sql'}->{'users_data_cleanup_query'}) eq "ARRAY") {
$config->{'users_data_cleanup_query'} = join(' ',
@{$scfg->{'mod_userdb_sql'}->{'users_data_cleanup_query'}});
} else {
$config->{'users_data_cleanup_query'} = $scfg->{'mod_userdb_sql'}->{'users_data_cleanup_query'};
}
}
if (defined($scfg->{'mod_userdb_sql'}->{'userdb_data_cache_time'})) {
if ($scfg->{'mod_userdb_sql'}{'userdb_data_cache_time'} =~ /^\s*(yes|true|1)\s*$/i) {
# Default?
......@@ -531,5 +515,36 @@ sub data_get
}
# Clean up of old user variables
sub cleanup
{
my $server = shift;
# Begin operation
DBBegin();
# Perform query
my $sth = DBDo('
DELETE FROM
@TP@users_data
WHERE UserID NOT IN
(
SELECT ID FROM users
)
');
# Error and rollback
if (!$sth) {
$server->log(LOG_NOTICE,"[MOD_USERDB_SQL] Cleanup => Database has been rolled back, no records deleted");
DBRollback();
return;
}
# Commit
DBCommit();
$server->log(LOG_NOTICE,"[MOD_USERDB_SQL] Cleanup => Old user variables have been deleted");
}
1;
# vim: ts=4
......@@ -489,15 +489,6 @@ users_data_delete_query=<<EOT
AND Name = %{query.Name}
EOT
users_data_cleanup_query=<<EOT
DELETE FROM
@TP@users_data
WHERE UserID NOT IN
(
SELECT ID FROM users
)
EOT
# This is how long we going to cache the data query for
# Default: 300 (seconds)
#
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment