.htaccess
1 year ago
Automation.php
10 months ago
General.php
3 months ago
Integrations.php
4 months ago
Logging.php
4 months ago
Maintenance.php
4 months ago
Notifications.php
4 months ago
Performance.php
3 months ago
Restore.php
1 year ago
Security.php
1 day ago
Settings.php
4 months ago
Updates.php
4 months ago
index.html
1 year ago
web.config
1 year ago
Logging.php
81 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JetBackup\Settings; |
| 4 | |
| 5 | use JetBackup\Exception\FieldsValidationException; |
| 6 | |
| 7 | if (!defined( '__JETBACKUP__')) die('Direct access is not allowed'); |
| 8 | |
| 9 | class Logging extends Settings { |
| 10 | |
| 11 | const SECTION = 'logging'; |
| 12 | |
| 13 | const DEBUG = 'DEBUG'; |
| 14 | const LOG_ROTATE = 'LOG_ROTATE'; |
| 15 | |
| 16 | /** |
| 17 | * @throws \JetBackup\Exception\IOException |
| 18 | * @throws \ReflectionException |
| 19 | */ |
| 20 | public function __construct() { |
| 21 | parent::__construct(self::SECTION); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * @return bool |
| 26 | */ |
| 27 | public function isDebugEnabled():bool { return (bool) $this->get(self::DEBUG, false); } |
| 28 | |
| 29 | /** |
| 30 | * @param bool $value |
| 31 | * |
| 32 | * @return void |
| 33 | */ |
| 34 | public function setDebugEnabled(bool $value):void { $this->set(self::DEBUG, $value); } |
| 35 | |
| 36 | /** |
| 37 | * @return int |
| 38 | */ |
| 39 | public function getLogRotate():int { return (int) $this->get(self::LOG_ROTATE, 7); } |
| 40 | |
| 41 | /** |
| 42 | * @param int $value |
| 43 | * |
| 44 | * @return void |
| 45 | */ |
| 46 | public function setLogRotate(int $value):void { $this->set(self::LOG_ROTATE, $value); } |
| 47 | |
| 48 | /** |
| 49 | * @return array |
| 50 | */ |
| 51 | public function getDisplay():array { |
| 52 | |
| 53 | return [ |
| 54 | self::DEBUG => $this->isDebugEnabled() ? 1 : 0, |
| 55 | self::LOG_ROTATE => $this->getLogRotate(), |
| 56 | ]; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @return string[] |
| 61 | */ |
| 62 | public function getDisplayCLI():array { |
| 63 | |
| 64 | return [ |
| 65 | 'Debug Enabled' => $this->isDebugEnabled() ? "Yes" : "No", |
| 66 | 'Log Rotate' => $this->getLogRotate(), |
| 67 | ]; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @return void |
| 72 | */ |
| 73 | public function validateFields():void { |
| 74 | |
| 75 | $changedFields = self::getChangedFields($this->getData(), (new Logging())->getData()); |
| 76 | |
| 77 | if(in_array(self::LOG_ROTATE, $changedFields)) { |
| 78 | if($this->getLogRotate() < 0) throw new FieldsValidationException("Log rotation must be a positive integer"); |
| 79 | } |
| 80 | } |
| 81 | } |