Skip to content

Commit 6ff67b4

Browse files
author
Ivan Matyunin
committed
Updated SendEmailCommand to match the new mailing system
1 parent e732a7b commit 6ff67b4

File tree

1 file changed

+13
-64
lines changed

1 file changed

+13
-64
lines changed

src/Symfony/Bundle/SwiftmailerBundle/Command/SendEmailCommand.php

Lines changed: 13 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Console\Input\InputOption;
1818

1919
use Symfony\Component\Console\Input\InputArgument;
20+
use Zenith\POSBundle\Services\ZenithMailer;
2021

2122
/**
2223
* Send Emails from the spool.
@@ -58,10 +59,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
5859
$storeId = $input->getArgument('storeId');
5960
$doctrine = $this->getContainer()->get('doctrine');
6061
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
61-
62+
$store = null;
63+
6264
if (!is_numeric($storeId))
6365
{
64-
$output->writeln("ERROR: Store ID must be an integer.");
66+
$output->writeln("ERROR: Store ID must be an integer. (0 == corporate)");
6567
$output->writeln("Function now terminates...");
6668
exit();
6769
}
@@ -70,74 +72,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
7072
//Getting store
7173
$store = $doctrine->getRepository('ZenithSalonEntityBundle:Store')->findOneById($storeId);
7274

73-
if ($store == null)
75+
if ($store == null && $storeId != 0)
7476
{
7577
$output->writeln("ERROR: Store with given ID Does Not Exist.");
7678
$output->writeln("Function now terminates...");
7779
exit();
7880
}
7981
}
80-
81-
//Getting Store setting
82-
$settingDQL = "SELECT s FROM ZenithSalonEntityBundle:Setting s " .
83-
" JOIN s.store store " .
84-
" WHERE store.id = :storeId AND s.isDeleted = FALSE " .
85-
" AND (s.settingName = 'PromSMTP' OR s.settingName = 'PromEmail' OR s.settingName = 'PromPassword' OR s.settingName = 'PromEmailAuthType')";
86-
87-
$settings = $em->createQuery($settingDQL)->setParameter(//array(
88-
'storeId', $store->getId()
89-
)->getResult();
90-
91-
$storeEmail = null;
92-
$storeEmailPass = null;
93-
$encrypt = null;
94-
$storeSMTP = null;
95-
96-
foreach ($settings as $setting)
97-
{
98-
switch ($setting->getSettingName())
99-
{
100-
case 'PromSMTP':
101-
$storeSMTP = $setting->getStringValue();
102-
break;
103-
case 'PromEmail': //full email
104-
$storeEmail = $setting->getStringValue();
105-
break;
106-
case 'PromPassword':
107-
$storeEmailPass = $setting->getStringValue();
108-
break;
109-
case "PromEmailAuthType":
110-
$encrypt = strtolower($setting->getStringValue());
111-
break;
112-
default:
113-
break;
114-
}
115-
}
116-
117-
if ($storeEmail == null || $storeSMTP == null || $storeEmailPass == null)
118-
{
119-
$output->writeln("ERROR: Mailing System Has NOT Been Set Up Yet.");
120-
$output->writeln("Function now terminates ...");
121-
exit();
122-
}
123-
124-
$spoolPath = "web/spool/" . $storeEmail; //This MUST be the same as the one specified in the MailSpooler class!
82+
83+
$store_suffix = ($store == null) ? 'corp' : $store->getId();
84+
85+
$spoolPath = "web/spool/store_" . $store_suffix; //This MUST be the same as the one specified in the MailSpooler class!
12586

126-
//Creating transport
127-
if ($encrypt)
128-
{
129-
$transport = \Swift_SmtpTransport::newInstance($storeSMTP)
130-
->setUsername($storeEmail)
131-
->setPassword($storeEmailPass)
132-
->setEncryption($encrypt);
133-
}
134-
else
135-
{
136-
$transport = \Swift_SmtpTransport::newInstance($storeSMTP)
137-
->setUsername($storeEmail)
138-
->setPassword($storeEmailPass);
139-
}
140-
14187
$spool = new \Swift_FileSpool($spoolPath);
14288

14389
//Setting max # of msgs sent and time limit
@@ -146,8 +92,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
14692
$spool->setMessageLimit($input->getOption('message-limit'));
14793
$spool->setTimeLimit($input->getOption('time-limit'));
14894
}
95+
96+
$zenithMailer = $this->getContainer()->get('zenith_mailer');
97+
$mailer = $zenithMailer->getMailer(ZenithMailer::TransportImmediate, $store);
14998

150-
$sent = $spool->flushQueue($transport);
99+
$sent = $spool->flushQueue($mailer->getTransport());
151100
$output->writeln(sprintf('sent %s emails', $sent));
152101
}
153102
}

0 commit comments

Comments
 (0)