mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
chore: update logic
This commit is contained in:
+9
-1
@@ -219,7 +219,15 @@ Server::setResource('abuseRetention', function () {
|
||||
});
|
||||
|
||||
Server::setResource('auditRetention', function () {
|
||||
return System::getEnv('_APP_MAINTENANCE_RETENTION_AUDIT', 'project=1209600,console=15778800'); // project = 14 days, console = 6 months
|
||||
return array_map(
|
||||
function ($part) {
|
||||
[$key, $value] = explode('=', $part);
|
||||
return [
|
||||
$key => DateTime::addSeconds(new \DateTime(), -1 * (int)$value)
|
||||
];
|
||||
},
|
||||
explode(',', System::getEnv('_APP_MAINTENANCE_RETENTION_AUDIT', 'project=1209600,console=15778800'))
|
||||
);
|
||||
});
|
||||
|
||||
Server::setResource('executionRetention', function () {
|
||||
|
||||
@@ -57,7 +57,7 @@ class Deletes extends Action
|
||||
->inject('auditRetention')
|
||||
->inject('log')
|
||||
->callback(
|
||||
fn ($message, Document $project, Database $dbForPlatform, callable $getProjectDB, callable $getLogsDB, Device $deviceForFiles, Device $deviceForFunctions, Device $deviceForBuilds, Device $deviceForCache, CertificatesAdapter $certificates, string $executionRetention, string $auditRetention, Log $log) =>
|
||||
fn ($message, Document $project, Database $dbForPlatform, callable $getProjectDB, callable $getLogsDB, Device $deviceForFiles, Device $deviceForFunctions, Device $deviceForBuilds, Device $deviceForCache, CertificatesAdapter $certificates, string $executionRetention, array $auditRetention, Log $log) =>
|
||||
$this->action($message, $project, $dbForPlatform, $getProjectDB, $getLogsDB, $deviceForFiles, $deviceForFunctions, $deviceForBuilds, $deviceForCache, $certificates, $executionRetention, $auditRetention, $log)
|
||||
);
|
||||
}
|
||||
@@ -66,7 +66,7 @@ class Deletes extends Action
|
||||
* @throws Exception
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function action(Message $message, Document $project, Database $dbForPlatform, callable $getProjectDB, callable $getLogsDB, Device $deviceForFiles, Device $deviceForFunctions, Device $deviceForBuilds, Device $deviceForCache, CertificatesAdapter $certificates, string $executionRetention, string $auditRetention, Log $log): void
|
||||
public function action(Message $message, Document $project, Database $dbForPlatform, callable $getProjectDB, callable $getLogsDB, Device $deviceForFiles, Device $deviceForFunctions, Device $deviceForBuilds, Device $deviceForCache, CertificatesAdapter $certificates, string $executionRetention, array $auditRetention, Log $log): void
|
||||
{
|
||||
$payload = $message->getPayload() ?? [];
|
||||
|
||||
@@ -746,21 +746,14 @@ class Deletes extends Action
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
private function deleteAuditLogs(Document $project, callable $getProjectDB, string $auditRetention): void
|
||||
private function deleteAuditLogs(Document $project, callable $getProjectDB, array $auditRetention): void
|
||||
{
|
||||
$projectId = $project->getId();
|
||||
$dbForProject = $getProjectDB($project);
|
||||
|
||||
[$projectAuditRetention, $consoleAuditRetention] = array_map(
|
||||
function ($part) {
|
||||
return DateTime::addSeconds(new \DateTime(), -1 * (int)explode('=', $part)[1]);
|
||||
},
|
||||
explode(',', $auditRetention)
|
||||
);
|
||||
|
||||
try {
|
||||
$this->deleteByGroup(Audit::COLLECTION, [
|
||||
Query::lessThan('time', ($projectId === 'console' ? $consoleAuditRetention : $projectAuditRetention)),
|
||||
Query::lessThan('time', ($projectId === 'console' ? $auditRetention['console'] : $auditRetention['project'])),
|
||||
Query::orderDesc('time'),
|
||||
Query::orderDesc('$internalId'),
|
||||
], $dbForProject);
|
||||
|
||||
Reference in New Issue
Block a user