@@ -29,9 +29,13 @@ class Mailer {
29
29
/** @var string $devBcc */
30
30
private $ devBcc ;
31
31
32
- public function __construct (ContainerInterface $ container , Environment $ templating ) {
32
+ /** @var EntityManager */
33
+ private $ em ;
34
+
35
+ public function __construct (ContainerInterface $ container , Environment $ templating , EntityManagerInterface $ em ) {
33
36
$ this ->container = $ container ;
34
37
$ this ->templating = $ templating ;
38
+ $ this ->em = $ em ;
35
39
36
40
$ devMode = $ this ->container ->getParameter ('nti_email.dev_mode ' );
37
41
$ this ->devMode = is_array ($ devMode ) && isset ($ devMode ["enabled " ]) && $ devMode ["enabled " ] == "true " ;
@@ -130,9 +134,8 @@ public function testConfiguration(Smtp $smtp) {
130
134
*/
131
135
public function check (OutputInterface $ output = null ) {
132
136
133
- $ em = $ this ->container ->get ('doctrine ' )->getManager ();
134
137
135
- $ configurations = $ em ->getRepository (Smtp::class)->findAll ();
138
+ $ configurations = $ this -> em ->getRepository (Smtp::class)->findAll ();
136
139
137
140
/** @var Smtp $smtp */
138
141
foreach ($ configurations as $ smtp ){
@@ -174,7 +177,7 @@ public function handleSmtpSpool(Smtp $smtp, OutputInterface $output = null){
174
177
$ output ->writeln ("Sent " .$ sent ." emails with config: {$ smtp ->getUniqueId ()}. " );
175
178
176
179
// Check email statuses
177
- $ emails = $ em ->getRepository (Email::class)->findEmailsToCheckByConfigName ($ smtp ->getUniqueId ());
180
+ $ emails = $ this -> em ->getRepository (Email::class)->findEmailsToCheckByConfigName ($ smtp ->getUniqueId ());
178
181
if (count ($ emails ) <= 0 ) {
179
182
$ output ->writeln ("No emails to check with config: {$ smtp ->getUniqueId ()}.... " );
180
183
return ;
@@ -230,7 +233,7 @@ public function handleSmtpSpool(Smtp $smtp, OutputInterface $output = null){
230
233
}
231
234
}
232
235
try {
233
- $ em ->flush ();
236
+ $ this -> em ->flush ();
234
237
} catch (\Exception $ ex ) {
235
238
$ this ->container ->get ('logger ' )->log (\Monolog \Logger::CRITICAL , StringUtilities::BeautifyException ($ ex ));
236
239
}
@@ -368,7 +371,7 @@ private function processEmail($from, $to, $cc = array(), $bcc = array(), $subjec
368
371
/** @var Smtp $smtp */
369
372
$ uniqueId = (is_array ($ from ) && count ($ from ) > 0 ) ? key ($ from ) : $ from ;
370
373
if (!$ smtp ) {
371
- $ smtp = $ em ->getRepository (Smtp::class)->findOneBy (array ("uniqueId " => strtolower ($ uniqueId )));
374
+ $ smtp = $ this -> em ->getRepository (Smtp::class)->findOneBy (array ("uniqueId " => strtolower ($ uniqueId )));
372
375
}
373
376
374
377
if (!$ smtp ) {
@@ -438,8 +441,8 @@ private function processEmail($from, $to, $cc = array(), $bcc = array(), $subjec
438
441
$ email ->setStatus (Email::STATUS_FAILURE );
439
442
}
440
443
441
- $ em ->persist ($ email );
442
- $ em ->flush ();
444
+ $ this -> em ->persist ($ email );
445
+ $ this -> em ->flush ();
443
446
444
447
@unlink ($ tempSpoolPath ."/ " .$ filename );
445
448
@rmdir ($ tempSpoolPath );
0 commit comments