/** * Process import step * * @return void */ protected function processImportStep() { $this->startImportStep(); $expire = time() + static::IMPORT_TTL; while (time() < $expire && !feof($this->filePointer)) { $row = fgetcsv($this->filePointer, 0, static::DELIMIER); $row = is_array($row) ? array_map('trim', $row) : array(); if ($row && preg_grep('/^.+$/Ss', $row)) { // Assemble associated list $list = $this->assembleImportRow($row); // Detect and get product $product = $this->getProduct($list); if (!$product->getId()) { if ($this->checkRequiredImportFields($list)) { \XLite\Core\Database::getEM()->persist($product); } else { $product = null; } } if ($product) { if (count($list) != $this->importCell['row_length']) { $this->logImportWarning(static::t('The string is different from that of the title number of columns - X instead of Y', array('right' => $this->importCell['row_length'], 'wrong' => count($list))), $this->importCell['position'], null, null, $product); } $this->importRow($product, $list); if (!$product->getId()) { $this->importCell['new']++; } \XLite\Core\Database::getEM()->flush(); } } $this->importCell['position']++; } if (feof($this->filePointer)) { \XLite\Core\Event::importFinish(); $this->postprocessImport(); $this->clearImportCell(); } else { \XLite\Core\Session::getInstance()->importCell = $this->importCell; $position = ftell($this->filePointer); fseek($this->filePointer, 0, SEEK_END); \XLite\Core\Event::importAfterStep(array('position' => $position, 'length' => ftell($this->filePointer))); } fclose($this->filePointer); }