♻️ Refactor: Decouple DeleteUnconfirmedUsersCronjob (Separation of Concerns) #8

Closed
opened 2025-11-22 13:47:58 +01:00 by DSR-Labs · 0 comments
DSR-Labs commented 2025-11-22 13:47:58 +01:00 (Migrated from github.com)

Refactor cronjob architecture to separate business logic and notification handling

Description
The background task responsible for cleaning up unconfirmed users currently handles too many distinct responsibilities. It simultaneously manages the user deletion process, constructs email notifications, and handles GDPR data anonymization. This tight coupling makes the code difficult to maintain and extend.

We need to refactor this architecture to decouple these components into a service-oriented structure.

Proposed Changes

  • Extract GDPR Anonymization: The logic for masking usernames and email addresses should be moved into a dedicated utility class. This ensures the logic is reusable and isolated from the deletion process.
  • Dedicated Notification Service: The handling of email notifications, including the retrieval of administrator recipients and the dispatching of messages, should be moved to a separate mail service class.
  • Template-Based Emails: Instead of building email content using hardcoded strings inside the logic, we should implement proper templates. This ensures a strict separation between the application logic and the design of the emails.
  • Simplified Controller: The main cronjob class should be reduced to a simple controller that coordinates the process by delegating tasks to these new services, rather than executing them directly.
# Refactor cronjob architecture to separate business logic and notification handling **Description** The background task responsible for cleaning up unconfirmed users currently handles too many distinct responsibilities. It simultaneously manages the user deletion process, constructs email notifications, and handles GDPR data anonymization. This tight coupling makes the code difficult to maintain and extend. We need to refactor this architecture to decouple these components into a service-oriented structure. **Proposed Changes** * **Extract GDPR Anonymization:** The logic for masking usernames and email addresses should be moved into a dedicated utility class. This ensures the logic is reusable and isolated from the deletion process. * **Dedicated Notification Service:** The handling of email notifications, including the retrieval of administrator recipients and the dispatching of messages, should be moved to a separate mail service class. * **Template-Based Emails:** Instead of building email content using hardcoded strings inside the logic, we should implement proper templates. This ensures a strict separation between the application logic and the design of the emails. * **Simplified Controller:** The main cronjob class should be reduced to a simple controller that coordinates the process by delegating tasks to these new services, rather than executing them directly.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
DSR-Labs/de.deinestrainreviews.autoDeleteUnconfirmedUsers#8
No description provided.