Commit fca8eea1 authored by Chanthou Nim's avatar Chanthou Nim Committed by Chivy Lim

[TASK] Add option max record import and function before remove object

refs KIME-5706
parent 6675670c
......@@ -15,6 +15,7 @@ use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Persistence\RepositoryInterface;
use WE\SpreadsheetImport\Annotations\Mapping;
use WE\SpreadsheetImport\Domain\Model\SpreadsheetImport;
use WE\SpreadsheetImport\Exception\Exception;
/**
* Service to handle the column mapping and the import itself
......@@ -212,6 +213,7 @@ class SpreadsheetImportService {
* SpreadsheetImport object.
*
* @return void
* @throws \WE\SpreadsheetImport\Exception\Exception
*/
public function import() {
$totalInserted = 0;
......@@ -221,6 +223,10 @@ class SpreadsheetImportService {
$objectRepository = $this->getDomainRepository();
$objectValidator = $this->validatorResolver->getBaseValidatorConjunction($this->domain, self::VALIDATION_GROUPS);
$sheet = $this->getFileActiveSheet();
if ($sheet->getHighestRow() > $this->settings['maxImportRecord']) {
$this->log(vsprintf('Your file have %d records is over maximum records. Please change settings(WE.SpreadsheetImport.maxImportRecord) if you want to import this file.', array($sheet->getHighestRow(), $this->settings['maxImportRecord'])), LOG_INFO);
throw new Exception('Maximum records are reach.', 1471257692);
}
$persistRecordsChunkSize = intval($this->settings['persistRecordsChunkSize']);
$totalCount = 0;
/** @var \PHPExcel_Worksheet_Row $row */
......@@ -271,6 +277,7 @@ class SpreadsheetImportService {
foreach ($notExistingObjects as $object) {
$id = $this->persistenceManager->getIdentifierByObject($object);
$this->log(vsprintf('Object %s deleted.', array($id)), LOG_INFO);
$this->emitBeforeRemove($object);
$objectRepository->remove($object);
if (++$totalDeleted % $persistRecordsChunkSize === 0) {
$this->persistenceManager->persistAll();
......@@ -284,6 +291,13 @@ class SpreadsheetImportService {
$this->spreadsheetImport->setTotalDeleted($totalDeleted);
}
/**
* @param mixed $object
* @return void
* @Flow\Signal
*/
protected function emitBeforeRemove($object) {}
/**
* Return the active sheet of a spreadsheet. Other potential sheets are ignored on the import.
*
......
......@@ -3,3 +3,4 @@ WE:
keepPastImportsThreasholdDays: 365
maxExecutionThreasholdMinutes: 720
persistRecordsChunkSize: 100
maxImportRecord: 10000
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment