Skip to content

Implement Background CSV Export for Case Retention Logs with Async Download#8760

Merged
sanjacornelius merged 4 commits intoepic/FOUR-29101from
task/FOUR-29118
Mar 27, 2026
Merged

Implement Background CSV Export for Case Retention Logs with Async Download#8760
sanjacornelius merged 4 commits intoepic/FOUR-29101from
task/FOUR-29118

Conversation

@sanjacornelius
Copy link
Copy Markdown
Contributor

@sanjacornelius sanjacornelius commented Mar 25, 2026

This PR introduces a background CSV export for Case Retention Policy logs. Since exporting large datasets can be slow, this moves the process to an async job so it doesn’t block the UI. Users can trigger the export, continue working, and download the file once it’s ready, aligned with how other admin exports (e.g. security logs) behave.

Solution

  • API: GET /api/1.0/cases-retention/logs/export
    • Dispatches DownloadCaseRetentionLogExport job
    • Returns immediate response indicating processing has started
  • Job:
    • Generates a UTF-8 CSV using existing filter logic (CaseRetentionLogQueryFilter) and writer (CaseRetentionLogCsvWriter)
    • On success: fires CaseRetentionLogExportReady with a temporary signed download URL (24h TTL)
    • On failure: fires CaseRetentionLogExportFailed and cleans up any partial files
  • Download Route:
    • Streams file as case_retention_policy_logs.csv
    • Deletes file after download
  • Realtime UX:
    • Listens for .CaseRetentionLogExportReady / .CaseRetentionLogExportFailed
    • Displays global notification with download link (consistent with security logs export pattern)
  • Tests: CasesRetentionLogsExportTest covers:
    • Job dispatch
    • Filter propagation
    • Signed download returning CSV when file exists

How to Test

  1. Log in as an admin, open Admin > Cases Retention Policy Logs
  2. Select the 'Download' button. Confirm an immediate success toast that the file is processing
  3. When the job finishes, confirm an in-app notificaiton with a link.
  4. Open the link and verify the CSV downloads and opens as expected
  5. Run automated tests:
    phpunit tests/Feature/Api/CasesRetentionLogsExportTest.php

Related Tickets & Packages

ci:deploy

Code Review Checklist

  • I have pulled this code locally and tested it on my instance, along with any associated packages.
  • This code adheres to ProcessMaker Coding Guidelines.
  • This code includes a unit test or an E2E test that tests its functionality, or is covered by an existing test.
  • This solution fixes the bug reported in the original ticket.
  • This solution does not alter the expected output of a component in a way that would break existing Processes.
  • This solution does not implement any breaking changes that would invalidate documentation or cause existing Processes to fail.
  • This solution has been tested with enterprise packages that rely on its functionality and does not introduce bugs in those packages.
  • This code does not duplicate functionality that already exists in the framework or in ProcessMaker.
  • This ticket conforms to the PRD associated with this part of ProcessMaker.

Add async CSV export for case retention logs: introduces DownloadCaseRetentionLogExport job to stream query results to disk, two broadcast events (CaseRetentionLogExportReady / CaseRetentionLogExportFailed) to notify users, and controller endpoints to queue the export and serve a signed download URL. The controller uses CaseRetentionLogQueryFilter to apply the current filter when queuing and downloading; temporary signed URLs are generated with a 24-hour TTL. Frontend changes wire a button to hit the queue endpoint and session sync listeners show success/failure alerts with the download link. A feature test was added to verify job dispatch, filter propagation, and signed download streaming.
Introduce two new utilities for CaseRetention logs:

- CaseRetentionLogCsvWriter: streams a query to a writable stream as CSV (no header), prepends a UTF-8 BOM, chunks results (500 rows), JSON-encodes array case_ids when present, and normalizes date columns using a csvDateColumn helper (returns empty string for nulls, formats DateTimeInterface as 'Y-m-d H:i:s').

- CaseRetentionLogQueryFilter: provides applyIfFilled (no-op for empty input) and apply methods to filter a Builder by term across id, process_id, numeric columns, and JSON case_ids; uses driver-specific SQL (ILIKE for pg, CAST to CHAR otherwise).
@sanjacornelius sanjacornelius changed the title Task/four 29118 Implement Background CSV Export for Case Retention Logs with Async Download Mar 25, 2026
@Kookster310
Copy link
Copy Markdown
Contributor

QA server K8S was successfully deployed https://ci-0d8e061f9a.engk8s.processmaker.net

Delete two event classes: CaseRetentionLogExportReady and CaseRetentionLogExportFailed. Both implemented ShouldBroadcastNow and broadcasted export status to a PrivateChannel for a user with payload {success, message, link}. These removals clean up legacy broadcasting events related to case retention log exports.
Introduce CaseRetentionLogExportNotification and switch the export job to send database + broadcast notifications (notifyNow) with the signed download URL instead of firing events. Update notification strings in config. Adjust frontend notification handling: de-duplicate pushes, add showNavbarAlert resolver so export/download toasts include the download link, and update the Vue notification component to consider local unread counts for badge/display. Add a test to assert the export job sends a notification containing a download URL. Minor docblock tweaks in the controller.
@processmaker-sonarqube
Copy link
Copy Markdown

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube

@Kookster310
Copy link
Copy Markdown
Contributor

QA server K8S was successfully deployed https://ci-0d8e061f9a.engk8s.processmaker.net

@sanjacornelius sanjacornelius merged commit c388349 into epic/FOUR-29101 Mar 27, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants