mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
N°2820 Log rotation : new MonthlyRotatingLogFileNameBuilder class
This commit is contained in:
@@ -331,6 +331,58 @@ class WeeklyRotatingLogFileNameBuilder extends RotatingLogFileNameBuilder
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.7.0 N°2820
|
||||
*/
|
||||
class MonthlyRotatingLogFileNameBuilder extends RotatingLogFileNameBuilder
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function ShouldRotate($oLogFileLastModified, $oNow)
|
||||
{
|
||||
$iLogYear = $oLogFileLastModified->format('Y');
|
||||
$iLogMonth = $oLogFileLastModified->format('n');
|
||||
$iNowYear = $oNow->format('Y');
|
||||
$iNowMonth = $oNow->format('n');
|
||||
|
||||
if ($iLogYear !== $iNowYear)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($iLogMonth !== $iNowMonth)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function GetFileSuffix($oDate)
|
||||
{
|
||||
$sWeekYear = $oDate->format('o');
|
||||
$sWeekNumber = $oDate->format('m');
|
||||
|
||||
return $sWeekYear.'-month'.$sWeekNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function GetCronProcessNextOccurrence(DateTime $oNow)
|
||||
{
|
||||
$oOccurrence = clone $oNow;
|
||||
$oOccurrence->modify('first day of next month');
|
||||
$oOccurrence->setTime(0, 0, 0);
|
||||
|
||||
return $oOccurrence;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.7.0 N°2518
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user