-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit, started working on this bundle
- Loading branch information
Benjamin
committed
Jan 10, 2017
0 parents
commit d0c00ae
Showing
15 changed files
with
1,302 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace NTI\EmailBundle\Command; | ||
|
||
use Doctrine\ORM\EntityManager; | ||
use NTI\EmailBundle\Entity\Email; | ||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class CheckCommand extends ContainerAwareCommand | ||
{ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('nti:email:check') | ||
->setDescription('Check the spool folder for changes in the email statuses') | ||
; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$spoolFolder = $this->getContainer()->getParameter('swiftmailer.spool.default.file.path'); | ||
$em = $this->getContainer()->get('doctrine')->getManager(); | ||
$emails = $em->getRepository('NTIEmailBundle:Email')->findEmailsToCheck(); | ||
|
||
if(count($emails) <= 0) { | ||
$output->writeln("No emails to check..."); | ||
return; | ||
} | ||
|
||
/** @var Email $email */ | ||
foreach($emails as $email) { | ||
|
||
// Update last check date | ||
$email->setLastCheck(new \DateTime()); | ||
|
||
// Check if it is sending | ||
if(file_exists($spoolFolder."/".$email->getFilename().".sending")) { | ||
$email->setStatus(Email::STATUS_SENDING); | ||
continue; | ||
} | ||
|
||
// Check if it failed | ||
if(file_exists($spoolFolder."/".$email->getFilename().".failure")) { | ||
// Attempt to reset it | ||
@rename($spoolFolder."/".$email->getFilename().".failure", $spoolFolder."/".$email->getFilename()); | ||
$email->setStatus(Email::STATUS_FAILURE); | ||
continue; | ||
} | ||
|
||
// Check if the file doesn't exists | ||
if(!file_exists($spoolFolder."/".$email->getFilename())) { | ||
$email->setStatus(Email::STATUS_SENT); | ||
continue; | ||
} | ||
} | ||
|
||
try { | ||
$em->flush(); | ||
if($this->getContainer()->has('nti.logger')) { | ||
$this->getContainer()->get('nti.logger')->logDebug("Finished checking ".count($emails)." emails."); | ||
} | ||
} catch (\Exception $ex) { | ||
$output->writeln("An error occurred while checking the emails.."); | ||
if($this->getContainer()->has('nti.logger')) { | ||
$this->getContainer()->get('nti.logger')->logException($ex); | ||
} | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.