Skip to content

Commit

Permalink
fix: trigger FileMetaData lifecycle hooks when uploading attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
TiSiE committed Aug 5, 2021
1 parent fac56bc commit 6d2a74b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions module/Applications/src/Service/UploadHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Applications\Entity\Application;
use Applications\Entity\ApplicationInterface;
use Applications\Entity\Attachment;
use Auth\Entity\AnonymousUser;
use Core\Entity\FileMetadata;
use Core\Service\FileManager;
use Core\Service\UploadedFileInfo;
Expand Down Expand Up @@ -115,15 +116,21 @@ private function doUploadFile(
$metadata->setUser($user);
$metadata->setContentType($info['type']);
$metadata->setName($info['name']);
$metadata->preventPersistingAnonymousUser();

if(!is_null($user)){
if(!is_null($user) && !$user instanceof AnonymousUser) {
$this->dm->persist($user);
}
return $fileManager->uploadFromFile(

$result = $fileManager->uploadFromFile(
Attachment::class,
$metadata,
$info['tmp_name'],
$info['name']
);

$metadata->restoreAnonymousUser();

return $result;
}
}

0 comments on commit 6d2a74b

Please sign in to comment.