Your IP : 216.73.217.79


Current Path : /var/www/v3.cesa.co.za/src/ContactBundle/Command/
Upload File :
Current File : /var/www/v3.cesa.co.za/src/ContactBundle/Command/MessageCommand.php

<?php

namespace App\ContactBundle\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Mailer\MailerInterface;
use App\CoreBundle\Services\ServiceGetterManager;

/**
 * Message Command
 *
 * @author Otto Saayman <otto@igotafrica.com>
 * @package ContactBundle
 * @subpackage Controller
 * @version 0.0.1
 */
class MessageCommand extends Command {

    private $serviceGetterManager;

    /**
     * Mailer Interface
     * @var object
     */
    private $mailer = null;

    public function __construct(ServiceGetterManager $serviceGetterManager, MailerInterface $mailer) {

        $this->serviceGetterManager = $serviceGetterManager;
        $this->mailer = $mailer;

        parent::__construct();
    }

    protected function configure() {
        $this
                ->setName('iga:message:send')
                ->setDescription('Send e-mails in the database')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output) {

        if (!$this->serviceGetterManager->get('batch_job.manager')->canProcessAny($output, 'message:send')) {
            return;
        }

        $_SERVER["HTTP_HOST"] = 'igotafrica.com';

        $messageManager = $this->serviceGetterManager->get('contact_message.manager');

        $mailCount = $messageManager->sendMails($this->mailer);

        $output->writeln('Sent ' . $mailCount . ' mails');

        return Command::SUCCESS;
    }
}