Skip to content

Commit 7773777

Browse files
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents 87c3026 + 4653c84 commit 7773777

File tree

9 files changed

+97
-27
lines changed

9 files changed

+97
-27
lines changed

src/app/code/community/IntegerNet/Solr/Helper/Factory.php

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,8 @@ public function getProductIndexer()
8787
public function getSolrRequest($requestMode = self::REQUEST_MODE_AUTODETECT)
8888
{
8989
$storeId = Mage::app()->getStore()->getId();
90-
$config = new IntegerNet_Solr_Model_Config_Store($storeId);
91-
if ($config->getGeneralConfig()->isLog()) {
92-
$logger = $this->_getLogger();
93-
if ($logger instanceof IntegerNet_Solr_Helper_Log) {
94-
$logger->setFile('solr.log');
95-
}
96-
} else {
97-
$logger = new NullLogger;
98-
}
99-
10090
$isCategoryPage = Mage::helper('integernet_solr')->page()->isCategoryPage();
101-
$applicationContext = new ApplicationContext(
102-
$this->_getAttributeRepository(),
103-
$config->getResultsConfig(),
104-
$config->getAutosuggestConfig(),
105-
$this->_getEventDispatcher(),
106-
$logger
107-
);
91+
$applicationContext = $this->getApplicationContext();
10892
if (Mage::app()->getLayout() && $block = Mage::app()->getLayout()->getBlock('product_list_toolbar')) {
10993
$pagination = $this->_bridgeFactory->createPaginationToolbar($block);
11094
$applicationContext->setPagination($pagination);
@@ -131,7 +115,7 @@ public function getSolrRequest($requestMode = self::REQUEST_MODE_AUTODETECT)
131115
break;
132116
default:
133117
$applicationContext
134-
->setFuzzyConfig($config->getFuzzySearchConfig())
118+
->setFuzzyConfig($this->getCurrentStoreConfig()->getFuzzySearchConfig())
135119
->setQuery($this->_getSearchTermSynonymHelper());
136120
$factory = new SearchRequestFactory(
137121
$applicationContext,
@@ -197,6 +181,31 @@ protected function _getIndexCategoryRepository()
197181
return $this->_bridgeFactory->getIndexCategoryRepository();
198182
}
199183

184+
/**
185+
* @return ApplicationContext
186+
*/
187+
public function getApplicationContext()
188+
{
189+
$config = $this->getCurrentStoreConfig();
190+
if ($config->getGeneralConfig()->isLog()) {
191+
$logger = $this->_getLogger();
192+
if ($logger instanceof IntegerNet_Solr_Helper_Log) {
193+
$logger->setFile('solr.log');
194+
}
195+
} else {
196+
$logger = new NullLogger;
197+
}
198+
199+
$applicationContext = new ApplicationContext(
200+
$this->_getAttributeRepository(),
201+
$config->getResultsConfig(),
202+
$config->getAutosuggestConfig(),
203+
$this->_getEventDispatcher(),
204+
$logger
205+
);
206+
return $applicationContext;
207+
}
208+
200209
/**
201210
* @return IntegerNet_Solr_Model_Bridge_CategoryRepository
202211
*/

src/app/code/community/IntegerNet/Solr/Model/Bridge/Category.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function getPathExcludingCurrentCategory($separator)
107107
array_shift($pathIds);
108108
array_pop($pathIds);
109109
foreach($pathIds as $pathId) {
110-
$pathParts[] = $this->_category->getResource()->getAttributeRawValue($pathId, 'name', $this->getStoreId());
110+
$pathParts[] = Mage::getResourceModel('catalog/category')->getAttributeRawValue($pathId, 'name', $this->getStoreId());
111111
}
112112
return implode($separator, $pathParts);
113113
}

src/app/code/community/IntegerNet/Solr/Model/Bridge/StoreEmulation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public function stop()
5858

5959
if ($this->_isEmulated && $this->_initialEnvironmentInfo) {
6060
Mage::getSingleton('core/app_emulation')->stopEnvironmentEmulation($this->_initialEnvironmentInfo);
61+
$this->_isEmulated = false;
6162
}
6263
}
6364

src/app/code/community/IntegerNet/Solr/Model/Resource/Catalog/Product/Indexing/Collection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
*/
1010
class IntegerNet_Solr_Model_Resource_Catalog_Product_Indexing_Collection extends Mage_Catalog_Model_Resource_Product_Collection
1111
{
12+
public function isEnabledFlat()
13+
{
14+
return false;
15+
}
16+
1217
/**
1318
* Join Product Price Table
1419
* Join left by default in order to include products without price index entry

src/app/code/community/IntegerNet/Solr/Model/Resource/Db.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,24 @@ public function disconnectMysql()
1919
/** @var Zend_Db_Adapter_Abstract $connection */
2020
foreach (Mage::getSingleton('core/resource')->getConnections() as $name => $connection) {
2121
if ($connection instanceof Zend_Db_Adapter_Abstract) {
22+
if ($this->isTransactionOpen($connection)) {
23+
continue;
24+
}
2225
$connection->closeConnection();
2326
}
2427
}
2528
// connections (adapter objects) must be fully reinitialized, otherwise initStatements are not executed
2629
Mage::unregister('_singleton/core/resource');
2730
}
31+
32+
/**
33+
* Returns true if the given connection has open transactions
34+
*
35+
* @param Zend_Db_Adapter_Abstract $connection
36+
* @return bool
37+
*/
38+
private function isTransactionOpen(Zend_Db_Adapter_Abstract $connection)
39+
{
40+
return $connection instanceof Magento_Db_Adapter_Pdo_Mysql && $connection->isTransaction();
41+
}
2842
}

src/app/code/community/IntegerNet/Solr/Test/Controller/Abstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ abstract class IntegerNet_Solr_Test_Controller_Abstract extends EcomDev_PHPUnit_
1212
{
1313
public static function setUpBeforeClass()
1414
{
15-
Mage::register('isSecureArea', true);
15+
Mage::register('isSecureArea', true, true);
1616
}
1717
public static function tearDownAfterClass()
1818
{

src/app/code/community/IntegerNet/Solr/Test/Model/Indexer/Product.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @loadFixture registry
1515
* @loadFixture config
1616
*/
17-
class IntegerNet_Solr_Test_Model_Indexer_Product extends EcomDev_PHPUnit_Test_Case_Controller
17+
class IntegerNet_Solr_Test_Model_Indexer_Product extends IntegerNet_Solr_Test_Controller_Abstract
1818
{
1919
/**
2020
* @param array $config
@@ -35,4 +35,48 @@ public function invalidSwapConfigurationShouldThrowException(array $config)
3535
Mage::helper('integernet_solr')->factory()->getProductIndexer()->reindex();
3636
}
3737

38+
/**
39+
* @test
40+
* @loadFixture catalog
41+
*/
42+
public function saveProductShouldUpdateSolrIndex()
43+
{
44+
$this->setUpFreshIndex();
45+
46+
$this->assertCount(0, $this->searchInStore(1, 'SUPERDUPER')->documents());
47+
$productId = 21001;
48+
$this->setCurrentStore(0);
49+
$product = Mage::getModel('catalog/product')->load($productId);
50+
$product->setData('name', 'SUPERDUPER');
51+
$product->save();
52+
$searchResponse = $this->searchInStore(1, 'SUPERDUPER');
53+
$this->assertCount(1, $searchResponse->documents());
54+
}
55+
56+
/**
57+
* @param $queryText
58+
* @return \IntegerNet\Solr\Resource\SolrResponse
59+
*/
60+
public function searchInStore($storeId, $queryText)
61+
{
62+
$queryStub = $this->getMockBuilder(\IntegerNet\Solr\Implementor\HasUserQuery::class)
63+
->getMockForAbstractClass();
64+
$queryStub->method('getUserQueryText')->willReturn($queryText);
65+
$factory = Mage::helper('integernet_solr/factory');
66+
$applicationContext = $factory->getApplicationContext();
67+
$applicationContext->setFuzzyConfig($factory->getCurrentStoreConfig()->getFuzzySearchConfig());
68+
$applicationContext->setQuery($queryStub);
69+
$applicationContext->setPagination(new \IntegerNet\Solr\Request\SinglePage(2));
70+
$searchRequestFactory = new \IntegerNet\Solr\Request\SearchRequestFactory(
71+
$applicationContext,
72+
$factory->getSolrResource(),
73+
$storeId
74+
);
75+
return $searchRequestFactory->createRequest()->doRequest();
76+
}
77+
78+
private function setUpFreshIndex()
79+
{
80+
Mage::getModel('integernet_solr/indexer')->reindexAll();
81+
}
3882
}

src/app/code/community/IntegerNet/Solr/Test/fixtures/registry.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ registry:
77
- integernet_solr/factory
88
- integernet_solr/log
99
singleton:
10+
- eav/config
11+
- core/app_emulation
12+
- core/factory
1013
- catalog/layer
1114
- core/session
1215
- customer/session

src/app/design/frontend/base/default/layout/integernet/solr.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010
</default>
1111

1212
<catalogsearch_result_index>
13-
<reference name="head">
14-
<action method="addItem" ifconfig="integernet_solr/general/is_active">
15-
<type>skin_js</type>
16-
<name>integernet/solr/js/result.js</name>
17-
</action>
18-
</reference>
1913
<reference name="head">
2014
<action method="addItem" ifconfig="integernet_solr/general/is_active">
2115
<type>skin_js</type>

0 commit comments

Comments
 (0)