29 private $minValue = 0;
34 private $correlationName;
44 private $currentSelect;
54 private $iteration = 0;
59 private $rangeFieldAlias;
64 private $isValid =
true;
82 $this->batchSize = $batchSize;
84 $this->correlationName = $correlationName;
85 $this->rangeField = $rangeField;
86 $this->rangeFieldAlias = $rangeFieldAlias;
87 $this->connection =
$select->getConnection();
95 if (
null == $this->currentSelect) {
96 $this->currentSelect = $this->initSelectObject();
97 $itemsCount = $this->calculateBatchSize($this->currentSelect);
98 $this->isValid = $itemsCount > 0;
100 return $this->currentSelect;
108 if (
null == $this->currentSelect) {
111 $select = $this->initSelectObject();
112 $itemsCountInSelect = $this->calculateBatchSize($select);
113 $this->isValid = $itemsCountInSelect > 0;
114 if ($this->isValid) {
116 $this->currentSelect = $select;
118 $this->currentSelect =
null;
120 return $this->currentSelect;
128 return $this->iteration;
136 return $this->isValid;
145 $this->currentSelect =
null;
146 $this->iteration = 0;
147 $this->isValid =
true;
156 private function calculateBatchSize(
Select $select)
158 $wrapperSelect = $this->connection->select();
159 $wrapperSelect->from(
162 new \
Zend_Db_Expr(
'MAX(' . $this->rangeFieldAlias .
') as max'),
166 $row = $this->connection->fetchRow($wrapperSelect);
167 $this->minValue =
$row[
'max'];
168 return intval(
$row[
'cnt']);
176 private function initSelectObject()
178 $object = clone $this->select;
180 $this->connection->quoteIdentifier($this->correlationName)
181 .
'.' . $this->connection->quoteIdentifier($this->rangeField)
185 $object->limit($this->batchSize);
189 $object->order($this->correlationName .
'.' . $this->rangeField .
' ' . \
Magento\Framework\DB\
Select::SQL_ASC);
__construct(Select $select, $batchSize, $correlationName, $rangeField, $rangeFieldAlias)