/** * Validate data rows and save bunches to DB. * * @return Mage_ImportExport_Model_Import_Entity_Abstract */ protected function _saveValidatedBunches() { $source = $this->_getSource(); $productDataSize = 0; $bunchRows = array(); $startNewBunch = false; $nextRowBackup = array(); $maxPacketData = $this->_connection->fetchRow('SHOW VARIABLES LIKE "max_allowed_packet"'); $maxPacket = empty($maxPacketData['Value']) ? self::DB_MAX_PACKET_DATA : $maxPacketData['Value']; // real-size to DB packet size coefficient $coefficient = self::DB_MAX_PACKET_COEFFICIENT / self::DB_MAX_PACKET_DATA; $maxPacket = $coefficient * $maxPacket; $source->rewind(); $this->_dataSourceModel->cleanBunches(); while ($source->valid() || $bunchRows) { if ($startNewBunch || !$source->valid()) { $this->_dataSourceModel->saveBunch($this->getEntityTypeCode(), $this->getBehavior(), $bunchRows); $bunchRows = $nextRowBackup; $productDataSize = strlen(serialize($bunchRows)); $startNewBunch = false; $nextRowBackup = array(); } if ($source->valid()) { if ($this->_errorsCount >= $this->_errorsLimit) { // errors limit check return; } $rowData = $source->current(); $this->_processedRowsCount++; if ($this->validateRow($rowData, $source->key())) { // add row to bunch for save $rowData = $this->_prepareRowForDb($rowData); $rowSize = strlen(serialize($rowData)); if ($productDataSize + $rowSize >= $maxPacket) { // check bunch size $startNewBunch = true; $nextRowBackup = array($source->key() => $rowData); } else { $bunchRows[$source->key()] = $rowData; $productDataSize += $rowSize; } } $source->next(); } } return $this; }
/** * Validate data rows and save bunches to DB. * * @return Mage_ImportExport_Model_Import_Entity_Abstract */ protected function _saveValidatedBunches() { $source = $this->_getSource(); $productDataSize = 0; $bunchRows = array(); $startNewBunch = false; $nextRowBackup = array(); $maxDataSize = Mage::getResourceHelper('importexport')->getMaxDataSize(); $bunchSize = Mage::helper('importexport')->getBunchSize(); /** @var Mage_Core_Helper_Data $coreHelper */ $coreHelper = Mage::helper("core"); $source->rewind(); $this->_dataSourceModel->cleanBunches(); while ($source->valid() || $bunchRows) { if ($startNewBunch || !$source->valid()) { $this->_dataSourceModel->saveBunch($this->getEntityTypeCode(), $this->getBehavior(), $bunchRows); $bunchRows = $nextRowBackup; $productDataSize = strlen(serialize($bunchRows)); $startNewBunch = false; $nextRowBackup = array(); } if ($source->valid()) { if ($this->_errorsCount >= $this->_errorsLimit) { // errors limit check return; } $rowData = $coreHelper->unEscapeCSVData($source->current()); $this->_processedRowsCount++; if ($this->validateRow($rowData, $source->key())) { // add row to bunch for save $rowData = $this->_prepareRowForDb($rowData); $rowSize = strlen(Mage::helper('core')->jsonEncode($rowData)); $isBunchSizeExceeded = $bunchSize > 0 && count($bunchRows) >= $bunchSize; if ($productDataSize + $rowSize >= $maxDataSize || $isBunchSizeExceeded) { $startNewBunch = true; $nextRowBackup = array($source->key() => $rowData); } else { $bunchRows[$source->key()] = $rowData; $productDataSize += $rowSize; } } $source->next(); } } return $this; }
/** * Validate data rows and save bunches to DB. * * @return Mage_ImportExport_Model_Import_Entity_Abstract */ protected function _saveValidatedBunches() { $source = $this->_getSource(); $productDataSize = 0; $bunchRows = array(); $startNewBunch = false; $nextRowBackup = array(); $maxDataSize = Mage::getResourceHelper('importexport')->getMaxDataSize(); $source->rewind(); $this->_dataSourceModel->cleanBunches(); while ($source->valid() || $bunchRows) { if ($startNewBunch || !$source->valid()) { $this->_dataSourceModel->saveBunch($this->getEntityTypeCode(), $this->getBehavior(), $bunchRows); $bunchRows = $nextRowBackup; $productDataSize = strlen(serialize($bunchRows)); $startNewBunch = false; $nextRowBackup = array(); } if ($source->valid()) { if ($this->_errorsCount >= $this->_errorsLimit) { // errors limit check return; } $rowData = $source->current(); $this->_processedRowsCount++; if ($this->validateRow($rowData, $source->key())) { // add row to bunch for save $rowData = $this->_prepareRowForDb($rowData); $rowSize = strlen(serialize($rowData)); if ($productDataSize + $rowSize >= $maxDataSize) { // check bunch size $startNewBunch = true; $nextRowBackup = array($source->key() => $rowData); } else { $bunchRows[$source->key()] = $rowData; $productDataSize += $rowSize; } } $source->next(); } } return $this; }