Skip to content

Add INT types in some WHERE IN (?) expressions #31098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ private function fetchTierPrices(array $productIds): array
)
->where(
'ap.' . $productEntityLinkField . ' IN (?)',
$productIds
$productIds,
\Zend_Db::INT_TYPE
);

if ($priceFromFilter !== null) {
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Bundle/Model/ResourceModel/Selection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Model/ResourceModel/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Catalog/Model/ResourceModel/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 14 additions & 8 deletions app/code/Magento/Catalog/Model/ResourceModel/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -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');
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) != '/') {
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/CatalogRule/Model/ResourceModel/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/ProductVideo/Model/ResourceModel/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
Expand Down