Cleanup Notes and Attachments?

Looking for ideas of how to cleanup notes/attachments. I’ve been using SuiteCRM for a long time, it’s growing in size. Ideally, I’d like to see a list of Attachments WITH their file size and date so I can make some quick decisions about what to delete.

The list view in “Notes” is pretty good, I can see when it was created and the attachment and who it belongs to. However, there is no file size.

Any ideas on how to populate a “file size” of the attachement in the note record? This would be super helpful to clean up large old records that are no longer relevant.

Maybe you need to create a custom field into Notes and then use PHP code to update file size using logic hook. It looks complex to me.

Mostly include/upload_file.php file.

$file_size = filesize($file_path);
$bean->file_size = $file_size; 
$bean->save();

Then custom logic hook like:

custom/modules/Notes/logic_hooks.php

$hook_array['before_save'][] = Array(
    1,
    'Update File Size',
    'custom/modules/Notes/UpdateFileSize.php',
    'UpdateFileSize',
    'updateSize'
);

custom/modules/Notes/UpdateFileSize.php

<?php
class UpdateFileSize
{
    public function updateSize($bean, $event, $arguments)
    {
        if (isset($bean->filename) && !empty($bean->filename)) {
            $file_path = 'path_to_upload_directory/' . $bean->filename; 
            if (file_exists($file_path)) {
                $bean->file_size = filesize($file_path);
            }
        }
    }
}
?>
1 Like

Nice! I didn’t know you could get file size from the bean!

Better than a hook (since I already have thousands), a scheduled job would be better. I’m going to give that a try and see if it works out. I’ll post the scheduled job code here when done. Thanks!

There’s an SQL query in this post

which might be helpful for email attachments. I’m not sure if the file size is stored in that DB table, but if it is, then you can add it to the query.

Just curious! Have you made a scheduled job for this?

How did you do that? Could you please share your code/config here? :raised_hands: