2 namespace Newsletter\Service;
7 * Manage Newsletter data.
10 class Newsletter extends \Newsletter\DataBin\Newsletter
15 * ExecuteAfter: Create, Update.
16 * New newsletter created, notifications be required, probably.
18 * @param object|null $jobRecord
19 * @param object|null $record
20 * @param \Workspace\Utility\ServiceInputParams $contract
22 public function sendNewsletter($meta, $jobRecord, $record, \Workspace\Utility\ServiceInputParams $contract)
25 \Utility\Debug::errorLog('options', $contract->options);
26 $jobRecord = !is_null($jobRecord)
30 if ('Sending' == $jobRecord->jobState)
34 if ($contract->options->SaveDraft)
36 $jobRecord->jobState = 'Draft';
37 $this->em->flush($jobRecord);
39 elseif ($contract->options->TestDraft)
41 $jobRecord->jobState = 'Draft';
42 $this->em->flush($jobRecord);
43 $profileId = \Utility\Registry::getAuthParam('id');
44 exec("php /var/www/B4C2/public/index.php newsletter send "
46 . " 1 $profileId > /dev/null &");
48 elseif ($contract->options->Send)
50 $jobRecord->jobState = 'Sending';
51 $this->em->flush($jobRecord);
52 exec("php /var/www/B4C2/public/index.php newsletter send "
54 . " 0 $profileId > /dev/null &");
60 * Cron: newsletter send
62 * @param integer $jobId
63 * @param integer $test
64 * @param integer $profileId
66 public function send($jobId, $test, $profileId)
69 $jobRecord = $this->em
70 ->getRepository('\Newsletter\Entity\Newsletter')
72 if (is_null($jobRecord))
78 $oNotify = new \Utility\Comms\Notification();
79 $sentTo = $oNotify->sendNewsletter($jobRecord->id, true, $profileId);
80 $jobRecord->jobState = 'Draft';
81 $jobRecord->sentTo = is_numeric($sentTo)
87 $oNotify = new \Utility\Comms\Notification();
88 $sentTo = $oNotify->sendNewsletter($jobRecord->id, false);
89 $jobRecord->jobState = 'Sent';
90 $jobRecord->sentTo = is_numeric($sentTo)
94 $this->em->flush($jobRecord);