Skip to content

Commit 5a95706

Browse files
authored
bugfix (#4259)
1 parent 7f61f77 commit 5a95706

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

app/code/core/Mage/Catalog/Model/Resource/Url.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ public function getLastUsedRewriteRequestIncrement($prefix, $suffix, $storeId)
184184
$select = $adapter->select()
185185
->from($this->getMainTable(), new Zend_Db_Expr('MAX(' . $urlIncrementPartExpression . ')'))
186186
->where('store_id = :store_id')
187+
// phpcs:ignore Ecg.Sql.SlowQuery.SlowRawSql
187188
->where('request_path LIKE :request_path')
188189
->where($adapter->prepareSqlCondition('request_path', [
189190
'regexp' => '^' . preg_quote($prefix) . '[0-9]*' . preg_quote($suffix) . '$'
@@ -264,6 +265,7 @@ public function prepareRewrites($storeId, $categoryIds = null, $productIds = nul
264265
$select->where('product_id IN(?)', $productIds);
265266
}
266267

268+
// phpcs:ignore Ecg.Performance.FetchAll.Found
267269
$rowSet = $adapter->fetchAll($select, $bind);
268270

269271
foreach ($rowSet as $row) {
@@ -467,6 +469,7 @@ protected function _getCategoryAttribute($attributeCode, $categoryIds, $storeId)
467469
$bind['store_id'] = $storeId;
468470
}
469471

472+
// phpcs:ignore Ecg.Performance.FetchAll.Found
470473
$rowSet = $adapter->fetchAll($select, $bind);
471474

472475
$attributes = [];
@@ -608,6 +611,7 @@ public function _getProductAttribute($attributeCode, $productIds, $storeId)
608611
$bind['store_id'] = $storeId;
609612
}
610613

614+
// phpcs:ignore Ecg.Performance.FetchAll.Found
611615
$rowSet = $adapter->fetchAll($select, $bind);
612616

613617
$attributes = [];
@@ -672,7 +676,7 @@ protected function _prepareStoreRootCategories($stores)
672676
* Retrieve categories objects
673677
* Either $categoryIds or $path (with ending slash) must be specified
674678
*
675-
* @param int|array $categoryIds
679+
* @param int|array|null $categoryIds
676680
* @param int $storeId
677681
* @param string $path
678682
* @return array
@@ -706,6 +710,7 @@ protected function _getCategories($categoryIds, $storeId = null, $path = null)
706710
}
707711

708712
$select
713+
// phpcs:ignore Ecg.Sql.SlowQuery.SlowRawSql
709714
->where('main_table.path LIKE ?', $path . '%')
710715
->order('main_table.path');
711716
}
@@ -730,6 +735,7 @@ protected function _getCategories($categoryIds, $storeId = null, $path = null)
730735
'store_id' => (int)$storeId
731736
];
732737

738+
// phpcs:ignore Ecg.Performance.FetchAll.Found
733739
$rowSet = $adapter->fetchAll($select, $bind);
734740
foreach ($rowSet as $row) {
735741
if ($storeId !== null) {
@@ -856,9 +862,11 @@ public function getRootChildrenIds($categoryId, $categoryPath, $includeStart = t
856862
$adapter = $this->_getReadAdapter();
857863
$select = $adapter->select()
858864
->from([$this->getTable('catalog/category')], ['entity_id'])
865+
// phpcs:ignore Ecg.Sql.SlowQuery.SlowRawSql
859866
->where('path LIKE ?', $categoryPath . '/%');
860867

861868
$categoryIds = [];
869+
// phpcs:ignore Ecg.Performance.FetchAll.Found
862870
$rowSet = $adapter->fetchAll($select);
863871
foreach ($rowSet as $row) {
864872
$categoryIds[$row['entity_id']] = $row['entity_id'];
@@ -918,7 +926,7 @@ public function getProductIdsByCategory($category)
918926
/**
919927
* Retrieve Product data objects
920928
*
921-
* @param int|array $productIds
929+
* @param int|array|null $productIds
922930
* @param int $storeId
923931
* @param int $entityId
924932
* @param int $lastEntityId
@@ -953,6 +961,7 @@ protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId
953961
$select->where('e.entity_id IN(?)', $productIds);
954962
}
955963

964+
// phpcs:ignore Ecg.Performance.FetchAll.Found
956965
$rowSet = $adapter->fetchAll($select, $bind);
957966
foreach ($rowSet as $row) {
958967
$product = new Varien_Object($row);
@@ -972,6 +981,7 @@ protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId
972981
['product_id', 'category_id']
973982
)
974983
->where('product_id IN(?)', array_keys($products));
984+
// phpcs:ignore Ecg.Performance.FetchAll.Found
975985
$categories = $adapter->fetchAll($select);
976986
foreach ($categories as $category) {
977987
$productId = $category['product_id'];
@@ -1103,13 +1113,17 @@ public function clearStoreCategoriesInvalidRewrites($storeId)
11031113
{
11041114
// Form a list of all current store categories ids
11051115
$store = $this->getStores($storeId);
1116+
if (!$store instanceof Mage_Core_Model_Store) {
1117+
return $this;
1118+
}
1119+
11061120
$rootCategoryId = $store->getRootCategoryId();
11071121
if (!$rootCategoryId) {
11081122
return $this;
11091123
}
11101124
$categoryIds = $this->getRootChildrenIds($rootCategoryId, $store->getRootCategoryPath());
11111125

1112-
// Remove all store catalog rewrites that are for some category or cartegory/product not within store categories
1126+
// Remove all store catalog rewrites that are for some category or category/product not within store categories
11131127
$where = [
11141128
'store_id = ?' => $storeId,
11151129
'category_id IS NOT NULL', // For sure check that it's a catalog rewrite
@@ -1136,6 +1150,10 @@ public function clearStoreCategoriesInvalidRewrites($storeId)
11361150
public function clearStoreProductsInvalidRewrites($storeId, $productId = null)
11371151
{
11381152
$store = $this->getStores($storeId);
1153+
if (!$store instanceof Mage_Core_Model_Store) {
1154+
return $this;
1155+
}
1156+
11391157
$adapter = $this->_getReadAdapter();
11401158
$bind = [
11411159
'website_id' => (int)$store->getWebsiteId(),
@@ -1269,6 +1287,7 @@ public function getRewriteByProductStore(array $products)
12691287
$select->orWhere($cond);
12701288
}
12711289

1290+
// phpcs:ignore Ecg.Performance.FetchAll.Found
12721291
$rowSet = $adapter->fetchAll($select, $bind);
12731292
foreach ($rowSet as $row) {
12741293
$result[$row['product_id']] = [

app/code/core/Mage/Catalog/Model/Url.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,10 @@ public function refreshRewrites($storeId = null)
236236
}
237237

238238
$this->clearStoreInvalidRewrites($storeId);
239-
$this->refreshCategoryRewrite($this->getStores($storeId)->getRootCategoryId(), $storeId, false);
239+
$store = $this->getStores($storeId);
240+
if ($store instanceof Mage_Core_Model_Store) {
241+
$this->refreshCategoryRewrite($store->getRootCategoryId(), $storeId, false);
242+
}
240243
$this->refreshProductRewrites($storeId);
241244
$this->getResource()->clearCategoryProduct($storeId);
242245

@@ -504,9 +507,14 @@ public function refreshProductRewrite($productId, $storeId = null)
504507
*/
505508
public function refreshProductRewrites($storeId)
506509
{
510+
$store = $this->getStores($storeId);
511+
if (!$store instanceof Mage_Core_Model_Store) {
512+
return $this;
513+
}
514+
507515
$this->_categories = [];
508-
$storeRootCategoryId = $this->getStores($storeId)->getRootCategoryId();
509-
$storeRootCategoryPath = $this->getStores($storeId)->getRootCategoryPath();
516+
$storeRootCategoryId = $store->getRootCategoryId();
517+
$storeRootCategoryPath = $store->getRootCategoryPath();
510518
$this->_categories[$storeRootCategoryId] = $this->getResource()->getCategory($storeRootCategoryId, $storeId);
511519

512520
$lastEntityId = 0;

0 commit comments

Comments
 (0)