Zenc_EmailLogger_Model_Email_Queue   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 47
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 14 3
A _logQueue() 0 17 2
1
<?php
2
3
/**
4
 * Extend email queue functionality with logging capability
5
 */
6
class Zenc_EmailLogger_Model_Email_Queue extends Mage_Core_Model_Email_Queue
7
{
8
    /**
9
     * Send all messages in a queue
10
     *
11
     * Log messages instead of sending if email logging is enabled
12
     *
13
     * @return Mage_Core_Model_Email_Queue
14
     */
15
    public function send()
16
    {
17
        if (!Mage::helper('zenc_emaillogger')->isEnabled()) {
18
            return parent::send();
19
        }
20
21
        $this->_logQueue();
22
23
        if (Mage::helper('zenc_emaillogger')->isPassthruEnabled()) {
24
            return parent::send();
25
        }
26
27
        return $this;
28
    }
29
30
    /**
31
     * Log queued emails and mark them as processed
32
     *
33
     * @throws Exception Thrown when unable to save message
34
     */
35
    private function _logQueue()
36
    {
37
        /** @var $collection Mage_Core_Model_Resource_Email_Queue_Collection */
38
        $collection = Mage::getModel('core/email_queue')->getCollection()
39
            ->addOnlyForSendingFilter()
40
            ->setPageSize(self::MESSAGES_LIMIT_PER_CRON_RUN)
41
            ->setCurPage(1)
42
            ->load();
43
44
        $logger = Mage::getModel('zenc_emaillogger/email_queue_logger');
45
        foreach ($collection as $message) {
46
            $logger->save($message);
0 ignored issues
show
Performance introduced by
Model LSD method save() detected in loop
Loading history...
47
48
            $message->setProcessedAt(Varien_Date::formatDate(true));
49
            $message->save();
0 ignored issues
show
Performance introduced by
Model LSD method save() detected in loop
Loading history...
50
        }
51
    }
52
}
53