Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Massaction is only inserted once to index_event #32

Open
tobihille opened this issue Jun 23, 2017 · 0 comments
Open

Massaction is only inserted once to index_event #32

tobihille opened this issue Jun 23, 2017 · 0 comments

Comments

@tobihille
Copy link
Contributor

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant