/** * @throws Gpf_Tasks_LongTaskInterrupt */ public function importCSV(){ Gpf_Log::info('Importing file' . $this->form->getFieldValue(self::FILENAME)); $transactionHeader = $this->getHeader(); $rowsList = $this->getDataFromFile(); $this->cache = new Pap_Merchants_Transaction_TransactionsImportCache(); $i = 0; while($this->row = $rowsList->readArray()) { $this->interruptIfMemoryFull(); if ($this->isPending($i, $this->_('Importing transactions'))) { if ($i == 0 && $this->form->getFieldValue(self::SKIP_FIRST_ROW) == Gpf::YES) { Gpf_Log::info('Skipping first row'); $this->row[]='errorMessage'; $this->errorHeader = $this->row; $i++; continue; } if(count($this->row)<=1) { Gpf_Log::info('Skipping empty row ' . $i); $i++; continue; } $transaction = $this->getTransactionObject(); try { $this->saveTransaction($transaction, $transactionHeader, $this->row); } catch (Gpf_DbEngine_DuplicateEntryException $e) { $this->addError($this->_('Duplicate row')); } catch (Gpf_Exception $e){ $this->addError($this->_($e->getMessage())); } $this->setDone(); } $i++; } Gpf_Log::info('Import complete'); if ($this->errorFile !== null) { $this->errorFile->close(); if($this->errorFile->isExists()) { Gpf_Log::warning('Error occured during import, please check ' . Gpf_Paths::getInstance()->getCacheAccountDirectory().self::ERROR_FILE); $this->form->setInfoMessage("Import was not successful<br /><a href='" . Gpf_Paths::getInstance()->getCacheAccountDirectory().self::ERROR_FILE. "'>" . $this->_("Download unimported .csv") . "</a><br /> (error messages are at the end of each line)"); } else{ $this->form->setInfoMessage("Import was successful"); } } else{ $this->form->setInfoMessage("Import was successful"); } $this->form->setErrorMessage($this->_('Import was not successful.')); $this->form->setSuccessful(); $this->cache->clearCache(); return $this->form; }