Commit 886ad68d authored by Chivy Lim's avatar Chivy Lim

[TASK] Force DB persist by specific amount of records

refs KIME-3603
parent c6ecbfd1
......@@ -190,6 +190,8 @@ class SpreadsheetImportService {
$identifierProperties = $this->getDomainMappingIdentifierProperties();
$file = $this->spreadsheetImport->getFile()->createTemporaryLocalCopy();
$reader = \PHPExcel_IOFactory::load($file);
$numberOfRecordsToPersist = $this->settings['numberOfRecordsToPersist'];
$i = 0;
/** @var \PHPExcel_Worksheet_Row $row */
foreach ($reader->getActiveSheet()->getRowIterator(2) as $row) {
$object = $this->findObjectByIdentifierPropertiesPerRow($identifierProperties, $row);
......@@ -199,6 +201,7 @@ class SpreadsheetImportService {
$this->setObjectPropertiesByRow($object, $row);
$objectRepository->update($object);
$totalUpdated++;
$i++;
} else {
$totalSkipped++;
}
......@@ -208,17 +211,28 @@ class SpreadsheetImportService {
$objectRepository->add($newObject);
$objectIds[] = $this->persistenceManager->getIdentifierByObject($newObject);
$totalInserted++;
$i++;
} else {
$totalSkipped++;
}
if ($i >= $numberOfRecordsToPersist) {
$this->persistenceManager->persistAll();
$i = 0;
}
}
// remove objects which are not exist on the spreadsheet
if ($this->spreadsheetImport->isDeleting()) {
$notExistingObjects = $this->findObjectsByExcludedIds($objectIds);
$i = 0;
foreach ($notExistingObjects as $object) {
$objectRepository->remove($object);
$totalDeleted++;
$i++;
if ($i >= $numberOfRecordsToPersist) {
$this->persistenceManager->persistAll();
$i = 0;
}
}
}
......
WE:
SpreadsheetImport:
cleanupImportFromPreviousDay: 5
numberOfRecordsToPersist: 100
swisscomGrb:
domain: WE\KIME\Domain\Model\User
Configuration:
......
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