Add dir variable on delete path variable
This commit is contained in:
parent
82e5248658
commit
67cc103db5
26
app/models/managers/LogMaintainer.php
Normal file
26
app/models/managers/LogMaintainer.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
class LogMaintainer
|
||||||
|
{
|
||||||
|
private 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)))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!is_dir($dir . $file)) {
|
||||||
|
if (strtotime(str_replace(".log", "", $file)) < (strtotime("now") - $seconds)) {
|
||||||
|
unlink ($dir . $file);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->cleaningDir ($dir . $file . "/", $seconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function purge ($days) {
|
||||||
|
$seconds = $days * 86400;
|
||||||
|
$this->cleaningDir ('../logs/', $seconds);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user