release 1.2.4
This commit is contained in:
100
jobs/clean.php
100
jobs/clean.php
@@ -1,45 +1,24 @@
|
||||
<?PHP
|
||||
function clean($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$cleanclients,$cleanperiod,$logpath) {
|
||||
$count_tsuser['count'] = 0;
|
||||
function clean($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$cleanclients,$cleanperiod,$logpath,$select_arr) {
|
||||
$nowtime = time();
|
||||
$sqlexec = '';
|
||||
|
||||
// clean usersnaps older then 1 month
|
||||
if($mysqlcon->query("DELETE a FROM $dbname.user_snapshot AS a CROSS JOIN(SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 1000 OFFSET 121) AS b WHERE a.timestamp=b.timestamp") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"clean 2.1:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
|
||||
// clean old server usage - older then a year
|
||||
if($mysqlcon->query("DELETE FROM $dbname.server_usage WHERE timestamp < (UNIX_TIMESTAMP() - 31536000)") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"clean 2.2:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
|
||||
// clean old clients out of the database
|
||||
if ($cleanclients == 1) {
|
||||
$cleantime = $nowtime - $cleanperiod;
|
||||
if(($lastclean = $mysqlcon->query("SELECT * FROM $dbname.job_check WHERE job_name='check_clean'")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"clean 3:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$lastclean = $lastclean->fetchAll();
|
||||
if ($lastclean[0]['timestamp'] < $cleantime) {
|
||||
if(($dbuserdata = $mysqlcon->query("SELECT uuid FROM $dbname.user")) === false) {
|
||||
enter_logfile($logpath,$timezone,2,"clean 4:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$countrs = $dbuserdata->rowCount();
|
||||
$uuids = $dbuserdata->fetchAll();
|
||||
if($select_arr['job_check']['clean_clients']['timestamp'] < ($nowtime - $cleanperiod)) {
|
||||
if ($cleanclients == 1) {
|
||||
enter_logfile($logpath,$timezone,4,$lang['clean']);
|
||||
$start=0;
|
||||
$start = $countdel = $countts = 0;
|
||||
$break=200;
|
||||
$count_tsuser['count'] = 0;
|
||||
$clientdblist=array();
|
||||
$countdel=0;
|
||||
$countts=0;
|
||||
while($getclientdblist=$ts3->clientListDb($start, $break)) {
|
||||
$clientdblist=array_merge($clientdblist, $getclientdblist);
|
||||
$start=$start+$break;
|
||||
$count_tsuser=array_shift($getclientdblist);
|
||||
if ($start == 100000 || $count_tsuser['count'] <= $start) {
|
||||
if($count_tsuser['count'] <= $start) {
|
||||
break;
|
||||
}
|
||||
check_shutdown($timezone,$logpath); usleep($slowmode);
|
||||
usleep($slowmode);
|
||||
}
|
||||
foreach($clientdblist as $uuidts) {
|
||||
$single_uuid = $uuidts['client_unique_identifier']->toString();
|
||||
@@ -47,43 +26,68 @@ function clean($ts3,$mysqlcon,$lang,$dbname,$slowmode,$timezone,$cleanclients,$c
|
||||
}
|
||||
unset($clientdblist);
|
||||
|
||||
foreach($uuids as $uuid) {
|
||||
if(isset($uidarrts[$uuid[0]])) {
|
||||
foreach($select_arr['all_user'] as $uuid => $value) {
|
||||
if(isset($uidarrts[$uuid])) {
|
||||
$countts++;
|
||||
} else {
|
||||
$deleteuuids[] = $uuid[0];
|
||||
$deleteuuids[] = $uuid;
|
||||
$countdel++;
|
||||
}
|
||||
}
|
||||
|
||||
unset($uidarrts);
|
||||
enter_logfile($logpath,$timezone,4," ".sprintf($lang['cleants'], $countts, $count_tsuser['count']));
|
||||
enter_logfile($logpath,$timezone,4," ".sprintf($lang['cleanrs'], $countrs));
|
||||
enter_logfile($logpath,$timezone,4," ".sprintf($lang['cleanrs'], count($select_arr['all_user'])));
|
||||
|
||||
if(isset($deleteuuids)) {
|
||||
$alldeldata = '';
|
||||
foreach ($deleteuuids as $dellarr) {
|
||||
$alldeldata = $alldeldata . "'" . $dellarr . "',";
|
||||
$fsfilelist = opendir(substr(__DIR__,0,-4).'avatars/');
|
||||
while (false !== ($fsfile = readdir($fsfilelist))) {
|
||||
if ($fsfile != '.' && $fsfile != '..') {
|
||||
$fsfilelistarray[$fsfile] = filemtime(substr(__DIR__,0,-4).'avatars/'.$fsfile);
|
||||
}
|
||||
}
|
||||
$alldeldata = substr($alldeldata, 0, -1);
|
||||
$alldeldata = "(".$alldeldata.")";
|
||||
if ($alldeldata != '') {
|
||||
if($mysqlcon->exec("DELETE FROM $dbname.user WHERE uuid IN $alldeldata") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"clean 5:".print_r($mysqlcon->errorInfo(), true));
|
||||
} else {
|
||||
enter_logfile($logpath,$timezone,4," ".sprintf($lang['cleandel'], $countdel));
|
||||
if($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='check_clean'") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"clean 6:".print_r($mysqlcon->errorInfo(), true));
|
||||
unset($fsfilelist);
|
||||
$avatarfilepath = substr(__DIR__,0,-4).'avatars/';
|
||||
$convert = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p');
|
||||
foreach ($deleteuuids as $uuid) {
|
||||
$alldeldata = $alldeldata . "'" . $uuid . "',";
|
||||
$uuidasbase16 = '';
|
||||
for ($i = 0; $i < 20; $i++) {
|
||||
$char = ord(substr(base64_decode($uuid), $i, 1));
|
||||
$uuidasbase16 .= $convert[($char & 0xF0) >> 4];
|
||||
$uuidasbase16 .= $convert[$char & 0x0F];
|
||||
}
|
||||
if (isset($fsfilelistarray[$uuidasbase16.'.png'])) {
|
||||
if(unlink($avatarfilepath.$uuidasbase16.'.png') === false) {
|
||||
enter_logfile($logpath,$timezone,2," ".sprintf($lang['clean0002'], $uuidasbase16, $uuid).' '.sprintf($lang['errperm'], 'avatars'));
|
||||
} else {
|
||||
enter_logfile($logpath,$timezone,4," ".sprintf($lang['clean0001'], $uuidasbase16, $uuid));
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($$deleteuuids);
|
||||
$alldeldata = substr($alldeldata, 0, -1);
|
||||
$alldeldata = "(".$alldeldata.")";
|
||||
if ($alldeldata != '') {
|
||||
$sqlexec .= "UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='clean_clients'; UPDATE $dbname.stats_user AS t LEFT JOIN $dbname.user AS u ON t.uuid=u.uuid SET t.removed='1' WHERE u.uuid IS NULL; DELETE FROM $dbname.user WHERE uuid IN $alldeldata; ";
|
||||
enter_logfile($logpath,$timezone,4," ".sprintf($lang['cleandel'], $countdel));
|
||||
unset($$alldeldata);
|
||||
}
|
||||
} else {
|
||||
enter_logfile($logpath,$timezone,4," ".$lang['cleanno']);
|
||||
if($mysqlcon->exec("UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='check_clean'") === false) {
|
||||
enter_logfile($logpath,$timezone,2,"clean 7:".print_r($mysqlcon->errorInfo(), true));
|
||||
}
|
||||
$sqlexec .= "UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='clean_clients'; ";
|
||||
}
|
||||
} else {
|
||||
enter_logfile($logpath,$timezone,4,$lang['clean0004']);
|
||||
$sqlexec .= "UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='clean_clients'; ";
|
||||
}
|
||||
}
|
||||
|
||||
// clean usersnaps older then 1 month + clean old server usage - older then a year
|
||||
if ($select_arr['job_check']['clean_db']['timestamp'] < ($nowtime - 86400)) {
|
||||
$sqlexec .= "DELETE a FROM $dbname.user_snapshot AS a CROSS JOIN(SELECT DISTINCT(timestamp) FROM $dbname.user_snapshot ORDER BY timestamp DESC LIMIT 1000 OFFSET 121) AS b WHERE a.timestamp=b.timestamp; DELETE FROM $dbname.server_usage WHERE timestamp < (UNIX_TIMESTAMP() - 31536000); DELETE b FROM $dbname.user a RIGHT JOIN $dbname.stats_user b ON a.uuid = b.uuid WHERE a.uuid IS NULL; UPDATE $dbname.job_check SET timestamp='$nowtime' WHERE job_name='clean_db'; ";
|
||||
enter_logfile($logpath,$timezone,4,$lang['clean0003']);
|
||||
}
|
||||
return($sqlexec);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user