Commit 742dd077 authored by Kristof Ringleff's avatar Kristof Ringleff

move indexing out of transaction

parent 59a15d7e
...@@ -84,10 +84,12 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Eav ...@@ -84,10 +84,12 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Eav
*/ */
public function apply(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface $fixture) public function apply(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
{ {
$eavLoaders = array();
$this->getResource()->beginTransaction(); $this->getResource()->beginTransaction();
foreach ($data as $entityType => $values) { foreach ($data as $entityType => $values) {
$this->_getEavLoader($entityType) $eavLoaders[] = $this->_getEavLoader($entityType)
->setFixture($fixture) ->setFixture($fixture)
->setOptions($fixture->getOptions()) ->setOptions($fixture->getOptions())
->loadEntity($entityType, $values); ->loadEntity($entityType, $values);
...@@ -95,6 +97,10 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Eav ...@@ -95,6 +97,10 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Eav
$this->getResource()->commit(); $this->getResource()->commit();
foreach ($eavLoaders as $eavLoader){
$eavLoader->runRequiredIndexers();
}
$fixture->setStorageData(self::STORAGE_KEY, array_keys($data)); $fixture->setStorageData(self::STORAGE_KEY, array_keys($data));
return $this; return $this;
} }
......
...@@ -31,15 +31,45 @@ abstract class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract ...@@ -31,15 +31,45 @@ abstract class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract
protected $_requiredIndexers = array(); protected $_requiredIndexers = array();
/** /**
* Retrieve required indexers for re-building * Original list of indexers required to build
* *
* @var array * @var array
*/ */
protected $_originalIndexers = array();
/**
* Retrieve required indexers for re-building
*
* @return array
*/
public function getRequiredIndexers() public function getRequiredIndexers()
{ {
return $this->_requiredIndexers; return $this->_requiredIndexers;
} }
/**
* Run required indexers and reset to original required indexers
*
* @return EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract
*/
public function runRequiredIndexers()
{
if (empty($this->_options['doNotIndexAll'])) {
$indexer = Mage::getSingleton('index/indexer');
foreach ($this->getRequiredIndexers() as $indexerCode) {
if (empty($this->_options['doNotIndex'])
|| !in_array($indexerCode, $this->_options['doNotIndex'])) {
$indexer->getProcessByCode($indexerCode)
->reindexAll();
}
}
}
// Restoring original required indexers for making tests isolated
$this->_requiredIndexers = $this->_originalIndexers;
return $this;
}
/** /**
* Add indexer by specific code to required indexers list * Add indexer by specific code to required indexers list
* *
...@@ -78,7 +108,7 @@ abstract class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract ...@@ -78,7 +108,7 @@ abstract class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract
*/ */
public function loadEntity($entityType, $values) public function loadEntity($entityType, $values)
{ {
$originalRequiredIndexers = $this->_requiredIndexers; $this->_originalIndexers = $this->_requiredIndexers;
if (!empty($this->_options['addRequiredIndex'])) { if (!empty($this->_options['addRequiredIndex'])) {
foreach ($this->_options['addRequiredIndex'] as $data) { foreach ($this->_options['addRequiredIndex'] as $data) {
if (preg_match('/^([a-z0-9_\\-])+\\s+([a-z0-9_\\-])\s*$/i', $data, $match) if (preg_match('/^([a-z0-9_\\-])+\\s+([a-z0-9_\\-])\s*$/i', $data, $match)
...@@ -182,19 +212,6 @@ abstract class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract ...@@ -182,19 +212,6 @@ abstract class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract
$this->_customEntityAction($entity, $entityTypeModel); $this->_customEntityAction($entity, $entityTypeModel);
} }
if (empty($this->_options['doNotIndexAll'])) {
$indexer = Mage::getSingleton('index/indexer');
foreach ($this->getRequiredIndexers() as $indexerCode) {
if (empty($this->_options['doNotIndex'])
|| !in_array($indexerCode, $this->_options['doNotIndex'])) {
$indexer->getProcessByCode($indexerCode)
->reindexAll();
}
}
}
// Restoring original required indexers for making tests isolated
$this->_requiredIndexers = $originalRequiredIndexers;
return $this; return $this;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment