diff --git a/app/code/core/Mage/Catalog/Model/Resource/Url.php b/app/code/core/Mage/Catalog/Model/Resource/Url.php index b72db8f572d..275d7e873c1 100644 --- a/app/code/core/Mage/Catalog/Model/Resource/Url.php +++ b/app/code/core/Mage/Catalog/Model/Resource/Url.php @@ -184,6 +184,7 @@ public function getLastUsedRewriteRequestIncrement($prefix, $suffix, $storeId) $select = $adapter->select() ->from($this->getMainTable(), new Zend_Db_Expr('MAX(' . $urlIncrementPartExpression . ')')) ->where('store_id = :store_id') + // phpcs:ignore Ecg.Sql.SlowQuery.SlowRawSql ->where('request_path LIKE :request_path') ->where($adapter->prepareSqlCondition('request_path', [ 'regexp' => '^' . preg_quote($prefix) . '[0-9]*' . preg_quote($suffix) . '$' @@ -264,6 +265,7 @@ public function prepareRewrites($storeId, $categoryIds = null, $productIds = nul $select->where('product_id IN(?)', $productIds); } + // phpcs:ignore Ecg.Performance.FetchAll.Found $rowSet = $adapter->fetchAll($select, $bind); foreach ($rowSet as $row) { @@ -467,6 +469,7 @@ protected function _getCategoryAttribute($attributeCode, $categoryIds, $storeId) $bind['store_id'] = $storeId; } + // phpcs:ignore Ecg.Performance.FetchAll.Found $rowSet = $adapter->fetchAll($select, $bind); $attributes = []; @@ -608,6 +611,7 @@ public function _getProductAttribute($attributeCode, $productIds, $storeId) $bind['store_id'] = $storeId; } + // phpcs:ignore Ecg.Performance.FetchAll.Found $rowSet = $adapter->fetchAll($select, $bind); $attributes = []; @@ -672,7 +676,7 @@ protected function _prepareStoreRootCategories($stores) * Retrieve categories objects * Either $categoryIds or $path (with ending slash) must be specified * - * @param int|array $categoryIds + * @param int|array|null $categoryIds * @param int $storeId * @param string $path * @return array @@ -706,6 +710,7 @@ protected function _getCategories($categoryIds, $storeId = null, $path = null) } $select + // phpcs:ignore Ecg.Sql.SlowQuery.SlowRawSql ->where('main_table.path LIKE ?', $path . '%') ->order('main_table.path'); } @@ -730,6 +735,7 @@ protected function _getCategories($categoryIds, $storeId = null, $path = null) 'store_id' => (int)$storeId ]; + // phpcs:ignore Ecg.Performance.FetchAll.Found $rowSet = $adapter->fetchAll($select, $bind); foreach ($rowSet as $row) { if ($storeId !== null) { @@ -856,9 +862,11 @@ public function getRootChildrenIds($categoryId, $categoryPath, $includeStart = t $adapter = $this->_getReadAdapter(); $select = $adapter->select() ->from([$this->getTable('catalog/category')], ['entity_id']) + // phpcs:ignore Ecg.Sql.SlowQuery.SlowRawSql ->where('path LIKE ?', $categoryPath . '/%'); $categoryIds = []; + // phpcs:ignore Ecg.Performance.FetchAll.Found $rowSet = $adapter->fetchAll($select); foreach ($rowSet as $row) { $categoryIds[$row['entity_id']] = $row['entity_id']; @@ -918,7 +926,7 @@ public function getProductIdsByCategory($category) /** * Retrieve Product data objects * - * @param int|array $productIds + * @param int|array|null $productIds * @param int $storeId * @param int $entityId * @param int $lastEntityId @@ -953,6 +961,7 @@ protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId $select->where('e.entity_id IN(?)', $productIds); } + // phpcs:ignore Ecg.Performance.FetchAll.Found $rowSet = $adapter->fetchAll($select, $bind); foreach ($rowSet as $row) { $product = new Varien_Object($row); @@ -972,6 +981,7 @@ protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId ['product_id', 'category_id'] ) ->where('product_id IN(?)', array_keys($products)); + // phpcs:ignore Ecg.Performance.FetchAll.Found $categories = $adapter->fetchAll($select); foreach ($categories as $category) { $productId = $category['product_id']; @@ -1103,13 +1113,17 @@ public function clearStoreCategoriesInvalidRewrites($storeId) { // Form a list of all current store categories ids $store = $this->getStores($storeId); + if (!$store instanceof Mage_Core_Model_Store) { + return $this; + } + $rootCategoryId = $store->getRootCategoryId(); if (!$rootCategoryId) { return $this; } $categoryIds = $this->getRootChildrenIds($rootCategoryId, $store->getRootCategoryPath()); - // Remove all store catalog rewrites that are for some category or cartegory/product not within store categories + // Remove all store catalog rewrites that are for some category or category/product not within store categories $where = [ 'store_id = ?' => $storeId, 'category_id IS NOT NULL', // For sure check that it's a catalog rewrite @@ -1136,6 +1150,10 @@ public function clearStoreCategoriesInvalidRewrites($storeId) public function clearStoreProductsInvalidRewrites($storeId, $productId = null) { $store = $this->getStores($storeId); + if (!$store instanceof Mage_Core_Model_Store) { + return $this; + } + $adapter = $this->_getReadAdapter(); $bind = [ 'website_id' => (int)$store->getWebsiteId(), @@ -1269,6 +1287,7 @@ public function getRewriteByProductStore(array $products) $select->orWhere($cond); } + // phpcs:ignore Ecg.Performance.FetchAll.Found $rowSet = $adapter->fetchAll($select, $bind); foreach ($rowSet as $row) { $result[$row['product_id']] = [ diff --git a/app/code/core/Mage/Catalog/Model/Url.php b/app/code/core/Mage/Catalog/Model/Url.php index 7fe943684dc..f063239148c 100644 --- a/app/code/core/Mage/Catalog/Model/Url.php +++ b/app/code/core/Mage/Catalog/Model/Url.php @@ -236,7 +236,10 @@ public function refreshRewrites($storeId = null) } $this->clearStoreInvalidRewrites($storeId); - $this->refreshCategoryRewrite($this->getStores($storeId)->getRootCategoryId(), $storeId, false); + $store = $this->getStores($storeId); + if ($store instanceof Mage_Core_Model_Store) { + $this->refreshCategoryRewrite($store->getRootCategoryId(), $storeId, false); + } $this->refreshProductRewrites($storeId); $this->getResource()->clearCategoryProduct($storeId); @@ -504,9 +507,14 @@ public function refreshProductRewrite($productId, $storeId = null) */ public function refreshProductRewrites($storeId) { + $store = $this->getStores($storeId); + if (!$store instanceof Mage_Core_Model_Store) { + return $this; + } + $this->_categories = []; - $storeRootCategoryId = $this->getStores($storeId)->getRootCategoryId(); - $storeRootCategoryPath = $this->getStores($storeId)->getRootCategoryPath(); + $storeRootCategoryId = $store->getRootCategoryId(); + $storeRootCategoryPath = $store->getRootCategoryPath(); $this->_categories[$storeRootCategoryId] = $this->getResource()->getCategory($storeRootCategoryId, $storeId); $lastEntityId = 0;