mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2025-12-30 00:53:50 +00:00
implement changes in to the event_guard class (#7045)
Co-authored-by: Tim Fry <tim@fusionpbx.com>
This commit is contained in:
@@ -287,7 +287,34 @@ if (!class_exists('users')) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove old user log entries. Called the maintenance service application.
|
||||
* @param settings $settings
|
||||
* @return void
|
||||
*/
|
||||
public static function database_maintenance(settings $settings): void {
|
||||
$database = $settings->database();
|
||||
$domains = maintenance_service::get_domains($database);
|
||||
foreach ($domains as $domain_uuid => $domain_name) {
|
||||
$domain_settings = new settings(['database' => $database, 'domain_uuid' => $domain_uuid]);
|
||||
$retention_days = $domain_settings->get('users', 'database_retention_days', '');
|
||||
if (!empty($retention_days) && is_numeric($retention_days)) {
|
||||
$sql = "delete from v_user_logs where timestamp < NOW() - INTERVAL '$retention_days days'";
|
||||
$sql.= " and domain_uuid = '$domain_uuid'";
|
||||
$database->execute($sql);
|
||||
$code = $database->message['code'] ?? 0;
|
||||
if ($code == 200) {
|
||||
maintenance_service::log_write(self::class, "Removed database entries older than $retention_days", $domain_uuid);
|
||||
} else {
|
||||
$message = $database->message['message'] ?? "An unknown error has occurred";
|
||||
maintenance_service::log_write(self::class, "Unable to remove old database records. Error message: $message ($code)", $domain_uuid, maintenance_service::LOG_ERROR);
|
||||
}
|
||||
} else {
|
||||
maintenance_service::log_write(self::class, "Database retention days not set or not numeric", $domain_uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user