Attachment uploader information is missing in case attachments
Overview
The Case attachments don't have the uploader information. The created_id
is not supposed to be empty regardless of how you uploaded the attachments i.e. when creating new cases or creating/editing the related activities.
For the records, the created_id
field was added in the #11739 PR / #CRM-19948 issue, but they didn't consider the case attachments scenario.
Reproduction steps
- Click on Cases -> New Case.
- Under Attachments, upload a file and click Save.
- In the case details page, click on any activity.
- Under Attachments, upload a file and click Save.
Current behaviour
Files uploaded in steps two and four, don't have the uploader information i.e. the created_id value is empty.
Expected behaviour
Files uploaded in steps two and four should have the uploader information.
Environment information
- CiviCRM: Master/5.61.0/.../5.3.0 (since adding the created_id field/feature)
Proposed Solution
In the old #11739 PR, it uses the current logged-in $contact_id
for the created_id field when calling the method create:
/**
* BAO object for crm_log table
*/
class CRM_Core_BAO_File extends CRM_Core_DAO_File {
...
public static function create($params) {
$fileDAO = new CRM_Core_DAO_File();
...
if (empty($params['id']) && empty($params['created_id'])) {
$fileDAO->created_id = CRM_Core_Session::getLoggedInContactID();
}
For case attachments, another method is called to create the File which is filePostProcess :
public static function filePostProcess(...) {
...
$fileDAO = new CRM_Core_DAO_File();
$op = 'create';
if (isset($dao->cfID) && $dao->cfID) {
$op = 'edit';
$fileDAO->id = $dao->cfID;
unlink($directoryName . DIRECTORY_SEPARATOR . $dao->uri);
}
if (!empty($fileParams)) {
$fileDAO->copyValues($fileParams);
}
The proposed solution is to set the $created_id
inside the filePostProcess method :
$fileDAO = new CRM_Core_DAO_File();
$op = 'create';
if (isset($dao->cfID) && $dao->cfID) {
$op = 'edit';
$fileDAO->id = $dao->cfID;
unlink($directoryName . DIRECTORY_SEPARATOR . $dao->uri);
}
+ else if (empty($fileParams['created_id'])) {
+ $fileDAO->created_id = CRM_Core_Session::getLoggedInContactID();
+ }
I've created the PR https://github.com/civicrm/civicrm-core/pull/26409 to check the proposed solution.