Merge branch 'feature/delayed-dbclean'

This commit is contained in:
Jeroen De Meerleer 2018-09-14 13:09:34 +02:00
commit 0024996c8d
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
4 changed files with 43 additions and 35 deletions

View File

@ -28,15 +28,15 @@ require_once "include/initialize.inc.php";
if ($_SERVER["REQUEST_METHOD"] == "GET") {
$message = "";
if (isset($_GET["message"])) {
switch ($_GET["message"]) {
case "edited":
$message = "The config has been edited"; break;
}
}
$error = "";
$message = "";
if (isset($_GET["message"])) {
switch ($_GET["message"]) {
case "edited":
$message = "The config has been edited"; break;
}
}
$error = "";
if (isset($_GET["error"])) {
switch ($_GET["error"]) {
case "emptyfields":
@ -45,28 +45,28 @@ if ($_SERVER["REQUEST_METHOD"] == "GET") {
}
$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader, array('cache' => 'cache', "debug" => true));
$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader, array('cache' => 'cache', "debug" => true));
$configs = load_config_categorized();
$configs = load_config_categorized();
$twig_vars = array('config' => $configs, "error" => $error, "message" => $message);
$twig_vars = array('config' => $configs, "error" => $error, "message" => $message);
echo $twig->render('config.html.twig', $twig_vars);
echo $twig->render('config.html.twig', $twig_vars);
}
elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
foreach($_POST as $key => $value) {
if (empty($value)) {
header("location:config.php?error=emptyfields"); exit;
}
foreach($_POST as $key => $value) {
if (empty($value)) {
header("location:config.php?error=emptyfields"); exit;
}
$keydb = str_replace('_', '.', $key);
$stmt = $db->prepare("UPDATE config SET value = ? WHERE conf = ?");
$stmt->execute(array($value, $keydb));
}
$keydb = str_replace('_', '.', $key);
$stmt = $db->prepare("UPDATE config SET value = ? WHERE conf = ?");
$stmt->execute(array($value, $keydb));
}
header("location:config.php?message=edited");
header("location:config.php?message=edited");
exit;
}

View File

@ -36,7 +36,9 @@ CREATE TABLE IF NOT EXISTS `config` (
--
INSERT INTO `config` (`conf`, `category`, `type`, `label`, `description`, `value`) VALUES
('dbclean.expireruns', 'Database Cleanup', 'number(0,-1)', 'Retention value', 'How many days does the database keep the runs', '30'),
('dbclean.delay', 'Database Cleanup', 'number(0)', 'Cleanup Delay', 'How many days until the database cleanup is triggered', '7'),
('dbclean.expireruns', 'Database Cleanup', 'number(0)', 'Retention value', 'How many days does the database keep the runs', '30'),
('dbclean.lastrun', 'Database Cleanup', 'hidden', 'Last run', 'Last run of database cleanup', UNIX_TIMESTAMP()),
('jobs.reboottime', 'Jobs', 'number(0,30)', 'Reboot delay', 'The amount of delay in minutes between scheduling a reboot and the actual reboot', '5');
-- --------------------------------------------------------

View File

@ -48,7 +48,8 @@ function load_config_categorized() {
$configCategorized[$value['category']][$count]['label'] = $value['label'];
$configCategorized[$value['category']][$count]['description'] = $value['description'];
$configCategorized[$value['category']][$count]['type'] = parse_config_type($value['type']);
$count++;
if ($configCategorized[$value['category']][$count]['type']['type'] != 'hidden') $count++;
}
// into a easy twig array
@ -74,18 +75,20 @@ function get_configvalue($conf) {
}
function parse_config_type($type) {
$splittype = explode('(', substr($type, 0, -1));
$splittype = explode('(', explode(')', $type)[0]);
$r_var['type'] = $splittype[0];
$splitargs = explode(',', $splittype[1]);
if (isset($splittype[1])) {
$splitargs = explode(',', $splittype[1]);
switch($r_var['type'])
{
case 'number':
$r_var['args'][] = $splitargs[0] != '-1' ? 'min="' . $splitargs[0] . '"' : '';
$r_var['args'][] = $splitargs[1] != '-1' ? 'max="' . $splitargs[1] . '"' : '';
break;
}
switch($r_var['type'])
{
case 'number':
$r_var['args'][] = isset($splitargs[0]) ? 'min="' . $splitargs[0] . '"' : '';
$r_var['args'][] = isset($splitargs[1]) ? 'max="' . $splitargs[1] . '"' : '';
break;
}
}
return $r_var;
}
@ -96,4 +99,7 @@ function clean_database() {
$stmt = $db->prepare("DELETE FROM runs WHERE timestamp < ?");
$stmt->execute(array($oldestrun));
$stmt = $db->prepare("UPDATE config SET value = ? WHERE conf = ?");
$stmt->execute(array(time(), 'dbclean.lastrun'));
}

View File

@ -105,7 +105,7 @@ foreach ($results as $result) {
$nosave = false;
}
clean_database();
if (get_configvalue('dbclean.lastrun') + (60 * 60 * 24 * get_configvalue('dbclean.delay')) < time()) clean_database();
unlink('/tmp/webcron.lock');