Skip to content

Commit

Permalink
set default created_id value to BAO
Browse files Browse the repository at this point in the history
  • Loading branch information
monishdeb committed Apr 28, 2018
1 parent bcf4cfb commit f1fd7c0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
21 changes: 21 additions & 0 deletions CRM/Core/BAO/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ class CRM_Core_BAO_File extends CRM_Core_DAO_File {

static $_signableFields = array('entityTable', 'entityID', 'fileID');

/**
* Takes an associative array and creates a File object.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
*
* @return CRM_Core_BAO_File
*/
public static function create($params) {
$fileDAO = new CRM_Core_DAO_File();
$fileDAO->copyValues($params);

if (empty($params['id']) && empty($params['created_id'])) {
$fileDAO->created_id = CRM_Core_Session::getLoggedInContactID();
}

$fileDAO->save();

return $fileDAO;
}

/**
* @param int $fileID
* @param int $entityID
Expand Down
4 changes: 2 additions & 2 deletions CRM/Upgrade/Incremental/php/FiveTwo.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public static function addFileCreatedIdColumn(CRM_Queue_TaskContext $ctx) {
ON UPDATE CASCADE;
");

return TRUE;
}
return TRUE;
}

/*
* Important! All upgrade functions MUST add a 'runSql' task.
Expand Down
10 changes: 5 additions & 5 deletions api/v3/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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;
Expand Down Expand Up @@ -499,7 +500,6 @@ function _civicrm_api3_attachment_getfields() {
'title' => 'Created By Contact ID',
'type' => CRM_Utils_Type::T_INT,
'description' => 'FK to civicrm_contact, who uploaded this file',
'api.default' => 'user_contact_id',
);

return $spec;
Expand Down

0 comments on commit f1fd7c0

Please sign in to comment.