Commit c732c13c authored by Chivy Lim's avatar Chivy Lim

Merge branch 'KIME-5706' into 'master'

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

See merge request !21
parents 6675670c fca8eea1
...@@ -15,6 +15,7 @@ use TYPO3\Flow\Annotations as Flow; ...@@ -15,6 +15,7 @@ use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Persistence\RepositoryInterface; use TYPO3\Flow\Persistence\RepositoryInterface;
use WE\SpreadsheetImport\Annotations\Mapping; use WE\SpreadsheetImport\Annotations\Mapping;
use WE\SpreadsheetImport\Domain\Model\SpreadsheetImport; use WE\SpreadsheetImport\Domain\Model\SpreadsheetImport;
use WE\SpreadsheetImport\Exception\Exception;
/** /**
* Service to handle the column mapping and the import itself * Service to handle the column mapping and the import itself
...@@ -212,6 +213,7 @@ class SpreadsheetImportService { ...@@ -212,6 +213,7 @@ class SpreadsheetImportService {
* SpreadsheetImport object. * SpreadsheetImport object.
* *
* @return void * @return void
* @throws \WE\SpreadsheetImport\Exception\Exception
*/ */
public function import() { public function import() {
$totalInserted = 0; $totalInserted = 0;
...@@ -221,6 +223,10 @@ class SpreadsheetImportService { ...@@ -221,6 +223,10 @@ class SpreadsheetImportService {
$objectRepository = $this->getDomainRepository(); $objectRepository = $this->getDomainRepository();
$objectValidator = $this->validatorResolver->getBaseValidatorConjunction($this->domain, self::VALIDATION_GROUPS); $objectValidator = $this->validatorResolver->getBaseValidatorConjunction($this->domain, self::VALIDATION_GROUPS);
$sheet = $this->getFileActiveSheet(); $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']); $persistRecordsChunkSize = intval($this->settings['persistRecordsChunkSize']);
$totalCount = 0; $totalCount = 0;
/** @var \PHPExcel_Worksheet_Row $row */ /** @var \PHPExcel_Worksheet_Row $row */
...@@ -271,6 +277,7 @@ class SpreadsheetImportService { ...@@ -271,6 +277,7 @@ class SpreadsheetImportService {
foreach ($notExistingObjects as $object) { foreach ($notExistingObjects as $object) {
$id = $this->persistenceManager->getIdentifierByObject($object); $id = $this->persistenceManager->getIdentifierByObject($object);
$this->log(vsprintf('Object %s deleted.', array($id)), LOG_INFO); $this->log(vsprintf('Object %s deleted.', array($id)), LOG_INFO);
$this->emitBeforeRemove($object);
$objectRepository->remove($object); $objectRepository->remove($object);
if (++$totalDeleted % $persistRecordsChunkSize === 0) { if (++$totalDeleted % $persistRecordsChunkSize === 0) {
$this->persistenceManager->persistAll(); $this->persistenceManager->persistAll();
...@@ -284,6 +291,13 @@ class SpreadsheetImportService { ...@@ -284,6 +291,13 @@ class SpreadsheetImportService {
$this->spreadsheetImport->setTotalDeleted($totalDeleted); $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. * Return the active sheet of a spreadsheet. Other potential sheets are ignored on the import.
* *
......
...@@ -3,3 +3,4 @@ WE: ...@@ -3,3 +3,4 @@ WE:
keepPastImportsThreasholdDays: 365 keepPastImportsThreasholdDays: 365
maxExecutionThreasholdMinutes: 720 maxExecutionThreasholdMinutes: 720
persistRecordsChunkSize: 100 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