function task_optimize($connection, $settings, $time, $table = false, $and_default = true) { require_once $settings['functions'] . 'function.task.log.php'; if ($table) { $tables[] = $table; } if ($and_default) { $tables[] = 'peers'; $tables[] = 'tasks'; $tables[] = 'torrents'; } $sql = ''; foreach ($tables as $table) { $sql .= 'CHECK TABLE `' . $settings['db_prefix'] . $table . '`;' . 'ANALYZE TABLE `' . $settings['db_prefix'] . $table . '`;' . 'REPAIR TABLE `' . $settings['db_prefix'] . $table . '`;' . 'OPTIMIZE TABLE `' . $settings['db_prefix'] . $table . '`;'; } $result = mysqli_multi_query($connection, $sql); if ($result) { while (mysqli_more_results($connection)) { mysqli_next_result($connection); mysqli_store_result($connection); } } if ($result) { task_log($connection, $settings, 'optimize', $time); } return $result; }
function task_clean($connection, $settings, $time) { require_once $settings['functions'] . 'function.task.log.php'; $cleaned = true; // Delete Peers that have been idle twice the announce interval. $sql[] = 'DELETE FROM `' . $settings['db_prefix'] . 'peers`' . ' WHERE `updated` < \'' . ($time - $settings['announce_interval'] * 3) . '\'' . ' OR `info_hash` LIKE \'__TEST_%\'' . ' OR `info_hash` = \'DELETEME\'' . ' OR `peer_id` LIKE \'__TEST_%\'' . ' OR `peer_id` = \'DELETEME\';'; $sql[] = 'DELETE FROM `' . $settings['db_prefix'] . 'tasks`' . ' WHERE `name` LIKE \'__TEST_%\'' . ' OR `name` = \'DELETEME\';'; $sql[] = 'DELETE FROM `' . $settings['db_prefix'] . 'torrents`' . ' WHERE `info_hash` LIKE \'__TEST_%\'' . ' OR `info_hash` = \'DELETEME\'' . ' OR `name` LIKE \'__TEST_%\'' . ' OR `name` = \'DELETEME\';'; foreach ($sql as $query) { $result = mysqli_query($connection, $query); if (!$result) { $cleaned = false; } } if ($cleaned) { task_log($connection, $settings, 'clean', $time); } return $cleaned; }
<?php require_once $settings['functions'] . 'function.task.log.php'; $result = task_log($connection, $settings, '__TEST__', 1); $delete = 'DELETE FROM `' . $settings['db_prefix'] . 'tasks` WHERE `name` LIKE \'__TEST_%\';'; mysqli_query($connection, $delete); if (!$result) { echo 'Error: Test for Function "task" failed.' . PHP_EOL; $failure = true; }