Current file: htdocs/app/code/core/Mage/Newsletter/Model/Template.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
0.00%0.00%
0.00% 0 / 1
6.25%6.25%
6.25% 1 / 16 CRAP
2.38%2.38%
2.38% 3 / 126
 
Mage_Newsletter_Model_Template
0.00%0.00%
0.00% 0 / 1
6.25%6.25%
6.25% 1 / 16
2.38%2.38%
2.38% 3 / 126
 _construct()
100.00%100.00%
100.00% 1 / 1 1
100.00%100.00%
100.00% 2 / 2
 validate()
0.00%0.00%
0.00% 0 / 1 42
0.00%0.00%
0.00% 0 / 23
 _beforeSave()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 2
 loadByCode($templateCode)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 2
 isValidForSend()
0.00%0.00%
0.00% 0 / 1 20
0.00%0.00%
0.00% 0 / 4
 getType()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 isPreprocessed()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 getTemplateTextPreprocessed()
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 4
 getProcessedTemplate(array $variables = array()
0.00%0.00%
0.00% 0 / 1 30
0.00%0.00%
0.00% 0 / 13
 getPreparedTemplateText($usePreprocess = false)
0.00%0.00%
0.00% 0 / 1 30
0.00%0.00%
0.00% 0 / 5
 getInclude($templateCode, array $variables)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 3
 getMail()
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 4
 send($subscriber, array $variables = array()
0.00%0.00%
0.00% 0 / 1 182
0.00%0.00%
0.00% 0 / 45
 preprocess()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 4
 getProcessedTemplateSubject(array $variables)
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 6
 getTemplateText()
0.00%0.00%
0.00% 0 / 1 12
0.00%0.00%
0.00% 0 / 6


       1                 : <?php                                                                                                                                                                                                                          
       2                 : /**                                                                                                                                                                                                                            
       3                 :  * Magento                                                                                                                                                                                                                     
       4                 :  *                                                                                                                                                                                                                             
       5                 :  * NOTICE OF LICENSE                                                                                                                                                                                                           
       6                 :  *                                                                                                                                                                                                                             
       7                 :  * This source file is subject to the Open Software License (OSL 3.0)                                                                                                                                                          
       8                 :  * that is bundled with this package in the file LICENSE.txt.                                                                                                                                                                  
       9                 :  * It is also available through the world-wide-web at this URL:                                                                                                                                                                
      10                 :  * http://opensource.org/licenses/osl-3.0.php                                                                                                                                                                                  
      11                 :  * If you did not receive a copy of the license and are unable to                                                                                                                                                              
      12                 :  * obtain it through the world-wide-web, please send an email                                                                                                                                                                  
      13                 :  * to license@magentocommerce.com so we can send you a copy immediately.                                                                                                                                                       
      14                 :  *                                                                                                                                                                                                                             
      15                 :  * DISCLAIMER                                                                                                                                                                                                                  
      16                 :  *                                                                                                                                                                                                                             
      17                 :  * Do not edit or add to this file if you wish to upgrade Magento to newer                                                                                                                                                     
      18                 :  * versions in the future. If you wish to customize Magento for your                                                                                                                                                           
      19                 :  * needs please refer to http://www.magentocommerce.com for more information.                                                                                                                                                  
      20                 :  *                                                                                                                                                                                                                             
      21                 :  * @category    Mage                                                                                                                                                                                                           
      22                 :  * @package     Mage_Newsletter                                                                                                                                                                                                
      23                 :  * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)                                                                                                                                               
      24                 :  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)                                                                                                                                    
      25                 :  */                                                                                                                                                                                                                            
      26                 :                                                                                                                                                                                                                                
      27                 : /**                                                                                                                                                                                                                            
      28                 :  * Template model                                                                                                                                                                                                              
      29                 :  *                                                                                                                                                                                                                             
      30                 :  * @category   Mage                                                                                                                                                                                                            
      31                 :  * @package    Mage_Newsletter                                                                                                                                                                                                 
      32                 :  * @author      Magento Core Team <core@magentocommerce.com>                                                                                                                                                                   
      33                 :  */                                                                                                                                                                                                                            
      34                 : class Mage_Newsletter_Model_Template extends Mage_Core_Model_Template                                                                                                                                                          
      35               1 : {                                                                                                                                                                                                                              
      36                 :     /**                                                                                                                                                                                                                        
      37                 :      * Template Text Preprocessed flag                                                                                                                                                                                         
      38                 :      *                                                                                                                                                                                                                         
      39                 :      * @var bool                                                                                                                                                                                                               
      40                 :      */                                                                                                                                                                                                                        
      41                 :     protected $_preprocessFlag = false;                                                                                                                                                                                        
      42                 :                                                                                                                                                                                                                                
      43                 :     /**                                                                                                                                                                                                                        
      44                 :      * Mail object                                                                                                                                                                                                             
      45                 :      *                                                                                                                                                                                                                         
      46                 :      * @var Zend_Mail                                                                                                                                                                                                          
      47                 :      */                                                                                                                                                                                                                        
      48                 :     protected $_mail;                                                                                                                                                                                                          
      49                 :                                                                                                                                                                                                                                
      50                 :     /**                                                                                                                                                                                                                        
      51                 :      * Initialize resource model                                                                                                                                                                                               
      52                 :      *                                                                                                                                                                                                                         
      53                 :      */                                                                                                                                                                                                                        
      54                 :     protected function _construct()                                                                                                                                                                                            
      55                 :     {                                                                                                                                                                                                                          
      56               1 :         $this->_init('newsletter/template');                                                                                                                                                                                   
      57               1 :     }                                                                                                                                                                                                                          
      58                 :                                                                                                                                                                                                                                
      59                 :     /**                                                                                                                                                                                                                        
      60                 :      * Validate Newsletter template                                                                                                                                                                                            
      61                 :      *                                                                                                                                                                                                                         
      62                 :      * @throws Mage_Core_Exception                                                                                                                                                                                             
      63                 :      * @return bool                                                                                                                                                                                                            
      64                 :      */                                                                                                                                                                                                                        
      65                 :     public function validate()                                                                                                                                                                                                 
      66                 :     {                                                                                                                                                                                                                          
      67                 :         $validators = array(                                                                                                                                                                                                   
      68               0 :             'template_code'         => array(Zend_Filter_Input::ALLOW_EMPTY => false),                                                                                                                                         
      69               0 :             'template_type'         => 'Int',                                                                                                                                                                                  
      70               0 :             'template_sender_email' => 'EmailAddress',                                                                                                                                                                         
      71               0 :             'template_sender_name'  => array(Zend_Filter_Input::ALLOW_EMPTY => false)                                                                                                                                          
      72               0 :         );                                                                                                                                                                                                                     
      73               0 :         $data = array();                                                                                                                                                                                                       
      74               0 :         foreach (array_keys($validators) as $validateField) {                                                                                                                                                                  
      75               0 :             $data[$validateField] = $this->getDataUsingMethod($validateField);                                                                                                                                                 
      76               0 :         }                                                                                                                                                                                                                      
      77                 :                                                                                                                                                                                                                                
      78               0 :         $validateInput = new Zend_Filter_Input(array(), $validators, $data);                                                                                                                                                   
      79               0 :         if (!$validateInput->isValid()) {                                                                                                                                                                                      
      80               0 :             $errorMessages = array();                                                                                                                                                                                          
      81               0 :             foreach ($validateInput->getMessages() as $messages) {                                                                                                                                                             
      82               0 :                 if (is_array($messages)) {                                                                                                                                                                                     
      83               0 :                     foreach ($messages as $message) {                                                                                                                                                                          
      84               0 :                         $errorMessages[] = $message;                                                                                                                                                                           
      85               0 :                     }                                                                                                                                                                                                          
      86               0 :                 }                                                                                                                                                                                                              
      87                 :                 else {                                                                                                                                                                                                         
      88               0 :                     $errorMessages[] = $messages;                                                                                                                                                                              
      89                 :                 }                                                                                                                                                                                                              
      90               0 :             }                                                                                                                                                                                                                  
      91                 :                                                                                                                                                                                                                                
      92               0 :             Mage::throwException(join("\n", $errorMessages));                                                                                                                                                                  
      93               0 :         }                                                                                                                                                                                                                      
      94               0 :     }                                                                                                                                                                                                                          
      95                 :                                                                                                                                                                                                                                
      96                 :     /**                                                                                                                                                                                                                        
      97                 :      * Processing object before save data                                                                                                                                                                                      
      98                 :      *                                                                                                                                                                                                                         
      99                 :      * @return Mage_Newsletter_Model_Template                                                                                                                                                                                  
     100                 :      */                                                                                                                                                                                                                        
     101                 :     protected function _beforeSave()                                                                                                                                                                                           
     102                 :     {                                                                                                                                                                                                                          
     103               0 :         $this->validate();                                                                                                                                                                                                     
     104               0 :         return parent::_beforeSave();                                                                                                                                                                                          
     105                 :     }                                                                                                                                                                                                                          
     106                 :                                                                                                                                                                                                                                
     107                 :     /**                                                                                                                                                                                                                        
     108                 :      * Load template by code                                                                                                                                                                                                   
     109                 :      *                                                                                                                                                                                                                         
     110                 :      * @param string $templateCode                                                                                                                                                                                             
     111                 :      * @return Mage_Newsletter_Model_Template                                                                                                                                                                                  
     112                 :      */                                                                                                                                                                                                                        
     113                 :     public function loadByCode($templateCode)                                                                                                                                                                                  
     114                 :     {                                                                                                                                                                                                                          
     115               0 :         $this->_getResource()->loadByCode($this, $templateCode);                                                                                                                                                               
     116               0 :         return $this;                                                                                                                                                                                                          
     117                 :     }                                                                                                                                                                                                                          
     118                 :                                                                                                                                                                                                                                
     119                 :     /**                                                                                                                                                                                                                        
     120                 :      * Return true if this template can be used for sending queue as main template                                                                                                                                             
     121                 :      *                                                                                                                                                                                                                         
     122                 :      * @return boolean                                                                                                                                                                                                         
     123                 :      * @deprecated since 1.4.0.1                                                                                                                                                                                               
     124                 :      */                                                                                                                                                                                                                        
     125                 :     public function isValidForSend()                                                                                                                                                                                           
     126                 :     {                                                                                                                                                                                                                          
     127               0 :         return !Mage::getStoreConfigFlag('system/smtp/disable')                                                                                                                                                                
     128               0 :             && $this->getTemplateSenderName()                                                                                                                                                                                  
     129               0 :             && $this->getTemplateSenderEmail()                                                                                                                                                                                 
     130               0 :             && $this->getTemplateSubject();                                                                                                                                                                                    
     131                 :     }                                                                                                                                                                                                                          
     132                 :                                                                                                                                                                                                                                
     133                 :     /**                                                                                                                                                                                                                        
     134                 :      * Getter for template type                                                                                                                                                                                                
     135                 :      *                                                                                                                                                                                                                         
     136                 :      * @return int|string                                                                                                                                                                                                      
     137                 :      */                                                                                                                                                                                                                        
     138                 :     public function getType(){                                                                                                                                                                                                 
     139               0 :         return $this->getTemplateType();                                                                                                                                                                                       
     140                 :     }                                                                                                                                                                                                                          
     141                 :                                                                                                                                                                                                                                
     142                 :     /**                                                                                                                                                                                                                        
     143                 :      * Check is Preprocessed                                                                                                                                                                                                   
     144                 :      *                                                                                                                                                                                                                         
     145                 :      * @return bool                                                                                                                                                                                                            
     146                 :      */                                                                                                                                                                                                                        
     147                 :     public function isPreprocessed()                                                                                                                                                                                           
     148                 :     {                                                                                                                                                                                                                          
     149               0 :         return strlen($this->getTemplateTextPreprocessed()) > 0;                                                                                                                                                               
     150                 :     }                                                                                                                                                                                                                          
     151                 :                                                                                                                                                                                                                                
     152                 :     /**                                                                                                                                                                                                                        
     153                 :      * Check Template Text Preprocessed                                                                                                                                                                                        
     154                 :      *                                                                                                                                                                                                                         
     155                 :      * @return bool                                                                                                                                                                                                            
     156                 :      */                                                                                                                                                                                                                        
     157                 :     public function getTemplateTextPreprocessed()                                                                                                                                                                              
     158                 :     {                                                                                                                                                                                                                          
     159               0 :         if ($this->_preprocessFlag) {                                                                                                                                                                                          
     160               0 :             $this->setTemplateTextPreprocessed($this->getProcessedTemplate());                                                                                                                                                 
     161               0 :         }                                                                                                                                                                                                                      
     162                 :                                                                                                                                                                                                                                
     163               0 :         return $this->getData('template_text_preprocessed');                                                                                                                                                                   
     164                 :     }                                                                                                                                                                                                                          
     165                 :                                                                                                                                                                                                                                
     166                 :     /**                                                                                                                                                                                                                        
     167                 :      * Retrieve processed template                                                                                                                                                                                             
     168                 :      *                                                                                                                                                                                                                         
     169                 :      * @param array $variables                                                                                                                                                                                                 
     170                 :      * @param bool $usePreprocess                                                                                                                                                                                              
     171                 :      * @return string                                                                                                                                                                                                          
     172                 :      */                                                                                                                                                                                                                        
     173                 :     public function getProcessedTemplate(array $variables = array(), $usePreprocess = false)                                                                                                                                   
     174                 :     {                                                                                                                                                                                                                          
     175                 :         /* @var $processor Mage_Newsletter_Model_Template_Filter */                                                                                                                                                            
     176               0 :         $processor = Mage::helper('newsletter')->getTemplateProcessor();                                                                                                                                                       
     177                 :                                                                                                                                                                                                                                
     178               0 :         if (!$this->_preprocessFlag) {                                                                                                                                                                                         
     179               0 :             $variables['this'] = $this;                                                                                                                                                                                        
     180               0 :         }                                                                                                                                                                                                                      
     181                 :                                                                                                                                                                                                                                
     182               0 :         if (Mage::app()->isSingleStoreMode()) {                                                                                                                                                                                
     183               0 :             $processor->setStoreId(Mage::app()->getStore());                                                                                                                                                                   
     184               0 :         } else {                                                                                                                                                                                                               
     185               0 :             $processor->setStoreId(Mage::app()->getRequest()->getParam('store_id'));                                                                                                                                           
     186                 :         }                                                                                                                                                                                                                      
     187                 :                                                                                                                                                                                                                                
     188                 :         $processor                                                                                                                                                                                                             
     189               0 :             ->setIncludeProcessor(array($this, 'getInclude'))                                                                                                                                                                  
     190               0 :             ->setVariables($variables);                                                                                                                                                                                        
     191                 :                                                                                                                                                                                                                                
     192               0 :         if ($usePreprocess && $this->isPreprocessed()) {                                                                                                                                                                       
     193               0 :             return $processor->filter($this->getPreparedTemplateText(true));                                                                                                                                                   
     194                 :         }                                                                                                                                                                                                                      
     195                 :                                                                                                                                                                                                                                
     196               0 :         return $processor->filter($this->getPreparedTemplateText());                                                                                                                                                           
     197                 :     }                                                                                                                                                                                                                          
     198                 :                                                                                                                                                                                                                                
     199                 :     /**                                                                                                                                                                                                                        
     200                 :      * Makes additional text preparations for HTML templates                                                                                                                                                                   
     201                 :      *                                                                                                                                                                                                                         
     202                 :      * @param bool $usePreprocess Use Preprocessed text or original text                                                                                                                                                       
     203                 :      * @return string                                                                                                                                                                                                          
     204                 :      */                                                                                                                                                                                                                        
     205                 :     public function getPreparedTemplateText($usePreprocess = false)                                                                                                                                                            
     206                 :     {                                                                                                                                                                                                                          
     207               0 :         $text = $usePreprocess ? $this->getTemplateTextPreprocessed() : $this->getTemplateText();                                                                                                                              
     208                 :                                                                                                                                                                                                                                
     209               0 :         if ($this->_preprocessFlag || $this->isPlain() || !$this->getTemplateStyles()) {                                                                                                                                       
     210               0 :             return $text;                                                                                                                                                                                                      
     211                 :         }                                                                                                                                                                                                                      
     212                 :         // wrap styles into style tag                                                                                                                                                                                          
     213               0 :         $html = "<style type=\"text/css\">\n%s\n</style>\n%s";                                                                                                                                                                 
     214               0 :         return sprintf($html, $this->getTemplateStyles(), $text);                                                                                                                                                              
     215                 :     }                                                                                                                                                                                                                          
     216                 :                                                                                                                                                                                                                                
     217                 :     /**                                                                                                                                                                                                                        
     218                 :      * Retrieve included template                                                                                                                                                                                              
     219                 :      *                                                                                                                                                                                                                         
     220                 :      * @param string $templateCode                                                                                                                                                                                             
     221                 :      * @param array $variables                                                                                                                                                                                                 
     222                 :      * @return string                                                                                                                                                                                                          
     223                 :      */                                                                                                                                                                                                                        
     224                 :     public function getInclude($templateCode, array $variables)                                                                                                                                                                
     225                 :     {                                                                                                                                                                                                                          
     226               0 :         return Mage::getModel('newsletter/template')                                                                                                                                                                           
     227               0 :             ->loadByCode($templateCode)                                                                                                                                                                                        
     228               0 :             ->getProcessedTemplate($variables);                                                                                                                                                                                
     229                 :     }                                                                                                                                                                                                                          
     230                 :                                                                                                                                                                                                                                
     231                 :     /**                                                                                                                                                                                                                        
     232                 :      * Retrieve mail object instance                                                                                                                                                                                           
     233                 :      *                                                                                                                                                                                                                         
     234                 :      * @return Zend_Mail                                                                                                                                                                                                       
     235                 :      * @deprecated since 1.4.0.1                                                                                                                                                                                               
     236                 :      */                                                                                                                                                                                                                        
     237                 :     public function getMail()                                                                                                                                                                                                  
     238                 :     {                                                                                                                                                                                                                          
     239               0 :         if (is_null($this->_mail)) {                                                                                                                                                                                           
     240               0 :             $this->_mail = new Zend_Mail('utf-8');                                                                                                                                                                             
     241               0 :         }                                                                                                                                                                                                                      
     242               0 :         return $this->_mail;                                                                                                                                                                                                   
     243                 :     }                                                                                                                                                                                                                          
     244                 :                                                                                                                                                                                                                                
     245                 :                                                                                                                                                                                                                                
     246                 :     /**                                                                                                                                                                                                                        
     247                 :      * Send mail to subscriber                                                                                                                                                                                                 
     248                 :      *                                                                                                                                                                                                                         
     249                 :      * @param   Mage_Newsletter_Model_Subscriber|string   $subscriber   subscriber Model or E-mail                                                                                                                             
     250                 :      * @param   array                                     $variables    template variables                                                                                                                                     
     251                 :      * @param   string|null                               $name         receiver name (if subscriber model not specified)                                                                                                      
     252                 :      * @param   Mage_Newsletter_Model_Queue|null          $queue        queue model, used for problems reporting.                                                                                                              
     253                 :      * @return boolean                                                                                                                                                                                                         
     254                 :      * @deprecated since 1.4.0.1                                                                                                                                                                                               
     255                 :      **/                                                                                                                                                                                                                       
     256                 :     public function send($subscriber, array $variables = array(), $name=null, Mage_Newsletter_Model_Queue $queue=null)                                                                                                         
     257                 :     {                                                                                                                                                                                                                          
     258               0 :         if (!$this->isValidForSend()) {                                                                                                                                                                                        
     259               0 :             return false;                                                                                                                                                                                                      
     260                 :         }                                                                                                                                                                                                                      
     261                 :                                                                                                                                                                                                                                
     262               0 :         $email = '';                                                                                                                                                                                                           
     263               0 :         if ($subscriber instanceof Mage_Newsletter_Model_Subscriber) {                                                                                                                                                         
     264               0 :             $email = $subscriber->getSubscriberEmail();                                                                                                                                                                        
     265               0 :             if (is_null($name) && ($subscriber->hasCustomerFirstname() || $subscriber->hasCustomerLastname()) ) {                                                                                                              
     266               0 :                 $name = $subscriber->getCustomerFirstname() . ' ' . $subscriber->getCustomerLastname();                                                                                                                        
     267               0 :             }                                                                                                                                                                                                                  
     268               0 :         }                                                                                                                                                                                                                      
     269                 :         else {                                                                                                                                                                                                                 
     270               0 :             $email = (string) $subscriber;                                                                                                                                                                                     
     271                 :         }                                                                                                                                                                                                                      
     272                 :                                                                                                                                                                                                                                
     273               0 :         if (Mage::getStoreConfigFlag(Mage_Core_Model_Email_Template::XML_PATH_SENDING_SET_RETURN_PATH)) {                                                                                                                      
     274               0 :             $this->getMail()->setReturnPath($this->getTemplateSenderEmail());                                                                                                                                                  
     275               0 :         }                                                                                                                                                                                                                      
     276                 :                                                                                                                                                                                                                                
     277               0 :         ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));                                                                                                                                                             
     278               0 :         ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));                                                                                                                                                        
     279                 :                                                                                                                                                                                                                                
     280               0 :         $mail = $this->getMail();                                                                                                                                                                                              
     281               0 :         $mail->addTo($email, $name);                                                                                                                                                                                           
     282               0 :         $text = $this->getProcessedTemplate($variables, true);                                                                                                                                                                 
     283                 :                                                                                                                                                                                                                                
     284               0 :         if ($this->isPlain()) {                                                                                                                                                                                                
     285               0 :             $mail->setBodyText($text);                                                                                                                                                                                         
     286               0 :         }                                                                                                                                                                                                                      
     287                 :         else {                                                                                                                                                                                                                 
     288               0 :             $mail->setBodyHTML($text);                                                                                                                                                                                         
     289                 :         }                                                                                                                                                                                                                      
     290                 :                                                                                                                                                                                                                                
     291               0 :         $mail->setSubject($this->getProcessedTemplateSubject($variables));                                                                                                                                                     
     292               0 :         $mail->setFrom($this->getTemplateSenderEmail(), $this->getTemplateSenderName());                                                                                                                                       
     293                 :                                                                                                                                                                                                                                
     294                 :         try {                                                                                                                                                                                                                  
     295               0 :             $mail->send();                                                                                                                                                                                                     
     296               0 :             $this->_mail = null;                                                                                                                                                                                               
     297               0 :             if (!is_null($queue)) {                                                                                                                                                                                            
     298               0 :                 $subscriber->received($queue);                                                                                                                                                                                 
     299               0 :             }                                                                                                                                                                                                                  
     300                 :         }                                                                                                                                                                                                                      
     301               0 :         catch (Exception $e) {                                                                                                                                                                                                 
     302               0 :             if ($subscriber instanceof Mage_Newsletter_Model_Subscriber) {                                                                                                                                                     
     303                 :                 // If letter sent for subscriber, we create a problem report entry                                                                                                                                             
     304               0 :                 $problem = Mage::getModel('newsletter/problem');                                                                                                                                                               
     305               0 :                 $problem->addSubscriberData($subscriber);                                                                                                                                                                      
     306               0 :                 if (!is_null($queue)) {                                                                                                                                                                                        
     307               0 :                     $problem->addQueueData($queue);                                                                                                                                                                            
     308               0 :                 }                                                                                                                                                                                                              
     309               0 :                 $problem->addErrorData($e);                                                                                                                                                                                    
     310               0 :                 $problem->save();                                                                                                                                                                                              
     311                 :                                                                                                                                                                                                                                
     312               0 :                 if (!is_null($queue)) {                                                                                                                                                                                        
     313               0 :                     $subscriber->received($queue);                                                                                                                                                                             
     314               0 :                 }                                                                                                                                                                                                              
     315               0 :             } else {                                                                                                                                                                                                           
     316                 :                 // Otherwise throw error to upper level                                                                                                                                                                        
     317               0 :                 throw $e;                                                                                                                                                                                                      
     318                 :             }                                                                                                                                                                                                                  
     319               0 :             return false;                                                                                                                                                                                                      
     320                 :         }                                                                                                                                                                                                                      
     321                 :                                                                                                                                                                                                                                
     322               0 :         return true;                                                                                                                                                                                                           
     323                 :     }                                                                                                                                                                                                                          
     324                 :                                                                                                                                                                                                                                
     325                 :     /**                                                                                                                                                                                                                        
     326                 :      * Prepare Process (with save)                                                                                                                                                                                             
     327                 :      *                                                                                                                                                                                                                         
     328                 :      * @return Mage_Newsletter_Model_Template                                                                                                                                                                                  
     329                 :      * @deprecated since 1.4.0.1                                                                                                                                                                                               
     330                 :      */                                                                                                                                                                                                                        
     331                 :     public function preprocess()                                                                                                                                                                                               
     332                 :     {                                                                                                                                                                                                                          
     333               0 :         $this->_preprocessFlag = true;                                                                                                                                                                                         
     334               0 :         $this->save();                                                                                                                                                                                                         
     335               0 :         $this->_preprocessFlag = false;                                                                                                                                                                                        
     336               0 :         return $this;                                                                                                                                                                                                          
     337                 :     }                                                                                                                                                                                                                          
     338                 :                                                                                                                                                                                                                                
     339                 :     /**                                                                                                                                                                                                                        
     340                 :      * Retrieve processed template subject                                                                                                                                                                                     
     341                 :      *                                                                                                                                                                                                                         
     342                 :      * @param array $variables                                                                                                                                                                                                 
     343                 :      * @return string                                                                                                                                                                                                          
     344                 :      */                                                                                                                                                                                                                        
     345                 :     public function getProcessedTemplateSubject(array $variables)                                                                                                                                                              
     346                 :     {                                                                                                                                                                                                                          
     347               0 :         $processor = new Varien_Filter_Template();                                                                                                                                                                             
     348                 :                                                                                                                                                                                                                                
     349               0 :         if (!$this->_preprocessFlag) {                                                                                                                                                                                         
     350               0 :             $variables['this'] = $this;                                                                                                                                                                                        
     351               0 :         }                                                                                                                                                                                                                      
     352                 :                                                                                                                                                                                                                                
     353               0 :         $processor->setVariables($variables);                                                                                                                                                                                  
     354               0 :         return $processor->filter($this->getTemplateSubject());                                                                                                                                                                
     355                 :     }                                                                                                                                                                                                                          
     356                 :                                                                                                                                                                                                                                
     357                 :     /**                                                                                                                                                                                                                        
     358                 :      * Retrieve template text wrapper                                                                                                                                                                                          
     359                 :      *                                                                                                                                                                                                                         
     360                 :      * @return string                                                                                                                                                                                                          
     361                 :      */                                                                                                                                                                                                                        
     362                 :     public function getTemplateText()                                                                                                                                                                                          
     363                 :     {                                                                                                                                                                                                                          
     364               0 :         if (!$this->getData('template_text') && !$this->getId()) {                                                                                                                                                             
     365               0 :             $this->setData('template_text',                                                                                                                                                                                    
     366               0 :                 Mage::helper('newsletter')->__('Follow this link to unsubscribe <!-- This tag is for unsubscribe link  --><a href="{{var subscriber.getUnsubscriptionLink()}}">{{var subscriber.getUnsubscriptionLink()}}</a>')
     367               0 :             );                                                                                                                                                                                                                 
     368               0 :         }                                                                                                                                                                                                                      
     369                 :                                                                                                                                                                                                                                
     370               0 :         return $this->getData('template_text');                                                                                                                                                                                
     371                 :     }                                                                                                                                                                                                                          
     372                 : }                                                                                                                                                                                                                              

Generated by PHP_CodeCoverage 1.0.4 using PHP 5.3.4 and PHPUnit 3.5.13 at Tue Jul 5 9:07:16 UTC 2011.