-
Notifications
You must be signed in to change notification settings - Fork 37
Description
Hi,
I discovered a ... let's say non-intuitive behaviour ... in magento which leads to loosing index-events when using async-index.
Scince massactions naturally don't have a single primary key the key is set to null - this seems to make sense. But when another massaction occurs the event with the corresponding PK is updated instead of inserted again - which can lead to a loss of index-events when this happens right between two asyncindex - runs.
My fix is rather crude: i registered a new indexer and add time() as PK.
In config.xml you define the indexer (inside global):
<indexer>
<somecode>
<model>yourmodelnamespace/indexer</model>
</somecode>
</indexer>
</index>
You add the indexer to the index_process table:
/* @var $this Mage_Core_Model_Resource_Setup /
$installer = new Mage_Catalog_Model_Resource_Setup('yourmodelnamespace');
$installer->startSetup();
try {
/* @var Mage_Index_Model_Process $ip */
$ip = Mage::getModel('index/process');
$ip->setData([
'indexer_code' => 'dt_adminhtml',
'status' => Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX,
'mode' => Mage_Index_Model_Process::MODE_MANUAL
]);
$ip->save();
} catch (Exception $e) {
Mage::logException($e);
}
$installer->endSetup();
You create the new Indexer-Model:
class [Placeholder]_Model_Indexer extends Mage_Index_Model_Indexer_Abstract
{
/**
* @var string[]
/
protected $_matchedEntities = array(
Mage_Catalog_Model_Product::ENTITY => array(
Mage_Index_Model_Event::TYPE_MASS_ACTION,
),
);
/*
* @param Mage_Index_Model_Event $event
* @return $this
/
protected function _registerEvent(Mage_Index_Model_Event $event)
{
if ($event->getEntity() !== Mage_Catalog_Model_Product::ENTITY) {
return $this;
}
if ($event->getType() !== Mage_Index_Model_Event::TYPE_MASS_ACTION) {
return $this;
}
$event->setEntityPk( time() ); //to prevent massactions overriding their index events
return $this;
}
/*
* @param Mage_Index_Model_Event $event
*/
protected function _processEvent(Mage_Index_Model_Event $event)
{
//do nothing, we only want to modify the event that is added
}
public function getName()
{
return 'Admin Massaction fix';
}
public function getDescription()
{
return 'Admin Massaction fix';
}
}
Sorry for the bad formatting
- Tobi