From 66a0607d8d781b2ae84c90e8afc3ad949706cf7a Mon Sep 17 00:00:00 2001 From: Stanislav Ilnytskyi Date: Thu, 26 Nov 2020 13:12:52 +0100 Subject: [PATCH 1/3] int type for price indexer --- .../Model/Indexer/ProductPriceIndexFilter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/CatalogInventory/Model/Indexer/ProductPriceIndexFilter.php b/app/code/Magento/CatalogInventory/Model/Indexer/ProductPriceIndexFilter.php index 2ad7ca9f14963..2b37c9099a0e6 100644 --- a/app/code/Magento/CatalogInventory/Model/Indexer/ProductPriceIndexFilter.php +++ b/app/code/Magento/CatalogInventory/Model/Indexer/ProductPriceIndexFilter.php @@ -105,7 +105,7 @@ public function modifyPrice(IndexTableStructure $priceTable, array $entityIds = } if (!empty($entityIds)) { - $select->where('stock_item.product_id in (?)', $entityIds, \Zend_Db::INT_TYPE); + $select->where('stock_item.product_id IN (?)', $entityIds, \Zend_Db::INT_TYPE); } $select->group('stock_item.product_id'); @@ -121,7 +121,7 @@ public function modifyPrice(IndexTableStructure $priceTable, array $entityIds = foreach ($batchSelectIterator as $select) { $productIds = null; foreach ($connection->query($select)->fetchAll() as $row) { - $productIds[] = $row['product_id']; + $productIds[] = (int) $row['product_id']; } if ($productIds !== null) { $where = [$priceTable->getEntityField() .' IN (?)' => $productIds]; From e7bd3acc0e39f94d090bf5450581016d61f2c5e5 Mon Sep 17 00:00:00 2001 From: Stanislav Ilnytskyi Date: Fri, 27 Nov 2020 08:36:42 +0100 Subject: [PATCH 2/3] add cast to int type in other places --- .../Model/Export/AdvancedPricing.php | 3 ++- .../Bundle/Model/ResourceModel/Selection.php | 3 ++- .../Indexer/Product/Price/AbstractAction.php | 13 ++++++----- .../Catalog/Model/ResourceModel/Attribute.php | 2 +- .../Catalog/Model/ResourceModel/Category.php | 3 ++- .../Catalog/Model/ResourceModel/Url.php | 22 ++++++++++++------- .../DataProvider/AttributeQuery.php | 2 +- .../Model/Indexer/Stock/AbstractAction.php | 4 ++-- .../Indexer/Stock/DefaultStock.php | 2 +- .../Model/ResourceModel/Stock/Status.php | 8 ++++--- .../CatalogRule/Model/ResourceModel/Rule.php | 2 +- .../Indexer/Stock/Configurable.php | 2 +- .../Product/Type/Configurable.php | 2 +- .../ResourceModel/Indexer/Stock/Grouped.php | 2 +- .../Product/Indexer/Price/Grouped.php | 2 +- .../Model/ResourceModel/Video.php | 3 ++- .../ResourceModel/Customer/Collection.php | 3 ++- 17 files changed, 47 insertions(+), 31 deletions(-) diff --git a/app/code/Magento/AdvancedPricingImportExport/Model/Export/AdvancedPricing.php b/app/code/Magento/AdvancedPricingImportExport/Model/Export/AdvancedPricing.php index af43562984134..b63141b510b85 100644 --- a/app/code/Magento/AdvancedPricingImportExport/Model/Export/AdvancedPricing.php +++ b/app/code/Magento/AdvancedPricingImportExport/Model/Export/AdvancedPricing.php @@ -486,7 +486,8 @@ private function fetchTierPrices(array $productIds): array ) ->where( 'ap.' . $productEntityLinkField . ' IN (?)', - $productIds + $productIds, + \Zend_Db::INT_TYPE ); if ($priceFromFilter !== null) { diff --git a/app/code/Magento/Bundle/Model/ResourceModel/Selection.php b/app/code/Magento/Bundle/Model/ResourceModel/Selection.php index ead687faff7bc..45018406277f9 100644 --- a/app/code/Magento/Bundle/Model/ResourceModel/Selection.php +++ b/app/code/Magento/Bundle/Model/ResourceModel/Selection.php @@ -145,7 +145,8 @@ public function getParentIdsByChild($childId) ['e.entity_id as parent_product_id'] )->where( $this->getMainTable() . '.product_id IN(?)', - $childId + $childId, + \Zend_Db::INT_TYPE ); return $connection->fetchCol($select); diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php b/app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php index f3a4b322e29df..404fd27232b93 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php @@ -465,10 +465,11 @@ protected function _copyRelationIndexData($parentIds, $excludeIds = null) [] )->where( 'e.entity_id IN(?)', - $parentIds + $parentIds, + \Zend_Db::INT_TYPE ); if (!empty($excludeIds)) { - $select->where('child_id NOT IN(?)', $excludeIds); + $select->where('child_id NOT IN(?)', $excludeIds, \Zend_Db::INT_TYPE); } $children = $this->getConnection()->fetchCol($select); @@ -479,7 +480,8 @@ protected function _copyRelationIndexData($parentIds, $excludeIds = null) $this->getIndexTargetTableByDimension($dimensions) )->where( 'entity_id IN(?)', - $children + $children, + \Zend_Db::INT_TYPE ); $query = $select->insertFromSelect($this->_defaultIndexerResource->getIdxTable(), [], false); $this->getConnection()->query($query); @@ -578,13 +580,14 @@ private function getParentProductsTypes(array $productsIds) ['e.entity_id as parent_id', 'type_id'] )->where( 'l.child_id IN(?)', - $productsIds + $productsIds, + \Zend_Db::INT_TYPE ); $pairs = $this->getConnection()->fetchPairs($select); $byType = []; foreach ($pairs as $productId => $productType) { - $byType[$productType][$productId] = $productId; + $byType[$productType][$productId] = (int)$productId; } return $byType; diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Attribute.php b/app/code/Magento/Catalog/Model/ResourceModel/Attribute.php index 203126cf1fd8c..03f1edea0ea77 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Attribute.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Attribute.php @@ -101,7 +101,7 @@ protected function _clearUselessAttributeValues(\Magento\Framework\Model\Abstrac $attributeStoreIds = array_keys($this->_storeManager->getStores()); if (!empty($attributeStoreIds)) { $delCondition = [ - 'attribute_id = ?' => $object->getId(), + 'attribute_id = ?' => (int)$object->getId(), 'store_id IN(?)' => $attributeStoreIds, ]; $this->getConnection()->delete($object->getBackendTable(), $delCondition); diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Category.php b/app/code/Magento/Catalog/Model/ResourceModel/Category.php index e19286efc38c0..ed2df0f10ac3b 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Category.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Category.php @@ -575,7 +575,8 @@ public function verifyIds(array $ids) 'entity_id' )->where( 'entity_id IN(?)', - $ids + $ids, + \Zend_Db::INT_TYPE ); return $this->getConnection()->fetchCol($select); diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Url.php b/app/code/Magento/Catalog/Model/ResourceModel/Url.php index be95f088a2477..eceae322fbd8e 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Url.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Url.php @@ -204,7 +204,8 @@ protected function _getCategoryAttribute($attributeCode, $categoryIds, $storeId) ['value' => $attributeCode, 'entity_id' => 'entity_id'] )->where( 'entity_id IN(?)', - $categoryIds + $categoryIds, + \Zend_Db::INT_TYPE ); } elseif ($this->_categoryAttributes[$attributeCode]['is_global'] || $storeId == 0) { $select->from( @@ -216,7 +217,8 @@ protected function _getCategoryAttribute($attributeCode, $categoryIds, $storeId) ['value'] )->where( "t1.{$identifierFiled} IN(?)", - $categoryIds + $categoryIds, + \Zend_Db::INT_TYPE )->where( 'e.attribute_id = :attribute_id' )->where( @@ -245,7 +247,8 @@ protected function _getCategoryAttribute($attributeCode, $categoryIds, $storeId) 't1.attribute_id = :attribute_id' )->where( "e.entity_id IN(?)", - $categoryIds + $categoryIds, + \Zend_Db::INT_TYPE )->group('e.entity_id'); $bind['attribute_id'] = $this->_categoryAttributes[$attributeCode]['attribute_id']; @@ -308,7 +311,8 @@ public function _getProductAttribute($attributeCode, $productIds, $storeId) 0 )->where( 'entity_id IN(?)', - $productIds + $productIds, + \Zend_Db::INT_TYPE ); } else { $valueExpr = $connection->getCheckSql('t2.value_id > 0', 't2.value', 't1.value'); @@ -326,7 +330,8 @@ public function _getProductAttribute($attributeCode, $productIds, $storeId) 't1.attribute_id = :attribute_id' )->where( 't1.entity_id IN(?)', - $productIds + $productIds, + \Zend_Db::INT_TYPE ); $bind['store_id'] = $storeId; } @@ -430,7 +435,7 @@ protected function _getCategories($categoryIds, $storeId = null, $path = null) // Prepare variables for checking whether categories belong to store if ($path === null) { - $select->where('main_table.entity_id IN(?)', $categoryIds); + $select->where('main_table.entity_id IN(?)', $categoryIds, \Zend_Db::INT_TYPE); } else { // Ensure that path ends with '/', otherwise we can get wrong results - e.g. $path = '1/2' will get '1/20' if (substr($path, -1) != '/') { @@ -569,7 +574,7 @@ protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId $this->_productLimit ); if ($productIds !== null) { - $select->where('e.entity_id IN(?)', $productIds); + $select->where('e.entity_id IN(?)', $productIds, \Zend_Db::INT_TYPE); } $rowSet = $connection->fetchAll($select, $bind); @@ -591,7 +596,8 @@ protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId ['product_id', 'category_id'] )->where( 'product_id IN(?)', - array_keys($products) + array_keys($products), + \Zend_Db::INT_TYPE ); $categories = $connection->fetchAll($select); foreach ($categories as $category) { diff --git a/app/code/Magento/CatalogGraphQl/DataProvider/AttributeQuery.php b/app/code/Magento/CatalogGraphQl/DataProvider/AttributeQuery.php index b0f085932bb8e..201c70913ca39 100644 --- a/app/code/Magento/CatalogGraphQl/DataProvider/AttributeQuery.php +++ b/app/code/Magento/CatalogGraphQl/DataProvider/AttributeQuery.php @@ -148,7 +148,7 @@ private function getAttributesFromEntityTable( ): Select { $select = $connection->select() ->from(['e' => $entityTableName], $entityTableAttributes) - ->where('e.entity_id IN (?)', $entityIds); + ->where('e.entity_id IN (?)', $entityIds, \Zend_Db::INT_TYPE); return $select; } diff --git a/app/code/Magento/CatalogInventory/Model/Indexer/Stock/AbstractAction.php b/app/code/Magento/CatalogInventory/Model/Indexer/Stock/AbstractAction.php index 4ea6b6bcfde9a..0b5f248331bfd 100644 --- a/app/code/Magento/CatalogInventory/Model/Indexer/Stock/AbstractAction.php +++ b/app/code/Magento/CatalogInventory/Model/Indexer/Stock/AbstractAction.php @@ -167,7 +167,7 @@ public function getRelationsByChild($childIds) )->join( ['relation' => $this->_getTable('catalog_product_relation')], 'relation.parent_id = cpe.' . $linkField - )->where('child_id IN(?)', $childIds); + )->where('child_id IN(?)', $childIds, \Zend_Db::INT_TYPE); return $connection->fetchCol($select); } @@ -262,7 +262,7 @@ private function doReindex($productIds = []) // retrieve product types by processIds $select = $connection->select() ->from($this->_getTable('catalog_product_entity'), ['entity_id', 'type_id']) - ->where('entity_id IN(?)', $productIds); + ->where('entity_id IN(?)', $productIds, \Zend_Db::INT_TYPE); $pairs = $connection->fetchPairs($select); $byType = []; diff --git a/app/code/Magento/CatalogInventory/Model/ResourceModel/Indexer/Stock/DefaultStock.php b/app/code/Magento/CatalogInventory/Model/ResourceModel/Indexer/Stock/DefaultStock.php index c151e5897abd5..dec18044b699e 100644 --- a/app/code/Magento/CatalogInventory/Model/ResourceModel/Indexer/Stock/DefaultStock.php +++ b/app/code/Magento/CatalogInventory/Model/ResourceModel/Indexer/Stock/DefaultStock.php @@ -261,7 +261,7 @@ protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = f $select->columns(['status' => $this->getStatusExpression($connection, true)]); if ($entityIds !== null) { - $select->where('e.entity_id IN(?)', $entityIds); + $select->where('e.entity_id IN(?)', $entityIds, \Zend_Db::INT_TYPE); } return $select; diff --git a/app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Status.php b/app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Status.php index 02e443d09b228..afb7d51335df8 100644 --- a/app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Status.php +++ b/app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Status.php @@ -153,7 +153,7 @@ public function getProductsStockStatuses($productIds, $websiteId, $stockId = Sto $select = $this->getConnection()->select() ->from($this->getMainTable(), ['product_id', 'stock_status']) - ->where('product_id IN(?)', $productIds) + ->where('product_id IN(?)', $productIds, \Zend_Db::INT_TYPE) ->where('stock_id=?', (int) $stockId) ->where('website_id=?', (int) $websiteId); return $this->getConnection()->fetchPairs($select); @@ -190,7 +190,8 @@ public function getProductsType($productIds) ['entity_id', 'type_id'] )->where( 'entity_id IN(?)', - $productIds + $productIds, + \Zend_Db::INT_TYPE ); return $this->getConnection()->fetchPairs($select); } @@ -360,7 +361,8 @@ public function getProductStatus($productIds, $storeId = null) $attribute->getAttributeId() )->where( "t1.{$linkField} IN(?)", - $productIds + $productIds, + \Zend_Db::INT_TYPE ); $rows = $connection->fetchPairs($select); diff --git a/app/code/Magento/CatalogRule/Model/ResourceModel/Rule.php b/app/code/Magento/CatalogRule/Model/ResourceModel/Rule.php index 662cdede84ede..dd4f3306b8603 100644 --- a/app/code/Magento/CatalogRule/Model/ResourceModel/Rule.php +++ b/app/code/Magento/CatalogRule/Model/ResourceModel/Rule.php @@ -187,7 +187,7 @@ public function getRulePrices(\DateTimeInterface $date, $websiteId, $customerGro ->where('rule_date = ?', $date->format('Y-m-d')) ->where('website_id = ?', $websiteId) ->where('customer_group_id = ?', $customerGroupId) - ->where('product_id IN(?)', $productIds); + ->where('product_id IN(?)', $productIds, \Zend_Db::INT_TYPE); return $connection->fetchPairs($select); } diff --git a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Indexer/Stock/Configurable.php b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Indexer/Stock/Configurable.php index 39fcdf86fdcf4..29c4812cc7b96 100644 --- a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Indexer/Stock/Configurable.php +++ b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Indexer/Stock/Configurable.php @@ -101,7 +101,7 @@ protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = f $select->columns(['status' => $stockStatusExpr]); if ($entityIds !== null) { - $select->where('e.entity_id IN(?)', $entityIds); + $select->where('e.entity_id IN(?)', $entityIds, \Zend_Db::INT_TYPE); } return $select; diff --git a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Type/Configurable.php b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Type/Configurable.php index 9d779d9704c29..0dd38062e5a65 100644 --- a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Type/Configurable.php +++ b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Type/Configurable.php @@ -203,7 +203,7 @@ public function getParentIdsByChild($childId) ['e' => $this->getTable('catalog_product_entity')], 'e.' . $this->optionProvider->getProductEntityLinkField() . ' = l.parent_id', ['e.entity_id'] - )->where('l.product_id IN(?)', $childId); + )->where('l.product_id IN(?)', $childId, \Zend_Db::INT_TYPE); $parentIds = $this->getConnection()->fetchCol($select); return $parentIds; diff --git a/app/code/Magento/GroupedProduct/Model/ResourceModel/Indexer/Stock/Grouped.php b/app/code/Magento/GroupedProduct/Model/ResourceModel/Indexer/Stock/Grouped.php index 9d29b02f68bf1..b2a8a361564e0 100644 --- a/app/code/Magento/GroupedProduct/Model/ResourceModel/Indexer/Stock/Grouped.php +++ b/app/code/Magento/GroupedProduct/Model/ResourceModel/Indexer/Stock/Grouped.php @@ -94,7 +94,7 @@ protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = f $select->columns(['status' => $stockStatusExpr]); if ($entityIds !== null) { - $select->where('e.entity_id IN(?)', $entityIds); + $select->where('e.entity_id IN(?)', $entityIds, \Zend_Db::INT_TYPE); } return $select; diff --git a/app/code/Magento/GroupedProduct/Model/ResourceModel/Product/Indexer/Price/Grouped.php b/app/code/Magento/GroupedProduct/Model/ResourceModel/Product/Indexer/Price/Grouped.php index c5f0316feb126..4c24cdb752d3c 100644 --- a/app/code/Magento/GroupedProduct/Model/ResourceModel/Product/Indexer/Price/Grouped.php +++ b/app/code/Magento/GroupedProduct/Model/ResourceModel/Product/Indexer/Price/Grouped.php @@ -166,7 +166,7 @@ private function prepareGroupedProductPriceDataSelect(array $dimensions, array $ ); if ($entityIds !== null) { - $select->where('e.entity_id IN(?)', $entityIds); + $select->where('e.entity_id IN(?)', $entityIds, \Zend_Db::INT_TYPE); } return $select; diff --git a/app/code/Magento/ProductVideo/Model/ResourceModel/Video.php b/app/code/Magento/ProductVideo/Model/ResourceModel/Video.php index 68b593f335797..42fdf8265ee83 100644 --- a/app/code/Magento/ProductVideo/Model/ResourceModel/Video.php +++ b/app/code/Magento/ProductVideo/Model/ResourceModel/Video.php @@ -39,7 +39,8 @@ public function loadByIds(array $ids) $this->getMainTable() )->where( 'value_id IN(?)', - $ids + $ids, + \Zend_Db::INT_TYPE ); return $this->getConnection()->fetchAll($select); diff --git a/app/code/Magento/Reports/Model/ResourceModel/Customer/Collection.php b/app/code/Magento/Reports/Model/ResourceModel/Customer/Collection.php index b6e55af96f4c1..a346ad4ede29b 100644 --- a/app/code/Magento/Reports/Model/ResourceModel/Customer/Collection.php +++ b/app/code/Magento/Reports/Model/ResourceModel/Customer/Collection.php @@ -213,7 +213,8 @@ protected function _addOrdersStatistics() \Magento\Sales\Model\Order::STATE_CANCELED )->where( 'orders.customer_id IN(?)', - $customerIds + $customerIds, + \Zend_Db::INT_TYPE )->group( 'orders.customer_id' ); From 14b9169b13e1a033a2d185ff2c47ceeefc8bef48 Mon Sep 17 00:00:00 2001 From: Stanislav Ilnytskyi Date: Tue, 1 Dec 2020 10:06:51 +0100 Subject: [PATCH 3/3] fix unit test --- .../Test/Unit/Model/Indexer/ProductPriceIndexFilterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/ProductPriceIndexFilterTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/ProductPriceIndexFilterTest.php index 0f3d8be212e30..090a74afca050 100644 --- a/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/ProductPriceIndexFilterTest.php +++ b/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/ProductPriceIndexFilterTest.php @@ -82,7 +82,7 @@ public function testModifyPrice() $connectionMock->expects($this->once())->method('select')->willReturn($selectMock); $selectMock->expects($this->at(2)) ->method('where') - ->with('stock_item.product_id in (?)', $entityIds) + ->with('stock_item.product_id IN (?)', $entityIds) ->willReturn($selectMock); $this->generator->expects($this->once()) ->method('generate')