Merge pull request #12747 from mattwire/tabheader_extract_and_events
[civicrm-core.git] / api / v3 / Attachment.php
index 9c097038db75451c5bdd6b2a9e68dbad26cdaa13..70aa4c6a72aa0aed1504de8a792c4dd9beb1fe5e 100644 (file)
@@ -117,7 +117,8 @@ function civicrm_api3_attachment_create($params) {
   $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");
     }
@@ -144,11 +145,11 @@ function civicrm_api3_attachment_create($params) {
     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;
@@ -299,6 +300,7 @@ function __civicrm_api3_attachment_find($params, $id, $file, $entityFile, $isTru
       'cf.mime_type',
       'cf.description',
       'cf.upload_date',
+      'cf.created_id',
       'cef.entity_table',
       'cef.entity_id',
     ));
@@ -431,6 +433,7 @@ function _civicrm_api3_attachment_format_result($fileDao, $entityFileDao, $retur
     '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'],
@@ -493,6 +496,11 @@ function _civicrm_api3_attachment_getfields() {
     '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;
 }