Skip to content

Commit 44291c7

Browse files
committed
Merge branch 'develop'
2 parents 1c1b277 + 2a1d477 commit 44291c7

File tree

13 files changed

+192
-34
lines changed

13 files changed

+192
-34
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/ProductRepository.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ public function getProductAssociations($productIds)
5252
foreach ($groupedResourceTypeModel->getChildrenIdsForMultipleParents($productIds) as $parentId => $childrenIds) {
5353
$associations[$parentId] = $childrenIds;
5454
}
55+
56+
/** @var $bundleResourceTypeModel IntegerNet_Solr_Model_Resource_Catalog_Product_Type_Bundle */
57+
$bundleResourceTypeModel = Mage::getResourceModel('integernet_solr/catalog_product_type_bundle');
58+
// Don't use array_merge here due to performance reasons
59+
foreach ($bundleResourceTypeModel->getChildrenIdsForMultipleParents($productIds) as $parentId => $childrenIds) {
60+
$associations[$parentId] = $childrenIds;
61+
}
5562
return array_combine(array_keys($associations), array_map(
5663
function($parentId, $childrenIds) {
5764
return new \IntegerNet\Solr\Indexer\Data\ProductAssociation($parentId, $childrenIds);

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/Catalog/Layer.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ public function getProductCollection()
2020
return parent::getProductCollection();
2121
}
2222

23-
if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) {
24-
$collection = $this->_productCollections[$this->getCurrentCategory()->getId()];
25-
} else {
26-
$collection = Mage::getModel('integernet_solr/result_collection');
27-
$this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;
23+
$category = $this->getCurrentCategory();
24+
25+
if ($category->getData('solr_exclude')) {
26+
return parent::getProductCollection();
2827
}
29-
return $collection;
28+
29+
if (! isset($this->_productCollections[$category->getId()])) {
30+
$this->_productCollections[$category->getId()] = Mage::getModel('integernet_solr/result_collection');
31+
}
32+
33+
return $this->_productCollections[$category->getId()];
3034
}
3135

3236
/**
@@ -52,4 +56,4 @@ public function getFilterableAttributes()
5256
return $collection;
5357
}
5458

55-
}
59+
}

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
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* integer_net Magento Module
4+
*
5+
* @category IntegerNet
6+
* @package IntegerNet_Solr
7+
* @copyright Copyright (c) 2016 integer_net GmbH (http://www.integer-net.de/)
8+
* @author Andreas von Studnitz <avs@integer-net.de>
9+
*/
10+
class IntegerNet_Solr_Model_Resource_Catalog_Product_Type_Bundle extends Mage_Bundle_Model_Resource_Selection
11+
{
12+
/**
13+
* Retrieve Required children ids
14+
* Return grouped array, ex array(
15+
* group => array(ids)
16+
* )
17+
*
18+
* @param null|int[] $parentIds
19+
* @return int[][]
20+
*/
21+
public function getChildrenIdsForMultipleParents($parentIds)
22+
{
23+
$childrenIds = array();
24+
$adapter = $this->_getReadAdapter();
25+
$select = $adapter->select()
26+
->from(
27+
array('tbl_selection' => $this->getMainTable()),
28+
array('product_id', 'parent_product_id', 'option_id')
29+
)
30+
->join(
31+
array('e' => $this->getTable('catalog/product')),
32+
'e.entity_id = tbl_selection.product_id AND e.required_options=0',
33+
array()
34+
)
35+
->join(
36+
array('tbl_option' => $this->getTable('bundle/option')),
37+
'tbl_option.option_id = tbl_selection.option_id',
38+
array('required')
39+
);
40+
if (!is_null($parentIds)) {
41+
$select->where('tbl_selection.parent_product_id IN (?)', $parentIds);
42+
}
43+
44+
foreach ($this->_getReadAdapter()->fetchAll($select) as $row) {
45+
$childrenIds[$row['parent_product_id']][$row['product_id']] = $row['product_id'];
46+
}
47+
48+
return $childrenIds;
49+
}
50+
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +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
}
28+
// connections (adapter objects) must be fully reinitialized, otherwise initStatements are not executed
29+
Mage::unregister('_singleton/core/resource');
30+
}
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();
2541
}
2642
}

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
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* integer_net Magento Module
4+
*
5+
* @category IntegerNet
6+
* @package IntegerNet_Solr
7+
* @copyright Copyright (c) 2016 integer_net GmbH (http://www.integer-net.de/)
8+
* @author Fabian Schmengler <fs@integer-net.de>
9+
*/
10+
11+
/**
12+
* @loadFixture registry
13+
* @doNotIndexAll
14+
*/
15+
class IntegerNet_Solr_Test_Model_Resource_Db extends EcomDev_PHPUnit_Test_Case
16+
{
17+
public function testDisconnectUnsetsConnection()
18+
{
19+
Mage::getResourceModel('integernet_solr/db')->disconnectMysql();
20+
$this->assertEquals(
21+
[],
22+
Mage::getSingleton('core/resource')->getConnections()
23+
);
24+
}
25+
}

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)