Skip to content

Commit

Permalink
test failure fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
monishdeb committed Jun 8, 2021
1 parent 8633729 commit 35f5e37
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
11 changes: 9 additions & 2 deletions CRM/Core/BAO/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CRM_Core_BAO_Attachment extends CRM_Core_DAO {
*
* @param array $params
*/
public static function create($params): void {
public static function create($params): array {
$config = CRM_Core_Config::singleton();
list($id, $file, $entityFile, $name, $content, $moveFile, $isTrusted, $returnContent) = self::parseParams($params);

Expand Down Expand Up @@ -71,6 +71,11 @@ public static function create($params): void {
$entityFileDao->file_id = $fileDao->id;
$entityFileDao->save();

$attachment = array_merge($fileDao->toArray(), [
'entity_table' => $entityFileDao->entity_table,
'entity_id' => $entityFileDao->entity_id,
]);

$path = $config->customFileUploadDir . DIRECTORY_SEPARATOR . $fileDao->uri;
if (is_string($content)) {
file_put_contents($path, $content);
Expand All @@ -93,8 +98,10 @@ public static function create($params): void {
}

$result = [
$fileDao->id => self::formatResult($fileDao, $entityFileDao, $returnContent, $isTrusted),
$attachment['id'] => self::formatResult($attachment, $isTrusted, ($params['return'] ?? [])),
];

return $result;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion Civi/Api4/Service/Spec/Provider/AttachmentSpecProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public function modifySpec(RequestSpec $spec) {

if ($action == 'create') {
$spec->getFieldByName('mime_type')->setRequired(TRUE);
$spec->getFieldByName('entity_table')->setRequiredIf('empty($values.field_name)');
$spec->getFieldByName('content')->setRequiredIf('empty($values.options.move-file)');
}
if ($action == 'update') {
$spec->getFieldByName('id')->setRequired(TRUE);
Expand All @@ -49,7 +51,6 @@ public function modifySpec(RequestSpec $spec) {
else {
$spec->getFieldByName('entity_id')->setRequired(TRUE);
$spec->getFieldByName('upload_date')->setDefaultValue('now');
$spec->getFieldByName('entity_table')->setRequiredIf('empty($values.id) && empty($values.field_name)');
}
}

Expand Down
5 changes: 3 additions & 2 deletions api/v3/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ function civicrm_api3_attachment_create($params) {
// When creating we need either entity_table or field_name.
civicrm_api3_verify_one_mandatory($params, NULL, ['entity_table', 'field_name']);
}
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);;
$result = CRM_Core_BAO_Attachment::create($params);
return civicrm_api3_create_success($result, $params, 'Attachment', 'create');
}

/**
Expand All @@ -111,7 +112,7 @@ function civicrm_api3_attachment_get($params) {
$result = [];
$returnProperties = $params['return'] ?? [];
foreach ($attachments as $attachment) {
$result[$attachement['id']] = CRM_Core_BAO_Attachment::formatResult($attachment, $isTrusted, $returnProperties);
$result[$attachment['id']] = CRM_Core_BAO_Attachment::formatResult($attachment, $isTrusted, $returnProperties);
}
return civicrm_api3_create_success($result, $params, 'Attachment', 'create');
}
Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/api/v3/SyntaxConformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ public static function toBeSkipped_automock($sequential = FALSE) {
'System',
'Logging',
'Payment',
'Attachment',
];
if ($sequential === TRUE) {
return $entitiesWithoutGet;
Expand Down Expand Up @@ -562,6 +563,8 @@ public static function toBeSkipped_getlimit() {
//a bit of a pseudoapi - keys by domain
'Payment',
// pseudoapi - problems with creating required sub entities.
'Attachment',
// pseudoapi - problems with creating required sub entities.
];
return $entitiesWithout;
}
Expand Down

0 comments on commit 35f5e37

Please sign in to comment.