Code Duplication    Length = 51-52 lines in 2 locations

Command/SendNewsLetterCommand.php 1 location

@@ 13-63 (lines=51) @@
10
 * Send Newsletter via email
11
 * @author dominik
12
 */
13
class SendNewsLetterCommand extends ContainerAwareCommand
14
{
15
    /**
16
     * (non-PHPdoc)
17
     * @see Symfony\Component\Console\Command.Command::configure()
18
     */
19
    protected function configure()
20
    {
21
        $this	->setName('emails:sendNewsletter')
22
                ->setDescription('Send Newsletter via email to all subscribers.')
23
                ->setHelp(<<<EOF
24
The <info>emails:sendNewsletter</info> command sends the newsletter email to all recipients who
25
indicate that they would like to recieve the newsletter (see Azine\EmailBundle\Entity\RecipientInterface.getNewsletter).
26
27
Depending on you Swiftmailer-Configuration the email will be send directly or will be written to the spool.
28
29
If you configured Swiftmailer to spool email, then you need to run the <info>swiftmailer:spool:send</info>
30
command to actually send the emails from the spool.
31
32
EOF
33
                )
34
        ;
35
    }
36
37
    /**
38
     * (non-PHPdoc)
39
     * @see Symfony\Component\Console\Command.Command::execute()
40
     */
41
    protected function execute(InputInterface $input, OutputInterface $output)
42
    {
43
        // create the lock
44
        $lock = new LockHandler($this->getName());
45
        if (!$lock->lock()) {
46
            $output->writeln('The command is already running in another process.');
47
            return 0;
48
        }
49
50
        $failedAddresses = array();
51
        $output->writeln(date(\DateTime::RFC2822)." : starting to send newsletter emails.");
52
53
        $sentMails = $this->getContainer()->get('azine_email_notifier_service')->sendNewsletter($failedAddresses);
54
55
        $output->writeln(date(\DateTime::RFC2822)." : ".str_pad($sentMails, 4, " ", STR_PAD_LEFT)." newsletter emails have been sent.");
56
        if (sizeof($failedAddresses) > 0) {
57
            $output->writeln(date(\DateTime::RFC2822)." : "."The following email-addresses failed:");
58
            foreach ($failedAddresses as $address) {
59
                $output->writeln("       ".$address);
60
            }
61
        }
62
    }
63
}
64

Command/SendNotificationsCommand.php 1 location

@@ 13-64 (lines=52) @@
10
 * Aggregate and send pending notifications or newsletters via email
11
 * @author dominik
12
 */
13
class SendNotificationsCommand extends ContainerAwareCommand
14
{
15
    /**
16
     * (non-PHPdoc)
17
     * @see Symfony\Component\Console\Command.Command::configure()
18
     */
19
    protected function configure()
20
    {
21
        $this	->setName('emails:sendNotifications')
22
                ->setDescription('Aggregate and send pending notifications via email.')
23
                ->setHelp(<<<EOF
24
The <info>emails:sendNotifications</info> command sends emails for all pending notifications.
25
26
Depending on you Swiftmailer-Configuration the email will be send directly or will be written to the spool.
27
28
If you configured Swiftmailer to spool email, then you need to run the <info>swiftmailer:spool:send</info>
29
command to actually send the emails from the spool.
30
31
EOF
32
            )
33
        ;
34
    }
35
36
    /**
37
     * (non-PHPdoc)
38
     * @see Symfony\Component\Console\Command.Command::execute()
39
     */
40
    protected function execute(InputInterface $input, OutputInterface $output)
41
    {
42
        // create the lock
43
        $lock = new LockHandler($this->getName());
44
        if (!$lock->lock()) {
45
            $output->writeln('The command is already running in another process.');
46
47
            return 0;
48
        }
49
50
        $failedAddresses = array();
51
        $sentMails = $this->getContainer()->get('azine_email_notifier_service')->sendNotifications($failedAddresses);
52
53
        $output->writeln(date(\DateTime::RFC2822)." : ".str_pad($sentMails, 4, " ", STR_PAD_LEFT)." emails have been processed.");
54
        if (sizeof($failedAddresses) > 0) {
55
            $output->writeln(date(\DateTime::RFC2822)." : "."The following email-addresses failed:");
56
            foreach ($failedAddresses as $address) {
57
                $output->writeln("    ".$address);
58
            }
59
        }
60
61
        // (optional) release the lock (otherwise, PHP will do it for you automatically)
62
        $lock->release();
63
    }
64
}
65