$entityFileDao = new CRM_Core_DAO_EntityFile();
if ($id) {
- $fileDao->id = $id;
+ $file['id'] = $fileDao->id = $id;
+
if (!$fileDao->find(TRUE)) {
throw new API_Exception("Invalid ID");
}
throw new API_Exception("Cannot modify name");
}
- $fileDao->copyValues($file);
if (!$id) {
- $fileDao->uri = CRM_Utils_File::makeFileName($name);
+ $file['uri'] = CRM_Utils_File::makeFileName($name);
}
- $fileDao->save();
+ $fileDao = CRM_Core_BAO_File::create($file);
+ $fileDao->find(TRUE);
$entityFileDao->copyValues($entityFile);
$entityFileDao->file_id = $fileDao->id;
'cf.mime_type',
'cf.description',
'cf.upload_date',
+ 'cf.created_id',
'cef.entity_table',
'cef.entity_id',
));
'entity_table' => $entityFileDao->entity_table,
'entity_id' => $entityFileDao->entity_id,
'icon' => CRM_Utils_File::getIconFromMimeType($fileDao->mime_type),
+ 'created_id' => $fileDao->created_id,
);
$result['url'] = CRM_Utils_System::url(
'civicrm/file', 'reset=1&id=' . $result['id'] . '&eid=' . $result['entity_id'],
'description' => 'File content (not searchable, not returned by default)',
'type' => CRM_Utils_Type::T_STRING,
);
+ $spec['created_id'] = array(
+ 'title' => 'Created By Contact ID',
+ 'type' => CRM_Utils_Type::T_INT,
+ 'description' => 'FK to civicrm_contact, who uploaded this file',
+ );
return $spec;
}