0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-05-03 05:20:31 +00:00
nextcloud_server/lib/public/Log/RotationTrait.php
Ferdinand Thiessen 832f79ac93
chore: apply code style
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
2025-04-30 19:04:59 +02:00

51 lines
873 B
PHP

<?php
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Log;
/**
* Trait RotationTrait
*
*
* @since 14.0.0
*/
trait RotationTrait {
/**
* @var string
* @since 14.0.0
*/
protected $filePath;
/**
* @var int
* @since 14.0.0
*/
protected $maxSize;
/**
* @return string the resulting new filepath
* @since 14.0.0
*/
protected function rotate():string {
$rotatedFile = $this->filePath.'.1';
rename($this->filePath, $rotatedFile);
return $rotatedFile;
}
/**
* @return bool
* @since 14.0.0
*/
protected function shouldRotateBySize():bool {
if ((int) $this->maxSize > 0 && file_exists($this->filePath)) {
$filesize = @filesize($this->filePath);
if ($filesize >= (int) $this->maxSize) {
return true;
}
}
return false;
}
}