From 065b7a01eb2511133216e112d8a47751aa75151e Mon Sep 17 00:00:00 2001 From: Ben Millar Date: Thu, 10 Oct 2024 22:29:19 +0100 Subject: [PATCH] Cleanup Historic Case Archive --- cla_backend/apps/cla_butler/tasks.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cla_backend/apps/cla_butler/tasks.py b/cla_backend/apps/cla_butler/tasks.py index f6ce322da..aa295f7a1 100644 --- a/cla_backend/apps/cla_butler/tasks.py +++ b/cla_backend/apps/cla_butler/tasks.py @@ -36,6 +36,7 @@ EODDetailsCategory, Property, ) +from historic.models import CaseArchived from timer.models import Timer from legalaid.utils import diversity from cla_butler.models import DiversityDataCheck, ACTION, STATUS @@ -71,6 +72,7 @@ def run(self, delete_option, *args, **kwargs): self.cleanup_adaptation_details() self.cleanup_sessions() self.cleanup_access_tokens() + self.cleanup_historic_casearchive() def _setup(self): self.now = timezone.now() @@ -230,6 +232,14 @@ def cleanup_audit(self, pks): audit_logs = AuditLog.objects.filter(complaint__in=case_complaints) audit_logs.delete() + def cleanup_historic_casearchive(self): + """ Removes all Archived Cases that not been modified in over 3 years. + No fields in this model have a relationship to any other model. + """ + three_years_ago = self.now - relativedelta(years=3) + archived_cases = CaseArchived.objects.filter(modifed__lte=three_years_ago) + archived_cases.delete() + class DiversityDataCheckTask(Task): def run(self, passphrase, start, end, description, *args, **kwargs):