SuiteCRM Scheduled Job for Attachment File Size Tracking
This custom SuiteCRM development project implemented a scheduled job to calculate and store the file size of attachments associated with Notes records. The goal was to help administrators and IT staff manage storage more efficiently and identify large attachments that may impact performance or backup size.
Challenge
SuiteCRM stores file attachments in the Notes module, but does not provide built-in file size tracking. For large or long-running CRM instances, these files can accumulate significantly, impacting:
- Server storage capacity
- Backup sizes and durations
- Performance and troubleshooting
Clients needed a solution to proactively manage and report on file attachment sizes within SuiteCRM.
Solution
We developed a custom scheduled job that runs at regular intervals (e.g., nightly) to inspect the file system, calculate file sizes, and store the data in a custom field (attachment_file_size_c
) on each Notes record.
✅ Features Implemented:
- Skips records where
attachment_file_size_c
is already set - Ignores Notes without an actual file attachment
- Uses PHP’s file system functions to check and store the file size
- Built-in logging for diagnostics and job success tracking
- Supports reporting and dashboards for total storage usage
Technical Highlights
- Custom Job Logic written in PHP using SuiteCRM’s job scheduler framework
- Efficient Querying: Only processes Notes records where file size is not yet set
- File Path Resolution: Accesses the correct directory and filenames for attachments
- Custom Field Update: Updates the
attachment_file_size_c
field without triggering unnecessary hooks - Compatible with large-scale SuiteCRM deployments
Impact
✅ Helped reduce overall SuiteCRM instance size through audits
✅ Improved visibility into large attachments
✅ Enabled smarter storage planning and maintenance
✅ Prepared system for future cleanup scripts or archiving processes