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

  Coverage
  Classes Functions / Methods Lines
Total
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 21 CRAP
0.00%0.00%
0.00% 0 / 150
 
Mage_Index_Model_Process
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 21
0.00%0.00%
0.00% 0 / 150
 _construct()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 2
 _setEventNamespace(Mage_Index_Model_Event $event)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 4
 _resetEventNamespace($event)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 3
 register(Mage_Index_Model_Event $event)
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 7
 matchEvent(Mage_Index_Model_Event $event)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 reindexAll()
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 9
 reindexEverything()
0.00%0.00%
0.00% 0 / 1 30
0.00%0.00%
0.00% 0 / 13
 processEvent(Mage_Index_Model_Event $event)
0.00%0.00%
0.00% 0 / 1 12
0.00%0.00%
0.00% 0 / 11
 getIndexer()
0.00%0.00%
0.00% 0 / 1 42
0.00%0.00%
0.00% 0 / 17
 indexEvents($entity=null, $type=null)
0.00%0.00%
0.00% 0 / 1 132
0.00%0.00%
0.00% 0 / 28
 updateEventStatus(Mage_Index_Model_Event $event, $status)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 2
 _getLockFile()
0.00%0.00%
0.00% 0 / 1 12
0.00%0.00%
0.00% 0 / 10
 lock()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 3
 lockAndBlock()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 3
 unlock()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 3
 isLocked()
0.00%0.00%
0.00% 0 / 1 12
0.00%0.00%
0.00% 0 / 7
 __destruct()
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 4
 changeStatus($status)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 2
 getModesOptions()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 3
 getStatusesOptions()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 4
 getDepends()
0.00%0.00%
0.00% 0 / 1 30
0.00%0.00%
0.00% 0 / 14


       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_Index                                                                                                                                         
      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                 : class Mage_Index_Model_Process extends Mage_Core_Model_Abstract                                                                                                    
      28                 : {                                                                                                                                                                  
      29                 :     const XML_PATH_INDEXER_DATA     = 'global/index/indexer';                                                                                                      
      30                 :     /**                                                                                                                                                            
      31                 :      * Process statuses                                                                                                                                            
      32                 :      */                                                                                                                                                            
      33                 :     const STATUS_RUNNING            = 'working';                                                                                                                   
      34                 :     const STATUS_PENDING            = 'pending';                                                                                                                   
      35                 :     const STATUS_REQUIRE_REINDEX    = 'require_reindex';                                                                                                           
      36                 :                                                                                                                                                                    
      37                 :     /**                                                                                                                                                            
      38                 :      * Process event statuses                                                                                                                                      
      39                 :      */                                                                                                                                                            
      40                 :     const EVENT_STATUS_NEW          = 'new';                                                                                                                       
      41                 :     const EVENT_STATUS_DONE         = 'done';                                                                                                                      
      42                 :     const EVENT_STATUS_ERROR        = 'error';                                                                                                                     
      43                 :     const EVENT_STATUS_WORKING      = 'working';                                                                                                                   
      44                 :                                                                                                                                                                    
      45                 :     /**                                                                                                                                                            
      46                 :      * Process modes                                                                                                                                               
      47                 :      * Process mode allow disable automatic process events processing                                                                                              
      48                 :      */                                                                                                                                                            
      49                 :     const MODE_MANUAL              = 'manual';                                                                                                                     
      50                 :     const MODE_REAL_TIME           = 'real_time';                                                                                                                  
      51                 :                                                                                                                                                                    
      52                 :     /**                                                                                                                                                            
      53                 :      * Indexer stategy object                                                                                                                                      
      54                 :      *                                                                                                                                                             
      55                 :      * @var Mage_Index_Model_Indexer_Abstract                                                                                                                      
      56                 :      */                                                                                                                                                            
      57                 :     protected $_indexer = null;                                                                                                                                    
      58                 :                                                                                                                                                                    
      59                 :     /**                                                                                                                                                            
      60                 :      * Process lock properties                                                                                                                                     
      61                 :      */                                                                                                                                                            
      62                 :     protected $_isLocked = null;                                                                                                                                   
      63                 :     protected $_lockFile = null;                                                                                                                                   
      64                 :                                                                                                                                                                    
      65                 :     /**                                                                                                                                                            
      66                 :      * Initialize resource                                                                                                                                         
      67                 :      */                                                                                                                                                            
      68                 :     protected function _construct()                                                                                                                                
      69                 :     {                                                                                                                                                              
      70               0 :         $this->_init('index/process');                                                                                                                             
      71               0 :     }                                                                                                                                                              
      72                 :                                                                                                                                                                    
      73                 :     /**                                                                                                                                                            
      74                 :      * Set indexer class name as data namespace for event object                                                                                                   
      75                 :      *                                                                                                                                                             
      76                 :      * @param   Mage_Index_Model_Event $event                                                                                                                      
      77                 :      * @return  Mage_Index_Model_Process                                                                                                                           
      78                 :      */                                                                                                                                                            
      79                 :     protected function _setEventNamespace(Mage_Index_Model_Event $event)                                                                                           
      80                 :     {                                                                                                                                                              
      81               0 :         $namespace = get_class($this->getIndexer());                                                                                                               
      82               0 :         $event->setDataNamespace($namespace);                                                                                                                      
      83               0 :         $event->setProcess($this);                                                                                                                                 
      84               0 :         return $this;                                                                                                                                              
      85                 :     }                                                                                                                                                              
      86                 :                                                                                                                                                                    
      87                 :     /**                                                                                                                                                            
      88                 :      * Remove indexer namespace from event                                                                                                                         
      89                 :      *                                                                                                                                                             
      90                 :      * @return  Mage_Index_Model_Process                                                                                                                           
      91                 :      */                                                                                                                                                            
      92                 :     protected function _resetEventNamespace($event)                                                                                                                
      93                 :     {                                                                                                                                                              
      94               0 :         $event->setDataNamespace(null);                                                                                                                            
      95               0 :         $event->setProcess(null);                                                                                                                                  
      96               0 :         return $this;                                                                                                                                              
      97                 :     }                                                                                                                                                              
      98                 :                                                                                                                                                                    
      99                 :     /**                                                                                                                                                            
     100                 :      * Register data required by process in event object                                                                                                           
     101                 :      *                                                                                                                                                             
     102                 :      * @param Mage_Index_Model_Event $event                                                                                                                        
     103                 :      */                                                                                                                                                            
     104                 :     public function register(Mage_Index_Model_Event $event)                                                                                                        
     105                 :     {                                                                                                                                                              
     106               0 :         if ($this->matchEvent($event)) {                                                                                                                           
     107               0 :             $this->_setEventNamespace($event);                                                                                                                     
     108               0 :             $this->getIndexer()->register($event);                                                                                                                 
     109               0 :             $event->addProcessId($this->getId());                                                                                                                  
     110               0 :             $this->_resetEventNamespace($event);                                                                                                                   
     111               0 :         }                                                                                                                                                          
     112               0 :         return $this;                                                                                                                                              
     113                 :                                                                                                                                                                    
     114                 :     }                                                                                                                                                              
     115                 :                                                                                                                                                                    
     116                 :     /**                                                                                                                                                            
     117                 :      * Check if event can be matched by process                                                                                                                    
     118                 :      *                                                                                                                                                             
     119                 :      * @param Mage_Index_Model_Event $event                                                                                                                        
     120                 :      * @return bool                                                                                                                                                
     121                 :      */                                                                                                                                                            
     122                 :     public function matchEvent(Mage_Index_Model_Event $event)                                                                                                      
     123                 :     {                                                                                                                                                              
     124               0 :         return $this->getIndexer()->matchEvent($event);                                                                                                            
     125                 :     }                                                                                                                                                              
     126                 :                                                                                                                                                                    
     127                 :     /**                                                                                                                                                            
     128                 :      * Reindex all data what this process responsible is                                                                                                           
     129                 :      *                                                                                                                                                             
     130                 :      * @return unknown_type                                                                                                                                        
     131                 :      */                                                                                                                                                            
     132                 :     public function reindexAll()                                                                                                                                   
     133                 :     {                                                                                                                                                              
     134               0 :         if ($this->isLocked()) {                                                                                                                                   
     135               0 :             Mage::throwException(Mage::helper('index')->__('%s Index process is working now. Please try run this process later.', $this->getIndexer()->getName()));
     136               0 :         }                                                                                                                                                          
     137               0 :         $this->_getResource()->startProcess($this);                                                                                                                
     138               0 :         $this->lock();                                                                                                                                             
     139               0 :         $this->getIndexer()->reindexAll();                                                                                                                         
     140               0 :         $this->unlock();                                                                                                                                           
     141               0 :         $this->_getResource()->endProcess($this);                                                                                                                  
     142               0 :     }                                                                                                                                                              
     143                 :                                                                                                                                                                    
     144                 :     /**                                                                                                                                                            
     145                 :      * Reindex all data what this process responsible is                                                                                                           
     146                 :      * Check and using depends processes                                                                                                                           
     147                 :      *                                                                                                                                                             
     148                 :      * @return Mage_Index_Model_Process                                                                                                                            
     149                 :      */                                                                                                                                                            
     150                 :     public function reindexEverything()                                                                                                                            
     151                 :     {                                                                                                                                                              
     152               0 :         if ($this->getData('runed_reindexall')) {                                                                                                                  
     153               0 :             return $this;                                                                                                                                          
     154                 :         }                                                                                                                                                          
     155                 :                                                                                                                                                                    
     156               0 :         if ($this->getDepends()) {                                                                                                                                 
     157               0 :             $indexer = Mage::getSingleton('index/indexer');                                                                                                        
     158               0 :             foreach ($this->getDepends() as $code) {                                                                                                               
     159               0 :                 $process = $indexer->getProcessByCode($code);                                                                                                      
     160               0 :                 if ($process) {                                                                                                                                    
     161               0 :                     $process->reindexEverything();                                                                                                                 
     162               0 :                 }                                                                                                                                                  
     163               0 :             }                                                                                                                                                      
     164               0 :         }                                                                                                                                                          
     165                 :                                                                                                                                                                    
     166               0 :         $this->setData('runed_reindexall', true);                                                                                                                  
     167               0 :         return $this->reindexAll();                                                                                                                                
     168                 :     }                                                                                                                                                              
     169                 :                                                                                                                                                                    
     170                 :     /**                                                                                                                                                            
     171                 :      * Process event with assigned indexer object                                                                                                                  
     172                 :      *                                                                                                                                                             
     173                 :      * @param Mage_Index_Model_Event $event                                                                                                                        
     174                 :      * @return Mage_Index_Model_Process                                                                                                                            
     175                 :      */                                                                                                                                                            
     176                 :     public function processEvent(Mage_Index_Model_Event $event)                                                                                                    
     177                 :     {                                                                                                                                                              
     178               0 :         if ($this->getMode() == self::MODE_MANUAL) {                                                                                                               
     179               0 :             $this->changeStatus(self::STATUS_REQUIRE_REINDEX);                                                                                                     
     180               0 :             return $this;                                                                                                                                          
     181                 :         }                                                                                                                                                          
     182               0 :         if (!$this->getIndexer()->matchEvent($event)) {                                                                                                            
     183               0 :             return $this;                                                                                                                                          
     184                 :         }                                                                                                                                                          
     185               0 :         $this->_setEventNamespace($event);                                                                                                                         
     186               0 :         $this->getIndexer()->processEvent($event);                                                                                                                 
     187               0 :         $event->resetData();                                                                                                                                       
     188               0 :         $this->_resetEventNamespace($event);                                                                                                                       
     189               0 :         $event->addProcessId($this->getId(), self::EVENT_STATUS_DONE);                                                                                             
     190               0 :         return $this;                                                                                                                                              
     191                 :     }                                                                                                                                                              
     192                 :                                                                                                                                                                    
     193                 :     /**                                                                                                                                                            
     194                 :      * Get Indexer strategy object                                                                                                                                 
     195                 :      *                                                                                                                                                             
     196                 :      * @return Mage_Index_Model_Indexer_Abstract                                                                                                                   
     197                 :      */                                                                                                                                                            
     198                 :     public function getIndexer()                                                                                                                                   
     199                 :     {                                                                                                                                                              
     200               0 :         if ($this->_indexer === null) {                                                                                                                            
     201               0 :             $code = $this->_getData('indexer_code');                                                                                                               
     202               0 :             if (!$code) {                                                                                                                                          
     203               0 :                 Mage::throwException(Mage::helper('index')->__('Indexer code is not defined.'));                                                                   
     204               0 :             }                                                                                                                                                      
     205               0 :             $xmlPath = self::XML_PATH_INDEXER_DATA . '/' . $code;                                                                                                  
     206               0 :             $config = Mage::getConfig()->getNode($xmlPath);                                                                                                        
     207               0 :             if (!$config || empty($config->model)) {                                                                                                               
     208               0 :                 Mage::throwException(Mage::helper('index')->__('Indexer model is not defined.'));                                                                  
     209               0 :             }                                                                                                                                                      
     210               0 :             $model = Mage::getModel((string)$config->model);                                                                                                       
     211               0 :             if ($model instanceof Mage_Index_Model_Indexer_Abstract) {                                                                                             
     212               0 :                 $this->_indexer = $model;                                                                                                                          
     213               0 :             } else {                                                                                                                                               
     214               0 :                 Mage::throwException(Mage::helper('index')->__('Indexer model should extend Mage_Index_Model_Indexer_Abstract.'));                                 
     215                 :             }                                                                                                                                                      
     216               0 :         }                                                                                                                                                          
     217               0 :         return $this->_indexer;                                                                                                                                    
     218                 :     }                                                                                                                                                              
     219                 :                                                                                                                                                                    
     220                 :     /**                                                                                                                                                            
     221                 :      * Index pending events addressed to the process                                                                                                               
     222                 :      *                                                                                                                                                             
     223                 :      * @param   null|string $entity                                                                                                                                
     224                 :      * @param   null|string $type                                                                                                                                  
     225                 :      * @return  Mage_Index_Model_Process                                                                                                                           
     226                 :      */                                                                                                                                                            
     227                 :     public function indexEvents($entity=null, $type=null)                                                                                                          
     228                 :     {                                                                                                                                                              
     229                 :         /**                                                                                                                                                        
     230                 :          * Check if process indexer can match entity code and action type                                                                                          
     231                 :          */                                                                                                                                                        
     232               0 :         if ($entity !== null && $type !== null) {                                                                                                                  
     233               0 :             if (!$this->getIndexer()->matchEntityAndType($entity, $type)) {                                                                                        
     234               0 :                 return $this;                                                                                                                                      
     235                 :             }                                                                                                                                                      
     236               0 :         }                                                                                                                                                          
     237                 :                                                                                                                                                                    
     238               0 :         if ($this->getMode() == self::MODE_MANUAL) {                                                                                                               
     239               0 :             return $this;                                                                                                                                          
     240                 :         }                                                                                                                                                          
     241                 :                                                                                                                                                                    
     242               0 :         if ($this->isLocked()) {                                                                                                                                   
     243               0 :             return $this;                                                                                                                                          
     244                 :         }                                                                                                                                                          
     245               0 :         $this->lock();                                                                                                                                             
     246                 :                                                                                                                                                                    
     247                 :         /**                                                                                                                                                        
     248                 :          * Prepare events collection                                                                                                                               
     249                 :          */                                                                                                                                                        
     250               0 :         $eventsCollection = Mage::getResourceModel('index/event_collection')                                                                                       
     251               0 :             ->addProcessFilter($this, self::EVENT_STATUS_NEW);                                                                                                     
     252               0 :         if ($entity !== null) {                                                                                                                                    
     253               0 :             $eventsCollection->addEntityFilter($entity);                                                                                                           
     254               0 :         }                                                                                                                                                          
     255               0 :         if ($type !== null) {                                                                                                                                      
     256               0 :             $eventsCollection->addTypeFilter($type);                                                                                                               
     257               0 :         }                                                                                                                                                          
     258                 :                                                                                                                                                                    
     259                 :         /**                                                                                                                                                        
     260                 :          * Process all new events                                                                                                                                  
     261                 :          */                                                                                                                                                        
     262               0 :         while ($eventsCollection->getSize()) {                                                                                                                     
     263               0 :             foreach ($eventsCollection as $event) {                                                                                                                
     264                 :                 try {                                                                                                                                              
     265               0 :                     $this->processEvent($event);                                                                                                                   
     266               0 :                 } catch (Exception $e) {                                                                                                                           
     267               0 :                     $event->addProcessId($this->getId(), self::EVENT_STATUS_ERROR);                                                                                
     268                 :                 }                                                                                                                                                  
     269               0 :                 $event->save();                                                                                                                                    
     270               0 :             }                                                                                                                                                      
     271               0 :             $eventsCollection->reset();                                                                                                                            
     272               0 :         }                                                                                                                                                          
     273                 :                                                                                                                                                                    
     274               0 :         $this->unlock();                                                                                                                                           
     275               0 :         return $this;                                                                                                                                              
     276                 :     }                                                                                                                                                              
     277                 :                                                                                                                                                                    
     278                 :     /**                                                                                                                                                            
     279                 :      * Update status process/event association                                                                                                                     
     280                 :      *                                                                                                                                                             
     281                 :      * @param   Mage_Index_Model_Event $event                                                                                                                      
     282                 :      * @param   string $status                                                                                                                                     
     283                 :      * @return  Mage_Index_Model_Process                                                                                                                           
     284                 :      */                                                                                                                                                            
     285                 :     public function updateEventStatus(Mage_Index_Model_Event $event, $status)                                                                                      
     286                 :     {                                                                                                                                                              
     287               0 :         $this->_getResource()->updateEventStatus($this->getId(), $event->getId(), $status);                                                                        
     288               0 :         return $this;                                                                                                                                              
     289                 :     }                                                                                                                                                              
     290                 :                                                                                                                                                                    
     291                 :     /**                                                                                                                                                            
     292                 :      * Get lock file resource                                                                                                                                      
     293                 :      *                                                                                                                                                             
     294                 :      * @return resource                                                                                                                                            
     295                 :      */                                                                                                                                                            
     296                 :     protected function _getLockFile()                                                                                                                              
     297                 :     {                                                                                                                                                              
     298               0 :         if ($this->_lockFile === null) {                                                                                                                           
     299               0 :             $varDir = Mage::getConfig()->getVarDir('locks');                                                                                                       
     300               0 :             $file = $varDir . DS . 'index_process_'.$this->getId().'.lock';                                                                                        
     301               0 :             if (is_file($file)) {                                                                                                                                  
     302               0 :                 $this->_lockFile = fopen($file, 'w');                                                                                                              
     303               0 :             } else {                                                                                                                                               
     304               0 :                 $this->_lockFile = fopen($file, 'x');                                                                                                              
     305                 :             }                                                                                                                                                      
     306               0 :             fwrite($this->_lockFile, date('r'));                                                                                                                   
     307               0 :         }                                                                                                                                                          
     308               0 :         return $this->_lockFile;                                                                                                                                   
     309                 :     }                                                                                                                                                              
     310                 :                                                                                                                                                                    
     311                 :     /**                                                                                                                                                            
     312                 :      * Lock process without blocking.                                                                                                                              
     313                 :      * This method allow protect multiple process runing and fast lock validation.                                                                                 
     314                 :      *                                                                                                                                                             
     315                 :      * @return Mage_Index_Model_Process                                                                                                                            
     316                 :      */                                                                                                                                                            
     317                 :     public function lock()                                                                                                                                         
     318                 :     {                                                                                                                                                              
     319               0 :         $this->_isLocked = true;                                                                                                                                   
     320               0 :         flock($this->_getLockFile(), LOCK_EX | LOCK_NB);                                                                                                           
     321               0 :         return $this;                                                                                                                                              
     322                 :     }                                                                                                                                                              
     323                 :                                                                                                                                                                    
     324                 :     /**                                                                                                                                                            
     325                 :      * Lock and block process.                                                                                                                                     
     326                 :      * If new instance of the process will try validate locking state                                                                                              
     327                 :      * script will wait until process will be unlocked                                                                                                             
     328                 :      *                                                                                                                                                             
     329                 :      * @return Mage_Index_Model_Process                                                                                                                            
     330                 :      */                                                                                                                                                            
     331                 :     public function lockAndBlock()                                                                                                                                 
     332                 :     {                                                                                                                                                              
     333               0 :         $this->_isLocked = true;                                                                                                                                   
     334               0 :         flock($this->_getLockFile(), LOCK_EX);                                                                                                                     
     335               0 :         return $this;                                                                                                                                              
     336                 :     }                                                                                                                                                              
     337                 :                                                                                                                                                                    
     338                 :     /**                                                                                                                                                            
     339                 :      * Unlock process                                                                                                                                              
     340                 :      *                                                                                                                                                             
     341                 :      * @return Mage_Index_Model_Process                                                                                                                            
     342                 :      */                                                                                                                                                            
     343                 :     public function unlock()                                                                                                                                       
     344                 :     {                                                                                                                                                              
     345               0 :         $this->_isLocked = false;                                                                                                                                  
     346               0 :         flock($this->_getLockFile(), LOCK_UN);                                                                                                                     
     347               0 :         return $this;                                                                                                                                              
     348                 :     }                                                                                                                                                              
     349                 :                                                                                                                                                                    
     350                 :     /**                                                                                                                                                            
     351                 :      * Check if process is locked                                                                                                                                  
     352                 :      *                                                                                                                                                             
     353                 :      * @return bool                                                                                                                                                
     354                 :      */                                                                                                                                                            
     355                 :     public function isLocked()                                                                                                                                     
     356                 :     {                                                                                                                                                              
     357               0 :         if ($this->_isLocked !== null) {                                                                                                                           
     358               0 :             return $this->_isLocked;                                                                                                                               
     359                 :         } else {                                                                                                                                                   
     360               0 :             $fp = $this->_getLockFile();                                                                                                                           
     361               0 :             if (flock($fp, LOCK_EX | LOCK_NB)) {                                                                                                                   
     362               0 :                 flock($fp, LOCK_UN);                                                                                                                               
     363               0 :                 return false;                                                                                                                                      
     364                 :             }                                                                                                                                                      
     365               0 :             return true;                                                                                                                                           
     366                 :         }                                                                                                                                                          
     367                 :     }                                                                                                                                                              
     368                 :                                                                                                                                                                    
     369                 :     /**                                                                                                                                                            
     370                 :      * Close file resource if it was opened                                                                                                                        
     371                 :      */                                                                                                                                                            
     372                 :     public function __destruct()                                                                                                                                   
     373                 :     {                                                                                                                                                              
     374               0 :         if ($this->_lockFile) {                                                                                                                                    
     375               0 :             fclose($this->_lockFile);                                                                                                                              
     376               0 :         }                                                                                                                                                          
     377               0 :     }                                                                                                                                                              
     378                 :                                                                                                                                                                    
     379                 :     /**                                                                                                                                                            
     380                 :      * Change process status                                                                                                                                       
     381                 :      *                                                                                                                                                             
     382                 :      * @param string $status                                                                                                                                       
     383                 :      * @return Mage_Index_Model_Process                                                                                                                            
     384                 :      */                                                                                                                                                            
     385                 :     public function changeStatus($status)                                                                                                                          
     386                 :     {                                                                                                                                                              
     387               0 :         $this->_getResource()->updateStatus($this, $status);                                                                                                       
     388               0 :         return $this;                                                                                                                                              
     389                 :     }                                                                                                                                                              
     390                 :                                                                                                                                                                    
     391                 :     /**                                                                                                                                                            
     392                 :      * Get list of process mode options                                                                                                                            
     393                 :      *                                                                                                                                                             
     394                 :      * @return array                                                                                                                                               
     395                 :      */                                                                                                                                                            
     396                 :     public function getModesOptions()                                                                                                                              
     397                 :     {                                                                                                                                                              
     398                 :         return array(                                                                                                                                              
     399               0 :             self::MODE_REAL_TIME => Mage::helper('index')->__('Update on Save'),                                                                                   
     400               0 :             self::MODE_MANUAL => Mage::helper('index')->__('Manual Update')                                                                                        
     401               0 :         );                                                                                                                                                         
     402                 :     }                                                                                                                                                              
     403                 :                                                                                                                                                                    
     404                 :     /**                                                                                                                                                            
     405                 :      * Get list of process status options                                                                                                                          
     406                 :      *                                                                                                                                                             
     407                 :      * @return array                                                                                                                                               
     408                 :      */                                                                                                                                                            
     409                 :     public function getStatusesOptions()                                                                                                                           
     410                 :     {                                                                                                                                                              
     411                 :         return array(                                                                                                                                              
     412               0 :             self::STATUS_PENDING            => Mage::helper('index')->__('Ready'),                                                                                 
     413               0 :             self::STATUS_RUNNING            => Mage::helper('index')->__('Processing'),                                                                            
     414               0 :             self::STATUS_REQUIRE_REINDEX    => Mage::helper('index')->__('Reindex Required'),                                                                      
     415               0 :         );                                                                                                                                                         
     416                 :     }                                                                                                                                                              
     417                 :                                                                                                                                                                    
     418                 :     /**                                                                                                                                                            
     419                 :      * Retrieve depend indexer codes                                                                                                                               
     420                 :      *                                                                                                                                                             
     421                 :      * @return array                                                                                                                                               
     422                 :      */                                                                                                                                                            
     423                 :     public function getDepends()                                                                                                                                   
     424                 :     {                                                                                                                                                              
     425               0 :         $depends = $this->getData('depends');                                                                                                                      
     426               0 :         if (is_null($depends)) {                                                                                                                                   
     427               0 :             $depends = array();                                                                                                                                    
     428               0 :             $path = self::XML_PATH_INDEXER_DATA . '/' . $this->getIndexerCode();                                                                                   
     429               0 :             $node = Mage::getConfig()->getNode($path);                                                                                                             
     430               0 :             if ($node) {                                                                                                                                           
     431               0 :                 $data = $node->asArray();                                                                                                                          
     432               0 :                 if (isset($data['depends']) && is_array($data['depends'])) {                                                                                       
     433               0 :                     $depends = array_keys($data['depends']);                                                                                                       
     434               0 :                 }                                                                                                                                                  
     435               0 :             }                                                                                                                                                      
     436                 :                                                                                                                                                                    
     437               0 :             $this->setData('depends', $depends);                                                                                                                   
     438               0 :         }                                                                                                                                                          
     439                 :                                                                                                                                                                    
     440               0 :         return $depends;                                                                                                                                           
     441                 :     }                                                                                                                                                              
     442                 : }                                                                                                                                                                  

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.