Make filename unique when copying
In our scenario, we added a custom handler for submissions through Webform D9+. This is working great and to migrate all the submitted documents to CiviCRM we used CRM_Documents_Utils_File::copyFileToDocument
to transfer over. An issue arose when people started having filenames that matched previous submissions, as it basically failed to copy properly.
So after some testing I thought it would be useful to essentially use CiviCRM's makeFileName
to create a unique filename for the destination. I also discovered that the customFileUploadDir
already had a separator at the end so I basically did a check for the separator and append if one does not exist.