Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
rratsun committed Aug 3, 2022
1 parent bb34a45 commit 9646720
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
19 changes: 10 additions & 9 deletions app/Repositories/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,19 @@ public function createAsset(Entity $attachment, bool $skipValidation = false, st
$asset->set('name', $attachment->get('name'));
$asset->set('private', $this->getConfig()->get('isUploadPrivate', true));
$asset->set('fileId', $attachment->get('id'));
$asset->set('type', [$type]);

try {
if (!empty($type)) {
$asset->set('type', [$type]);
if (!$skipValidation) {
$this->getInjection(AssetValidator::class)->validate($asset);
try {
$this->getInjection(AssetValidator::class)->validate($asset);
} catch (Throwable $exception) {
$this->getEntityManager()->removeEntity($attachment);
throw $exception;
}
}
$this->getEntityManager()->saveEntity($asset);
} catch (Throwable $exception) {
$this->getEntityManager()->removeEntity($attachment);

throw $exception;
}

$this->getEntityManager()->saveEntity($asset);
}

protected function init()
Expand Down
6 changes: 5 additions & 1 deletion app/Services/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,11 @@ protected function getFileStorageManager(): Manager
*/
protected function createAsset(Entity $entity, \stdClass $attachment): void
{
if ($this->getMetadata()->get(['entityDefs', $attachment->relatedType, 'fields', $attachment->field, 'noAsset'], false)) {
if (
property_exists($attachment, 'relatedType')
&& property_exists($attachment, 'field')
&& $this->getMetadata()->get(['entityDefs', $attachment->relatedType, 'fields', $attachment->field, 'noAsset'], false)
) {
return;
}

Expand Down

0 comments on commit 9646720

Please sign in to comment.