Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Index_Adminhtml_ProcessController
  • Mage_Index_Block_Adminhtml_Notifications
  • Mage_Index_Block_Adminhtml_Process
  • Mage_Index_Block_Adminhtml_Process_Edit
  • Mage_Index_Block_Adminhtml_Process_Edit_Form
  • Mage_Index_Block_Adminhtml_Process_Edit_Tab_Main
  • Mage_Index_Block_Adminhtml_Process_Edit_Tabs
  • Mage_Index_Block_Adminhtml_Process_Grid
  • Mage_Index_Block_Adminhtml_Process_Grid_Massaction
  • Mage_Index_Helper_Data
  • Mage_Index_Model_Event
  • Mage_Index_Model_Indexer
  • Mage_Index_Model_Indexer_Abstract
  • Mage_Index_Model_Mysql4_Abstract
  • Mage_Index_Model_Mysql4_Event
  • Mage_Index_Model_Mysql4_Event_Collection
  • Mage_Index_Model_Mysql4_Process
  • Mage_Index_Model_Mysql4_Process_Collection
  • Mage_Index_Model_Mysql4_Setup
  • Mage_Index_Model_Observer
  • Mage_Index_Model_Process
  • Mage_Index_Model_Resource_Abstract
  • Mage_Index_Model_Resource_Event
  • Mage_Index_Model_Resource_Event_Collection
  • Mage_Index_Model_Resource_Helper_Mysql4
  • Mage_Index_Model_Resource_Process
  • Mage_Index_Model_Resource_Process_Collection
  • Mage_Index_Model_Resource_Setup
  • Overview
  • Package
  • Class
  • Tree
  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) 2012 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:  * Enter description here ...
 29:  *
 30:  * @method Mage_Index_Model_Resource_Event _getResource()
 31:  * @method Mage_Index_Model_Resource_Event getResource()
 32:  * @method Mage_Index_Model_Event setType(string $value)
 33:  * @method Mage_Index_Model_Event setEntity(string $value)
 34:  * @method int getEntityPk()
 35:  * @method Mage_Index_Model_Event setEntityPk(int $value)
 36:  * @method string getCreatedAt()
 37:  * @method Mage_Index_Model_Event setCreatedAt(string $value)
 38:  * @method Mage_Index_Model_Event setOldData(string $value)
 39:  * @method Mage_Index_Model_Event setNewData(string $value)
 40:  * @method Varien_Object getDataObject()
 41:  *
 42:  * @category    Mage
 43:  * @package     Mage_Index
 44:  * @author      Magento Core Team <core@magentocommerce.com>
 45:  */
 46: class Mage_Index_Model_Event extends Mage_Core_Model_Abstract
 47: {
 48:     /**
 49:      * Predefined event types
 50:      */
 51:     const TYPE_SAVE        = 'save';
 52:     const TYPE_DELETE      = 'delete';
 53:     const TYPE_MASS_ACTION = 'mass_action';
 54:     const TYPE_REINDEX     = 'reindex';
 55: 
 56:     /**
 57:      * Array of related processes ids
 58:      * @var array
 59:      */
 60:     protected $_processIds = null;
 61: 
 62:     /**
 63:      * New and old data namespace. Used for separate processes data
 64:      *
 65:      * @var string
 66:      */
 67:     protected $_dataNamespace = null;
 68: 
 69:     /**
 70:      * Process object which currently working with event
 71:      */
 72:     protected $_process = null;
 73: 
 74:     /**
 75:      * Initialize resource
 76:      */
 77:     protected function _construct()
 78:     {
 79:         $this->_init('index/event');
 80:     }
 81: 
 82:     /**
 83:      * Specify process object
 84:      *
 85:      * @param null|Mage_Index_Model_Process $process
 86:      */
 87:     public function setProcess($process)
 88:     {
 89:         $this->_process = $process;
 90:         return $this;
 91:     }
 92: 
 93:     /**
 94:      * Get related process object
 95:      *
 96:      * @return Mage_Index_Model_Process | null
 97:      */
 98:     public function getProcess()
 99:     {
100:         return $this->_process;
101:     }
102: 
103:     /**
104:      * Specify namespace for old and new data
105:      */
106:     public function setDataNamespace($namespace)
107:     {
108:         $this->_dataNamespace = $namespace;
109:         return $this;
110:     }
111: 
112:     /**
113:      * Reset old and new data arrays
114:      *
115:      * @return Mage_Index_Model_Event
116:      */
117:     public function resetData()
118:     {
119:         if ($this->_dataNamespace) {
120:             $data = $this->getNewData(false);
121:             $data[$this->_dataNamespace] = null;
122:             $this->setNewData($data);
123:         } else {
124:             $this->setNewData(array());
125:         }
126:         return $this;
127:     }
128: 
129:     /**
130:      * Add process id to event object
131:      *
132:      * @param   $processId
133:      * @return  Mage_Index_Model_Event
134:      */
135:     public function addProcessId($processId, $status=Mage_Index_Model_Process::EVENT_STATUS_NEW)
136:     {
137:         $this->_processIds[$processId] = $status;
138:         return $this;
139:     }
140: 
141:     /**
142:      * Get event process ids
143:      *
144:      * @return array
145:      */
146:     public function getProcessIds()
147:     {
148:         return $this->_processIds;
149:     }
150: 
151:     /**
152:      * Merge new data
153:      *
154:      * @param array $previous
155:      * @param mixed $current
156:      * @return array
157:      */
158:     protected function _mergeNewDataRecursive($previous, $current)
159:     {
160:         if (!is_array($current)) {
161:             if (!is_null($current)) {
162:                 $previous[] = $current;
163:             }
164:             return $previous;
165:         }
166: 
167:         foreach ($previous as $key => $value) {
168:             if (array_key_exists($key, $current) && !is_null($current[$key]) && is_array($previous[$key])) {
169:                 if (!is_string($key) || is_array($current[$key])) {
170:                     $current[$key] = $this->_mergeNewDataRecursive($previous[$key], $current[$key]);
171:                 }
172:             } elseif (!array_key_exists($key, $current) || is_null($current[$key])) {
173:                 $current[$key] = $previous[$key];
174:             } elseif (!is_array($previous[$key]) && !is_string($key)) {
175:                 $current[] = $previous[$key];
176:             }
177:         }
178: 
179:         return $current;
180:     }
181: 
182:     /**
183:      * Merge previous event data to object.
184:      * Used for events duplicated protection
185:      *
186:      * @param array $data
187:      * @return Mage_Index_Model_Event
188:      */
189:     public function mergePreviousData($data)
190:     {
191:         if (!empty($data['event_id'])) {
192:             $this->setId($data['event_id']);
193:             $this->setCreatedAt($data['created_at']);
194:         }
195: 
196:         if (!empty($data['new_data'])) {
197:             $previousNewData = unserialize($data['new_data']);
198:             $currentNewData  = $this->getNewData(false);
199:             $currentNewData = $this->_mergeNewDataRecursive($previousNewData, $currentNewData);
200:             $this->setNewData(serialize($currentNewData));
201:         }
202:         return $this;
203:     }
204: 
205:     /**
206:      * Clean new data, unset data for done processes
207:      *
208:      * @return Mage_Index_Model_Event
209:      */
210:     public function cleanNewData()
211:     {
212:         $processIds = $this->getProcessIds();
213:         if (!is_array($processIds) || empty($processIds)) {
214:             return $this;
215:         }
216: 
217:         $newData = $this->getNewData(false);
218:         foreach ($processIds as $processId => $processStatus) {
219:             if ($processStatus == Mage_Index_Model_Process::EVENT_STATUS_DONE) {
220:                 $process = Mage::getSingleton('index/indexer')->getProcessById($processId);
221:                 if ($process) {
222:                     $namespace = get_class($process->getIndexer());
223:                     if (array_key_exists($namespace, $newData)) {
224:                         unset($newData[$namespace]);
225:                     }
226:                 }
227:             }
228:         }
229:         $this->setNewData(serialize($newData));
230: 
231:         return $this;
232:     }
233: 
234:     /**
235:      * Get event old data array
236:      *
237:      * @deprecated since 1.6.2.0
238:      * @param bool $useNamespace
239:      * @return array
240:      */
241:     public function getOldData($useNamespace = true)
242:     {
243:         return array();
244:     }
245: 
246:     /**
247:      * Get event new data array
248:      *
249:      * @param bool $useNamespace
250:      * @return array
251:      */
252:     public function getNewData($useNamespace = true)
253:     {
254:         $data = $this->_getData('new_data');
255:         if (is_string($data)) {
256:             $data = unserialize($data);
257:         } elseif (empty($data) || !is_array($data)) {
258:             $data = array();
259:         }
260:         if ($useNamespace && $this->_dataNamespace) {
261:             return isset($data[$this->_dataNamespace]) ? $data[$this->_dataNamespace] : array();
262:         }
263:         return $data;
264:     }
265: 
266:     /**
267:      * Add new values to old data array (overwrite if value with same key exist)
268:      *
269:      * @deprecated since 1.6.2.0
270:      * @param array | string $data
271:      * @param null | mixed $value
272:      * @return Mage_Index_Model_Event
273:      */
274:     public function addOldData($key, $value=null)
275:     {
276:         return $this;
277:     }
278: 
279:     /**
280:      * Add new values to new data array (overwrite if value with same key exist)
281:      *
282:      * @param array | string $data
283:      * @param null | mixed $value
284:      * @return Mage_Index_Model_Event
285:      */
286:     public function addNewData($key, $value=null)
287:     {
288:         $newData = $this->getNewData(false);
289:         if (!is_array($key)) {
290:             $key = array($key => $value);
291:         }
292:         if ($this->_dataNamespace) {
293:             if (!isset($newData[$this->_dataNamespace])) {
294:                 $newData[$this->_dataNamespace] = array();
295:             }
296:             $newData[$this->_dataNamespace] = array_merge($newData[$this->_dataNamespace], $key);
297:         } else {
298:             $newData = array_merge($newData, $key);
299:         }
300:         $this->setNewData($newData);
301:         return $this;
302:     }
303: 
304:     /**
305:      * Get event entity code.
306:      * Entity code declare what kind of data object related with event (product, category etc.)
307:      *
308:      * @return string
309:      */
310:     public function getEntity()
311:     {
312:         return $this->_getData('entity');
313:     }
314: 
315:     /**
316:      * Get event action type.
317:      * Data related on self::TYPE_* constants
318:      *
319:      * @return string
320:      */
321:     public function getType()
322:     {
323:         return $this->_getData('type');
324:     }
325: 
326:     /**
327:      * Serelaize old and new data arrays before saving
328:      *
329:      * @return Mage_Index_Model_Event
330:      */
331:     protected function _beforeSave()
332:     {
333:         $newData = $this->getNewData(false);
334:         $this->setNewData(serialize($newData));
335:         if (!$this->hasCreatedAt()) {
336:             $this->setCreatedAt($this->_getResource()->formatDate(time(), true));
337:         }
338:         return parent::_beforeSave();
339:     }
340: }
341: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0