Skip to content
This repository was archived by the owner on Jul 25, 2023. It is now read-only.

Commit 0aa407d

Browse files
authored
Merge pull request #6 from Charlie-Lucas/master
🐛 remove attachment uploader service doctrine dependency
2 parents 8438102 + 8578a0f commit 0aa407d

3 files changed

Lines changed: 11 additions & 13 deletions

File tree

EventListener/AttachmentUploadListener.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use AppVentus\Awesome\SpoolMailerBundle\Entity\Attachment;
66
use AppVentus\Awesome\SpoolMailerBundle\Utils\AttachmentUploader;
7+
use Doctrine\ORM\EntityManager;
78
use Doctrine\ORM\Event\LifecycleEventArgs;
89
use Doctrine\ORM\Event\PreUpdateEventArgs;
910

@@ -33,7 +34,7 @@ public function prePersist(LifecycleEventArgs $args)
3334
{
3435
$entity = $args->getEntity();
3536

36-
$this->uploadFile($entity);
37+
$this->uploadFile($entity, $args->getEntityManager());
3738
}
3839

3940
/**
@@ -43,19 +44,20 @@ public function preUpdate(PreUpdateEventArgs $args)
4344
{
4445
$entity = $args->getEntity();
4546

46-
$this->uploadFile($entity);
47+
$this->uploadFile($entity, $args->getEntityManager());
4748
}
4849

4950
/**
5051
* @param $entity
52+
* @param EntityManager $em
5153
*/
52-
private function uploadFile($entity)
54+
private function uploadFile($entity, EntityManager $em)
5355
{
5456
if (!$entity instanceof Attachment) {
5557
return;
5658
}
5759

58-
$this->uploader->upload($entity);
60+
$this->uploader->upload($entity, $em);
5961
}
6062

6163
/**

Resources/config/services.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ services:
2929
arguments:
3030
- '%spool_mailer.attachments_directory%'
3131
- '%kernel.root_dir%'
32-
- '@doctrine'
3332

3433
spool.doctrine_attachment_listener:
3534
class: AppVentus\Awesome\SpoolMailerBundle\EventListener\AttachmentUploadListener

Utils/AttachmentUploader.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
namespace AppVentus\Awesome\SpoolMailerBundle\Utils;
33

44
use AppVentus\Awesome\SpoolMailerBundle\Entity\Attachment;
5-
use Doctrine\Bundle\DoctrineBundle\Registry as DoctrineRegistry;
5+
use Doctrine\ORM\EntityManager;
66
use Gedmo\Exception\UploadableDirectoryNotFoundException;
7-
use Swift_FileStream;
87

98
/**
109
* Class AttachmentUploader
@@ -15,31 +14,29 @@ class AttachmentUploader {
1514

1615
private $targetDir;
1716
private $rootDir;
18-
private $em;
1917

2018
/**
2119
* AttachmentUploader constructor.
2220
*
2321
* @param $targetDir
2422
* @param $rootDir
25-
* @param \Doctrine\Bundle\DoctrineBundle\Registry $registry
2623
*/
27-
public function __construct($targetDir, $rootDir, DoctrineRegistry $registry)
24+
public function __construct($targetDir, $rootDir)
2825
{
2926
$this->targetDir = $targetDir;
3027
$this->rootDir = $rootDir;
31-
$this->em = $registry->getManager();
3228
}
3329

3430
/**
3531
* @param \AppVentus\Awesome\SpoolMailerBundle\Entity\Attachment $attachment
32+
* @param EntityManager $em
3633
*/
37-
public function upload(Attachment $attachment)
34+
public function upload(Attachment $attachment, EntityManager $em)
3835
{
3936
if ($swiftAttachment = $attachment->getSwiftAttachment())
4037
{
4138
/** @var Attachment $duplicatedAttachment */
42-
$duplicatedAttachment = $this->em->getRepository(Attachment::class)->findOneBy(['swiftAttachmentId' => $attachment->getSwiftAttachmentId()]);
39+
$duplicatedAttachment = $em->getRepository(Attachment::class)->findOneBy(['swiftAttachmentId' => $attachment->getSwiftAttachmentId()]);
4340
if (!$duplicatedAttachment)
4441
{
4542
$fileName = md5(uniqid('', true)).'_'.$swiftAttachment->getFilename();

0 commit comments

Comments
 (0)