public function rotateLogs()
{
@trigger_error('Using Automator::rotateLogs() has been deprecated and will no longer work in Contao 5.0. Use the logger service instead, which rotates its log files automatically.', E_USER_DEPRECATED);
$arrFiles = preg_grep('/\\.log$/', scan(TL_ROOT . '/system/logs'));
foreach ($arrFiles as $strFile) {
$objFile = new \File('system/logs/' . $strFile . '.9');
// Delete the oldest file
if ($objFile->exists()) {
$objFile->delete();
}
// Rotate the files (e.g. error.log.4 becomes error.log.5)
for ($i = 8; $i > 0; $i--) {
$strGzName = 'system/logs/' . $strFile . '.' . $i;
if (file_exists(TL_ROOT . '/' . $strGzName)) {
$objFile = new \File($strGzName);
$objFile->renameTo('system/logs/' . $strFile . '.' . ($i + 1));
}
}
// Add .1 to the latest file
$objFile = new \File('system/logs/' . $strFile);
$objFile->renameTo('system/logs/' . $strFile . '.1');
}
}