improved log fodder creation

deleting of old log files
This commit is contained in:
Steffen Schröder
2014-06-20 14:57:02 +02:00
parent 53e3078cc1
commit 6e08ee9ac7
2 changed files with 87 additions and 23 deletions

View File

@ -14,6 +14,7 @@ use ManiaControl\Utils\Formatter;
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
abstract class FileUtil {
/**
* Load a remote file
*
@ -186,4 +187,35 @@ abstract class FileUtil {
}
}
}
/**
* Delete old ManiaControl Log Files
*
* @param int $maxFileAgeInDays
* @return bool
*/
public static function deleteOldLogFiles($maxFileAgeInDays = 14) {
$logsFolderPath = Logger::getLogsFolderPath();
if (!is_readable($logsFolderPath)) {
return false;
}
$dirHandle = opendir($logsFolderPath);
if (!is_resource($dirHandle)) {
return false;
}
$time = time();
while ($fileName = readdir($dirHandle)) {
$filePath = $logsFolderPath . $fileName;
if (!is_readable($filePath)) {
continue;
}
$fileModTime = filemtime($filePath);
$timeDeltaDays = ($time - $fileModTime) / (24 * 3600);
if ($timeDeltaDays > $maxFileAgeInDays) {
unlink($filePath);
}
}
closedir($dirHandle);
return true;
}
}