From eba5301906689b921d77319ea95f7ce2b1e3e3b4 Mon Sep 17 00:00:00 2001 From: Haitem Date: Mon, 20 Jul 2020 19:15:23 +0200 Subject: [PATCH] Add old log remover and repair islogin function error --- app/models/managers/LogManager.php | 23 +++++++++++++++-------- app/views/Ajax.php | 2 +- app/views/Automation.php | 4 ++-- app/views/Log.php | 4 ++-- app/views/Login.php | 2 +- app/views/Setting.php | 4 ++-- 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/app/models/managers/LogManager.php b/app/models/managers/LogManager.php index dde1c14..cb0931d 100644 --- a/app/models/managers/LogManager.php +++ b/app/models/managers/LogManager.php @@ -11,21 +11,28 @@ class LogRecordType{ class LogKeeper { - function purge($days){ - $todayFileName = date("Y-m-d").'.log'; - $seconds = $days * 86400; - - $logFiles = scandir('../logs/'); + function cleaningDir ($dir, $seconds) { + $todayFileName = date ("Y-m-d").'.log'; + $logFiles = scandir ($dir); foreach ($logFiles as $key => $file) { - if (in_array($file,array(".","..", ".gitkeep", $todayFileName))) + if (in_array ($file,array (".", "..", ".gitkeep", $todayFileName))) { continue; } - if (filemtime($file) > $seconds) { - unlink('../logs/'.$file); + if (!is_dir($dir . $file)) { + if (strtotime(str_replace(".log", "", $file)) < (strtotime("now") - $seconds)) { + unlink ($dir . $file); + } + } else { + $this->cleaningDir ($path . $file . "/", $seconds); } } } + + function purge ($days) { + $seconds = $days * 86400; + $this->cleaningDir ('../logs/', $seconds); + } } class LogManager diff --git a/app/views/Ajax.php b/app/views/Ajax.php index 96554a3..06fba1a 100644 --- a/app/views/Ajax.php +++ b/app/views/Ajax.php @@ -4,7 +4,7 @@ class Ajax extends Template { function __construct() { - global $userManager; + $userManager = new UserManager(); global $lang; if (!$userManager->isLogin()){ diff --git a/app/views/Automation.php b/app/views/Automation.php index 8bd7263..5f76e22 100644 --- a/app/views/Automation.php +++ b/app/views/Automation.php @@ -3,8 +3,8 @@ class Automation extends Template { function __construct() { - global $userManager; - global $langMng; + $userManager = new UserManager(); + global $lang; if (!$userManager->isLogin()){ header('Location: ' . BASEURL . 'login'); diff --git a/app/views/Log.php b/app/views/Log.php index 81fedd6..cf95de1 100644 --- a/app/views/Log.php +++ b/app/views/Log.php @@ -18,8 +18,8 @@ class Log extends Template function __construct() { - global $userManager; - global $langMng; + $userManager = new UserManager(); + global $lang; if (!$userManager->isLogin()){ header('Location: ' . BASEURL . 'login'); diff --git a/app/views/Login.php b/app/views/Login.php index d905d03..e91c775 100644 --- a/app/views/Login.php +++ b/app/views/Login.php @@ -3,7 +3,7 @@ class Login extends Template { function __construct() { - global $userManager; + $userManager = new UserManager(); global $lang; if ($userManager->isLogin()){ diff --git a/app/views/Setting.php b/app/views/Setting.php index d89c28d..e173ec1 100644 --- a/app/views/Setting.php +++ b/app/views/Setting.php @@ -4,8 +4,8 @@ class Setting extends Template function __construct() { - global $userManager; - global $langMng; + $userManager = new UserManager(); + global $lang; if (!$userManager->isLogin()){ header('Location: ' . BASEURL . 'login');